Skip to content

Commit

Permalink
Add rxFifoFull() function, Only flush tx w ack_plds
Browse files Browse the repository at this point in the history
- Add function to check if the rx fifo has been filled and potentially
overloaded
- TX FIFO is now only flushed when transitioning between reading/writing
as start/stopListening() is called IF dynamic payloads are enabled
  • Loading branch information
TMRh20 committed Sep 13, 2014
1 parent 4e250cb commit 82629d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
18 changes: 16 additions & 2 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ void RF24::startListening(void)

// Flush buffers
//flush_rx();
flush_tx();
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
flush_tx();
}

// Go!
ce(HIGH);
Expand All @@ -538,7 +540,9 @@ void RF24::stopListening(void)
delayMicroseconds(300);
#endif
delayMicroseconds(130);
flush_tx();
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
flush_tx();
}
//flush_rx();
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0]))); // Enable RX on pipe0
Expand Down Expand Up @@ -714,6 +718,7 @@ void RF24::startFastWrite( const void* buf, uint8_t len, const bool multicast){

}

/****************************************************************************/

//Added the original startWrite back in so users can still use interrupts, ack payloads, etc
//Allows the library to pass all tests
Expand All @@ -732,6 +737,13 @@ void RF24::startWrite( const void* buf, uint8_t len, const bool multicast ){

}

/****************************************************************************/

bool RF24::rxFifoFull(){
return read_register(FIFO_STATUS) & _BV(RX_FULL);
}
/****************************************************************************/

bool RF24::txStandBy(){
#if defined (FAILURE_HANDLING)
uint32_t timeout = millis();
Expand All @@ -755,6 +767,8 @@ bool RF24::txStandBy(){
return 1;
}

/****************************************************************************/

bool RF24::txStandBy(uint32_t timeout){

uint32_t start = millis();
Expand Down
15 changes: 14 additions & 1 deletion RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class RF24
*/
bool available(uint8_t* pipe_num);

/**
* Check if the radio needs to be read. Can be used to prevent data loss
* @@return True if all three 32-byte radio buffers are full
*/
bool rxFifoFull();

/**
* Enter low-power mode
*
Expand Down Expand Up @@ -908,6 +914,7 @@ class RF24
*/
uint8_t get_status(void);

#if !defined (MINIMAL)
/**
* Decode and print the given status to stdout
*
Expand Down Expand Up @@ -951,7 +958,7 @@ class RF24
* @param qty How many successive registers to print
*/
void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);

#endif
/**
* Turn on or off the special features of the chip
*
Expand Down Expand Up @@ -1063,6 +1070,12 @@ class RF24
* ping/pong cycle, and the receiver sleeps between payloads. <br>
*/

/**
* @example rf24ping85.ino
* <b>New: Contributed by https://github.com/tong67</b><br>
* This is an example of how to use the RF24 class to communicate with ATtiny85 and other node. <br>
*/

/**
* @example pingpair_dyn.ino
*
Expand Down
17 changes: 13 additions & 4 deletions RPi/RF24/RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,10 @@ void RF24::startListening(void)
closeReadingPipe(0);
}
// Flush buffers
//flush_rx();
flush_tx();
flush_rx();
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
flush_tx();
}

// Go!
bcm2835_gpio_write(ce_pin, HIGH);
Expand All @@ -535,8 +537,11 @@ void RF24::stopListening(void)
{
bcm2835_gpio_write(ce_pin, LOW);
delayMicroseconds(470);
flush_tx();
//flush_rx();

if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
flush_tx();
}
flush_rx();

write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0])));
Expand Down Expand Up @@ -743,7 +748,11 @@ bool RF24::txStandBy(){
bcm2835_gpio_write(ce_pin, LOW); //Set STANDBY-I mode
return 1;
}
bool RF24::rxFifoFull(){

bool val = (read_register(FIFO_STATUS) & _BV(RX_FULL));
return val;
}
/****************************************************************************/

bool RF24::txStandBy(uint32_t timeout){
Expand Down
6 changes: 6 additions & 0 deletions RPi/RF24/RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,12 @@ class RF24
*/
bool available(uint8_t* pipe_num);

/**
* Check if the radio needs to be read. Can be used to prevent data loss and during delays
* @@return True if all three 32-byte radio buffers are full
*/
bool rxFifoFull();

/**
* Non-blocking write to the open writing pipe used for buffered writes
*
Expand Down

0 comments on commit 82629d4

Please sign in to comment.