Skip to content

Commit

Permalink
Reliability improvements for RPi
Browse files Browse the repository at this point in the history
- In testing with python wrapper, found setting CE(HIGH) sooner in
startListening() prevents issues
- Changed delay between available() checking on RPi to prevent what
seems like saturation of the RF24 module with SPI requests
- Reduces errors when switching between RX/TX modes
  • Loading branch information
TMRh20 committed Nov 16, 2014
1 parent b007fb4 commit d41d47a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void RF24::startListening(void)
#endif
write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX));
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

ce(HIGH);
// Restore the pipe0 adddress, if exists
if (pipe0_reading_address[0] > 0){
write_register(RX_ADDR_P0, pipe0_reading_address, addr_width);
Expand All @@ -735,7 +735,7 @@ void RF24::startListening(void)
}

// Go!
ce(HIGH);

delayMicroseconds(130);
listeningStarted = 1;
}
Expand Down Expand Up @@ -1066,16 +1066,16 @@ bool RF24::available(void)
bool RF24::available(uint8_t* pipe_num)
{
//Check the FIFO buffer to see if data is waiting to be read
if(listeningStarted){
#if defined (RF24_LINUX)
if(millis() - lastAvailableCheck < 2 && listeningStarted){delayMicroseconds(400);}
#if defined (RF24_LINUX) // This seems to prevent faster devices like RPi from saturating the RF24 module with SPI requests
while(millis() - lastAvailableCheck < 1){}
lastAvailableCheck = millis();
#else
#else
if(listeningStarted){
while(micros() - lastAvailableCheck < 800 && listeningStarted){};
lastAvailableCheck = micros();
#endif
lastAvailableCheck = micros();
listeningStarted = 0;
}
#endif
if (!( read_register(FIFO_STATUS) & _BV(RX_EMPTY) )){

// If the caller wants the pipe number, include that
Expand Down

0 comments on commit d41d47a

Please sign in to comment.