Parcourir la source

Send the data from the BME280 with the NRF24L01

Bernd Gottschlag il y a 5 ans
Parent
révision
ddb5b0426e

+ 2
- 14
weather-sensor/firmware/bme280_interface.c Voir le fichier

@@ -62,25 +62,13 @@ int8_t Initialize_BME280(void)
62 62
 }
63 63
 
64 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 67
 	int8_t rslt = BME280_OK;
68
-	struct bme280_data comp_data;
69
-	char debugString[30] = "";
70 68
 
71 69
 	rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, &deviceStructure);
72
-	/* Wait for the measurement to complete and print data @25Hz */
73 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 74
 /* Implementation of the interface function needed by the BME280 library */

+ 2
- 2
weather-sensor/firmware/bme280_interface.h Voir le fichier

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

+ 4
- 4
weather-sensor/firmware/main.c Voir le fichier

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

+ 9
- 3
weather-sensor/firmware/nrf24l01.c Voir le fichier

@@ -107,9 +107,8 @@ void Configure_Transmission(void)
107 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 112
 	bool transmissionFinished = false;
114 113
 
115 114
 	STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
@@ -123,7 +122,14 @@ void Send_Test_Message(void)
123 122
 	 * - Check if the FIFO is empty -> if not, flush it
124 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 134
 	/* Set CE = 1 for more than 10 us */
129 135
 	NRF_CE_PORT |= (1 << NRF_CE_PIN);

+ 1
- 1
weather-sensor/firmware/nrf24l01.h Voir le fichier

@@ -19,7 +19,7 @@ uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents);
19 19
 void Write_NRF_Register(uint8_t address, uint8_t registerContents);
20 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 23
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
24 24
 void Set_TX_Address(uint32_t txAddress);
25 25
 void Set_RX_P0_Address(uint32_t rxAddress);

Loading…
Annuler
Enregistrer