Browse Source

Send the data from the BME280 with the NRF24L01

Bernd Gottschlag 5 years ago
parent
commit
ddb5b0426e

+ 2
- 14
weather-sensor/firmware/bme280_interface.c View File

62
 }
62
 }
63
 
63
 
64
 /* Get one measurement in forced mode */
64
 /* Get one measurement in forced mode */
65
-void BME280_Get_Measurement(void)
65
+void BME280_Get_Measurement(struct bme280_data * data)
66
 {
66
 {
67
 	int8_t rslt = BME280_OK;
67
 	int8_t rslt = BME280_OK;
68
-	struct bme280_data comp_data;
69
-	char debugString[30] = "";
70
 
68
 
71
 	rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, &deviceStructure);
69
 	rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, &deviceStructure);
72
-	/* Wait for the measurement to complete and print data @25Hz */
73
 	deviceStructure.delay_ms(req_delay);
70
 	deviceStructure.delay_ms(req_delay);
74
-	rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, &deviceStructure);
75
-
76
-	sprintf(debugString, "rslt: %d\r\n", rslt);
77
-	Print_Debug_String(debugString);
78
-	sprintf(debugString, "temp: %ld\r\n", comp_data.temperature);
79
-	Print_Debug_String(debugString);
80
-	sprintf(debugString, "hum: %ld\r\n", comp_data.humidity);
81
-	Print_Debug_String(debugString);
82
-	sprintf(debugString, "pres: %ld\r\n", comp_data.pressure);
83
-	Print_Debug_String(debugString);
71
+	rslt = bme280_get_sensor_data(BME280_ALL, data, &deviceStructure);
84
 }
72
 }
85
 
73
 
86
 /* Implementation of the interface function needed by the BME280 library */
74
 /* Implementation of the interface function needed by the BME280 library */

+ 2
- 2
weather-sensor/firmware/bme280_interface.h View File

2
 #define BME280_H
2
 #define BME280_H
3
 
3
 
4
 #include <stdint.h>
4
 #include <stdint.h>
5
-//#include "bme280.h"
5
+#include "bme280_defs.h"
6
 
6
 
7
 /* AVR I/O pin definionts */
7
 /* AVR I/O pin definionts */
8
 #define BME_CSN_DDR   DDRB
8
 #define BME_CSN_DDR   DDRB
10
 #define BME_CSN_PIN   PB6
10
 #define BME_CSN_PIN   PB6
11
 
11
 
12
 int8_t Initialize_BME280(void);
12
 int8_t Initialize_BME280(void);
13
-void BME280_Get_Measurement(void);
13
+void BME280_Get_Measurement(struct bme280_data * data);
14
 
14
 
15
 #endif
15
 #endif

+ 4
- 4
weather-sensor/firmware/main.c View File

1
-//#define F_CPU 1000000UL  // Frequenz des Quarzes, ohne Quarz standardmäßig 1MHz
2
-
3
 #include <avr/io.h>
1
 #include <avr/io.h>
4
 #include <util/delay.h>
2
 #include <util/delay.h>
5
 #include <stdint.h>
3
 #include <stdint.h>
10
 #include "nrf24l01.h"
8
 #include "nrf24l01.h"
11
 #include "nrf24l01_definitions.h"
9
 #include "nrf24l01_definitions.h"
12
 #include "bme280_interface.h"
10
 #include "bme280_interface.h"
11
+#include "bme280_defs.h"
13
 #include "uart_debug.h"
12
 #include "uart_debug.h"
14
 
13
 
15
 //#define LED_DDR     DDRB        //DDRA, DDRB...
14
 //#define LED_DDR     DDRB        //DDRA, DDRB...
45
 int main (void)
44
 int main (void)
46
 {
45
 {
47
 	char debugString[50] = "";
46
 	char debugString[50] = "";
47
+	struct bme280_data sensorData;
48
 //	uint8_t testRegisterContent = 0x0A;
48
 //	uint8_t testRegisterContent = 0x0A;
49
 //	uint8_t registerContent[5];
49
 //	uint8_t registerContent[5];
50
 //	char registerContentString[30];
50
 //	char registerContentString[30];
86
 
86
 
87
 	while(1)
87
 	while(1)
88
 	{
88
 	{
89
-		BME280_Get_Measurement();
90
-		Send_Test_Message();
89
+		BME280_Get_Measurement(&sensorData);
90
+		NRF24L01_Send_Message((uint8_t*)&sensorData, sizeof(sensorData));
91
 		_delay_ms(1000);
91
 		_delay_ms(1000);
92
 	}
92
 	}
93
 }
93
 }

+ 9
- 3
weather-sensor/firmware/nrf24l01.c View File

107
 	// TODO: set addresses for all data pipes
107
 	// TODO: set addresses for all data pipes
108
 }
108
 }
109
 
109
 
110
-void Send_Test_Message(void)
110
+void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length)
111
 {
111
 {
112
-	uint8_t buffer[4] = {0xDE, 0xAD, 0xBE, 0xEF};
113
 	bool transmissionFinished = false;
112
 	bool transmissionFinished = false;
114
 
113
 
115
 	STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
114
 	STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
123
 	 * - Check if the FIFO is empty -> if not, flush it
122
 	 * - Check if the FIFO is empty -> if not, flush it
124
 	 * - reset the interupts of the STATUS
123
 	 * - reset the interupts of the STATUS
125
 	 */
124
 	 */
126
-	Write_Message_To_TX_FIFO(4, buffer);
125
+	
126
+	/* TODO: messages with more than 32 byte length */
127
+	if ((length > 32) || (length == 0))
128
+	{
129
+		return;
130
+	}
131
+
132
+	Write_Message_To_TX_FIFO(length, buffer);
127
 
133
 
128
 	/* Set CE = 1 for more than 10 us */
134
 	/* Set CE = 1 for more than 10 us */
129
 	NRF_CE_PORT |= (1 << NRF_CE_PIN);
135
 	NRF_CE_PORT |= (1 << NRF_CE_PIN);

+ 1
- 1
weather-sensor/firmware/nrf24l01.h View File

19
 void Write_NRF_Register(uint8_t address, uint8_t registerContents);
19
 void Write_NRF_Register(uint8_t address, uint8_t registerContents);
20
 void Send_Activate_Command(void);
20
 void Send_Activate_Command(void);
21
 
21
 
22
-void Send_Test_Message(void);
22
+void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length);
23
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
23
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
24
 void Set_TX_Address(uint32_t txAddress);
24
 void Set_TX_Address(uint32_t txAddress);
25
 void Set_RX_P0_Address(uint32_t rxAddress);
25
 void Set_RX_P0_Address(uint32_t rxAddress);

Loading…
Cancel
Save