Browse Source

Flush TX FIFO after an unsuccessful transmission

Bernd Gottschlag 5 years ago
parent
commit
b9cfc34e94
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      weather-sensor/firmware/nrf24l01.c

+ 15
- 0
weather-sensor/firmware/nrf24l01.c View File

16
  */
16
  */
17
 
17
 
18
 void Print_Register_Contents(uint8_t address);
18
 void Print_Register_Contents(uint8_t address);
19
+void Send_TX_Flush_Command(void);
19
 
20
 
20
 /* Startup and initial configuration of the NRF24L01 */
21
 /* Startup and initial configuration of the NRF24L01 */
21
 void Initialize_NRF24L01(void)
22
 void Initialize_NRF24L01(void)
147
 			transmissionFinished = true; //TODO: indicate failure
148
 			transmissionFinished = true; //TODO: indicate failure
148
 			sprintf(debugString, "%s\r\n", "max ret");
149
 			sprintf(debugString, "%s\r\n", "max ret");
149
 			Print_Debug_String(debugString);
150
 			Print_Debug_String(debugString);
151
+
152
+			Send_TX_Flush_Command(); /* Remove the packet from the TX FIFO as it is not done automatically */
150
 		}
153
 		}
151
 		
154
 		
152
 		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
269
 	NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
272
 	NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
270
 }
273
 }
271
 
274
 
275
+// TODO: clean up functions
272
 void Send_Activate_Command(void)
276
 void Send_Activate_Command(void)
273
 {
277
 {
274
 	/* First write the write command with the address */
278
 	/* First write the write command with the address */
285
 	NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
289
 	NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
286
 }
290
 }
287
 
291
 
292
+void Send_TX_Flush_Command(void)
293
+{
294
+	/* First write the write command with the address */
295
+	NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
296
+	SPDR = 0xE1;
297
+	
298
+	while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
299
+
300
+	NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
301
+}
302
+
288
 
303
 
289
 
304
 
290
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)
305
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)

Loading…
Cancel
Save