Explorar el Código

Change the MCU to the Atmega88

The pin definitions are updated and the uart debug interface is removed
as it is not present on the actual board.
Bernd Gottschlag hace 5 años
padre
commit
0c03c24fcd

+ 0
- 10
weather-sensor/firmware/bme280_interface.c Ver fichero

5
 #include "bme280.h"
5
 #include "bme280.h"
6
 #include "bme280_interface.h"
6
 #include "bme280_interface.h"
7
 
7
 
8
-/* for debugging */
9
-#include "uart_debug.h"
10
-#include <stdint.h>
11
-#include <stdio.h>
12
-#include <string.h>
13
-
14
 
8
 
15
 void user_delay_ms(uint32_t period);
9
 void user_delay_ms(uint32_t period);
16
 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
10
 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
25
 {
19
 {
26
 	int8_t rslt = BME280_OK;
20
 	int8_t rslt = BME280_OK;
27
 	uint8_t settings_sel;
21
 	uint8_t settings_sel;
28
-	char debugString[20] = "";
29
 
22
 
30
 
23
 
31
 	/* Setup the SPI interface */
24
 	/* Setup the SPI interface */
55
 	/* calculate minimum delay required between consecutive measurments */
48
 	/* calculate minimum delay required between consecutive measurments */
56
 	req_delay = bme280_cal_meas_delay(&deviceStructure.settings);
49
 	req_delay = bme280_cal_meas_delay(&deviceStructure.settings);
57
 
50
 
58
-	sprintf(debugString, "req delay: %ld\r\n", req_delay);
59
-	Print_Debug_String(debugString);
60
-
61
 	return rslt;
51
 	return rslt;
62
 }
52
 }
63
 
53
 

+ 1
- 1
weather-sensor/firmware/bme280_interface.h Ver fichero

7
 /* AVR I/O pin definionts */
7
 /* AVR I/O pin definionts */
8
 #define BME_CSN_DDR   DDRB
8
 #define BME_CSN_DDR   DDRB
9
 #define BME_CSN_PORT  PORTB
9
 #define BME_CSN_PORT  PORTB
10
-#define BME_CSN_PIN   PB6
10
+#define BME_CSN_PIN   PB2
11
 
11
 
12
 int8_t Initialize_BME280(void);
12
 int8_t Initialize_BME280(void);
13
 void BME280_Get_Measurement(struct bme280_data * data);
13
 void BME280_Get_Measurement(struct bme280_data * data);

+ 4
- 33
weather-sensor/firmware/main.c Ver fichero

9
 #include "nrf24l01_definitions.h"
9
 #include "nrf24l01_definitions.h"
10
 #include "bme280_interface.h"
10
 #include "bme280_interface.h"
11
 #include "bme280_defs.h"
11
 #include "bme280_defs.h"
12
-#include "uart_debug.h"
13
 
12
 
14
 //#define LED_DDR     DDRB        //DDRA, DDRB...
13
 //#define LED_DDR     DDRB        //DDRA, DDRB...
15
 //#define LED_PORT    PORTB       //PORTA, PORTB...
14
 //#define LED_PORT    PORTB       //PORTA, PORTB...
17
 //#define time_off    8
16
 //#define time_off    8
18
 
17
 
19
 /* SPI: */
18
 /* SPI: */
19
+/* TODO: move to spi.h */
20
 #define SPI_DDR       DDRB
20
 #define SPI_DDR       DDRB
21
-#define SPI_SCK_PIN   PB1
22
-#define SPI_MOSI_PIN  PB2
23
-#define SPI_MISO_PIN  PB3
24
-
25
-/* NRF24L01 */
26
-
27
-
28
-
29
-/*
30
- * CS: pin 9
31
- * CE: pin 8
32
- * IRQ: pin 7
33
- */
21
+#define SPI_SCK_PIN   PB5
22
+#define SPI_MOSI_PIN  PB3
23
+#define SPI_MISO_PIN  PB4
34
 
24
 
35
 
25
 
36
 
26
 
43
 
33
 
44
 int main (void)
34
 int main (void)
45
 {
35
 {
46
-	char debugString[50] = "";
47
 	struct bme280_data sensorData;
36
 	struct bme280_data sensorData;
48
 //	uint8_t testRegisterContent = 0x0A;
37
 //	uint8_t testRegisterContent = 0x0A;
49
 //	uint8_t registerContent[5];
38
 //	uint8_t registerContent[5];
50
 //	char registerContentString[30];
39
 //	char registerContentString[30];
51
 //	uint8_t lengthRead;
40
 //	uint8_t lengthRead;
52
 
41
 
53
-	/* Set baud rate */
54
-	Initialize_UART(51);
55
-
56
-	sprintf(debugString, "%s\r\n", "Program start");
57
-	Print_Debug_String(debugString);
58
 
42
 
59
 	/* Initialize the SPI */
43
 	/* Initialize the SPI */
60
 	Initialize_SPI();
44
 	Initialize_SPI();
70
 	Initialize_BME280();
54
 	Initialize_BME280();
71
 
55
 
72
 
56
 
73
-#if 0
74
-	/* Test the BME280 by reading the ID */
75
-	uint8_t id = Read_BME280_Register(0xD0);
76
-	sprintf(debugString, "ID: 0x%x\r\n", id);
77
-	Print_Debug_String(debugString);
78
-#endif
79
-
80
-
81
-
82
-
83
-
84
-//	sprintf(debugString, "%s\r\n", "program end");
85
-//	Print_Debug_String(debugString);
86
 
57
 
87
 	while(1)
58
 	while(1)
88
 	{
59
 	{

+ 3
- 3
weather-sensor/firmware/makefile Ver fichero

5
 	rm -f main
5
 	rm -f main
6
 
6
 
7
 flash: main.hex
7
 flash: main.hex
8
-	sudo avrdude -c avr109 -b 57600 -P /dev/ttyACM0 -p m32u4 -v -U flash:w:main.hex
8
+	sudo avrdude -c buspirate -b 115200 -P /dev/ttyUSB0 -p m88p -v -U flash:w:main.hex
9
 
9
 
10
-main: main.c spi.c spi.h nrf24l01.c nrf24l01.h nrf24l01_definitions.h uart_debug.c uart_debug.h bme280_interface.c bme280_interface.h BME280_driver/bme280.c BME280_driver/bme280.h
11
-	avr-gcc main.c spi.c nrf24l01.c bme280_interface.c BME280_driver/bme280.c uart_debug.c  -I BME280_driver -o main -mmcu=atmega32u4 -Os -Wall -Wextra -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DF_CPU=8000000UL -D BME280_32BIT_ENABLE
10
+main: main.c spi.c spi.h nrf24l01.c nrf24l01.h nrf24l01_definitions.h bme280_interface.c bme280_interface.h BME280_driver/bme280.c BME280_driver/bme280.h
11
+	avr-gcc main.c spi.c nrf24l01.c bme280_interface.c BME280_driver/bme280.c -I BME280_driver -o main -mmcu=atmega88p -Os -Wall -Wextra -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DF_CPU=1000000UL -D BME280_32BIT_ENABLE
12
 
12
 
13
 main.hex: main
13
 main.hex: main
14
 	avr-objcopy -O ihex -R .eeprom main main.hex
14
 	avr-objcopy -O ihex -R .eeprom main main.hex

+ 0
- 17
weather-sensor/firmware/nrf24l01.c Ver fichero

7
 #include "spi.h"
7
 #include "spi.h"
8
 #include "nrf24l01.h"
8
 #include "nrf24l01.h"
9
 #include "nrf24l01_definitions.h"
9
 #include "nrf24l01_definitions.h"
10
-#include "uart_debug.h"
11
 
10
 
12
 /* TODO
11
 /* TODO
13
  * - Build a state machine that tracks the mode the NRF is set to
12
  * - Build a state machine that tracks the mode the NRF is set to
112
 	bool transmissionFinished = false;
111
 	bool transmissionFinished = false;
113
 
112
 
114
 	STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
113
 	STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
115
-	char debugString[50] = "";
116
 	uint32_t timeout = 0;
114
 	uint32_t timeout = 0;
117
 	/* TODO:
115
 	/* TODO:
118
 	 * - if needed: PRIM_RX = 0
116
 	 * - if needed: PRIM_RX = 0
137
 	NRF_CE_PORT &= ~(1 << NRF_CE_PIN);
135
 	NRF_CE_PORT &= ~(1 << NRF_CE_PIN);
138
 
136
 
139
 
137
 
140
-	sprintf(debugString, "-\r\n");
141
-	Print_Debug_String(debugString);
142
 	do
138
 	do
143
 	{
139
 	{
144
 		_delay_ms(1);
140
 		_delay_ms(1);
147
 		if (statusRegisterContents.bits.TX_DS == 1)
143
 		if (statusRegisterContents.bits.TX_DS == 1)
148
 		{
144
 		{
149
 			transmissionFinished = true;
145
 			transmissionFinished = true;
150
-			sprintf(debugString, "%s\r\n", "TX fin");
151
-			Print_Debug_String(debugString);
152
 		}
146
 		}
153
 
147
 
154
 		if (statusRegisterContents.bits.MAX_RT == 1)
148
 		if (statusRegisterContents.bits.MAX_RT == 1)
155
 		{
149
 		{
156
 			transmissionFinished = true; //TODO: indicate failure
150
 			transmissionFinished = true; //TODO: indicate failure
157
-			sprintf(debugString, "%s\r\n", "max ret");
158
-			Print_Debug_String(debugString);
159
 
151
 
160
 			Send_TX_Flush_Command(); /* Remove the packet from the TX FIFO as it is not done automatically */
152
 			Send_TX_Flush_Command(); /* Remove the packet from the TX FIFO as it is not done automatically */
161
 		}
153
 		}
163
 		timeout ++; // TODO: this should work without the time out, as MAX_RT should be triggered if no ACK is received
155
 		timeout ++; // TODO: this should work without the time out, as MAX_RT should be triggered if no ACK is received
164
 	} while ((transmissionFinished == false) && (timeout < 0xFF));
156
 	} while ((transmissionFinished == false) && (timeout < 0xFF));
165
 
157
 
166
-	if (timeout >= 0xFF)
167
-	{
168
-			sprintf(debugString, "%s\r\n", "timeout");
169
-			Print_Debug_String(debugString);
170
-	}
171
-
172
 	/* Reset the interrupts */
158
 	/* Reset the interrupts */
173
 	statusRegisterContents.byte = Read_NRF_Status_Register();
159
 	statusRegisterContents.byte = Read_NRF_Status_Register();
174
 	statusRegisterContents.bits.TX_DS = 1;
160
 	statusRegisterContents.bits.TX_DS = 1;
180
 {
166
 {
181
 	uint8_t registerContent[5];
167
 	uint8_t registerContent[5];
182
 	uint8_t lengthRead;
168
 	uint8_t lengthRead;
183
-	char debugString[50] = "";
184
 	char registerContentString[30];
169
 	char registerContentString[30];
185
 
170
 
186
 
171
 
191
 	{
176
 	{
192
 		sprintf(registerContentString, "%s0x%x ", registerContentString, registerContent[i]);
177
 		sprintf(registerContentString, "%s0x%x ", registerContentString, registerContent[i]);
193
 	}
178
 	}
194
-	sprintf(debugString, "%s\r\n", registerContentString);
195
-	Print_Debug_String(debugString);
196
 }
179
 }
197
 
180
 
198
 
181
 

+ 6
- 6
weather-sensor/firmware/nrf24l01.h Ver fichero

4
 
4
 
5
 
5
 
6
 /* AVR I/O pin definionts */
6
 /* AVR I/O pin definionts */
7
-#define NRF_CE_DDR   DDRB
8
-#define NRF_CE_PORT  PORTB
9
-#define NRF_CE_PIN   PB4
7
+#define NRF_CE_DDR   DDRD
8
+#define NRF_CE_PORT  PORTD
9
+#define NRF_CE_PIN   PB7
10
 
10
 
11
-#define NRF_CSN_DDR   DDRB
12
-#define NRF_CSN_PORT  PORTB
13
-#define NRF_CSN_PIN   PB5
11
+#define NRF_CSN_DDR   DDRD
12
+#define NRF_CSN_PORT  PORTD
13
+#define NRF_CSN_PIN   PB6
14
 
14
 
15
 void Initialize_NRF24L01(void);
15
 void Initialize_NRF24L01(void);
16
 void Configure_Transmission(void);
16
 void Configure_Transmission(void);

+ 0
- 23
weather-sensor/firmware/uart_debug.c Ver fichero

1
-#include <avr/io.h>
2
-#include <string.h>
3
-
4
-#include "uart_debug.h"
5
-
6
-void Initialize_UART(uint16_t baudRate)
7
-{
8
-	UBRR1H = (unsigned char)(baudRate>>8);
9
-	UBRR1L = (unsigned char)baudRate;
10
-	/* Enable receiver and transmitter */
11
-	UCSR1B = (1<<RXEN1)|(1<<TXEN1);
12
-	/* Set frame format: 8data, 2stop bit */
13
-	UCSR1C = (1<<USBS1)|(3<<UCSZ10);
14
-}
15
-
16
-void Print_Debug_String(char * debugString)
17
-{
18
-	for (uint8_t i = 0; i < strlen(debugString); i++)
19
-	{
20
-		while ( !( UCSR1A & (1<<UDRE1)));
21
-		UDR1 = debugString[i];
22
-	}
23
-}

+ 0
- 7
weather-sensor/firmware/uart_debug.h Ver fichero

1
-#ifndef UART_DEBUG_C
2
-#define UART_DEBUG_C
3
-
4
-void Initialize_UART(uint16_t baudRate);
5
-void Print_Debug_String(char * debugString);
6
-
7
-#endif

Loading…
Cancelar
Guardar