Kaynağa Gözat

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 5 yıl önce
ebeveyn
işleme
0c03c24fcd

+ 0
- 10
weather-sensor/firmware/bme280_interface.c Dosyayı Görüntüle

@@ -5,12 +5,6 @@
5 5
 #include "bme280.h"
6 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 9
 void user_delay_ms(uint32_t period);
16 10
 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
@@ -25,7 +19,6 @@ int8_t Initialize_BME280(void)
25 19
 {
26 20
 	int8_t rslt = BME280_OK;
27 21
 	uint8_t settings_sel;
28
-	char debugString[20] = "";
29 22
 
30 23
 
31 24
 	/* Setup the SPI interface */
@@ -55,9 +48,6 @@ int8_t Initialize_BME280(void)
55 48
 	/* calculate minimum delay required between consecutive measurments */
56 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 51
 	return rslt;
62 52
 }
63 53
 

+ 1
- 1
weather-sensor/firmware/bme280_interface.h Dosyayı Görüntüle

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

+ 4
- 33
weather-sensor/firmware/main.c Dosyayı Görüntüle

@@ -9,7 +9,6 @@
9 9
 #include "nrf24l01_definitions.h"
10 10
 #include "bme280_interface.h"
11 11
 #include "bme280_defs.h"
12
-#include "uart_debug.h"
13 12
 
14 13
 //#define LED_DDR     DDRB        //DDRA, DDRB...
15 14
 //#define LED_PORT    PORTB       //PORTA, PORTB...
@@ -17,20 +16,11 @@
17 16
 //#define time_off    8
18 17
 
19 18
 /* SPI: */
19
+/* TODO: move to spi.h */
20 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,18 +33,12 @@ void Initialize_SPI(void);
43 33
 
44 34
 int main (void)
45 35
 {
46
-	char debugString[50] = "";
47 36
 	struct bme280_data sensorData;
48 37
 //	uint8_t testRegisterContent = 0x0A;
49 38
 //	uint8_t registerContent[5];
50 39
 //	char registerContentString[30];
51 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 43
 	/* Initialize the SPI */
60 44
 	Initialize_SPI();
@@ -70,19 +54,6 @@ int main (void)
70 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 58
 	while(1)
88 59
 	{

+ 3
- 3
weather-sensor/firmware/makefile Dosyayı Görüntüle

@@ -5,10 +5,10 @@ clean:
5 5
 	rm -f main
6 6
 
7 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 13
 main.hex: main
14 14
 	avr-objcopy -O ihex -R .eeprom main main.hex

+ 0
- 17
weather-sensor/firmware/nrf24l01.c Dosyayı Görüntüle

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

@@ -4,13 +4,13 @@
4 4
 
5 5
 
6 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 15
 void Initialize_NRF24L01(void);
16 16
 void Configure_Transmission(void);

+ 0
- 23
weather-sensor/firmware/uart_debug.c Dosyayı Görüntüle

@@ -1,23 +0,0 @@
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 Dosyayı Görüntüle

@@ -1,7 +0,0 @@
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…
İptal
Kaydet