Skip to content

Commit

Permalink
Added writeFast() cmd - fill FIFO or return 0
Browse files Browse the repository at this point in the history
- WriteFast allows the FIFO buffers to be filled up before returning 0
- The current payload will be dropped, and the previous payload resent
- The user should just keep trying to send the same data if a 0 is
received
  • Loading branch information
TMRh20 committed Mar 19, 2014
1 parent d0ec0c4 commit 281ace4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
40 changes: 37 additions & 3 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,14 @@ bool RF24::write( const void* buf, uint8_t len )

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

//For general use, the flags are not important to clear
//For general use, the interrupt flags are not important to clear
bool RF24::writeBlocking( const void* buf, uint8_t len )
{
//Block until the FIFO is NOT full.
//Keep track of the MAX retries and set auto-retry if seeing failures
//This way the FIFO will fill up and allow blocking until packets go through
//The radio will auto-clear everything in the FIFO as long as CE remains high

//Start Writing
startWrite(buf,len);

while ( (read_register(FIFO_STATUS) & _BV(FIFO_FULL))){ //Blocking only if FIFO is full. This will loop and block until TX is successful

Expand All @@ -486,9 +484,12 @@ bool RF24::writeBlocking( const void* buf, uint8_t len )
reUseTX(); //Set re-transmit
ce(LOW); //Re-Transfer packet
ce(HIGH);
delayMicroseconds(15);
}

}
//Start Writing
startWrite(buf,len);

return 1;
}
Expand All @@ -500,6 +501,39 @@ void RF24::reUseTX(){
csn(HIGH);

}

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

//This is for when every bit of data is important
bool RF24::writeFast( const void* buf, uint8_t len )
{
//Block until the FIFO is NOT full.
//Keep track of the MAX retries and set auto-retry if seeing failures
//Return 0 so the user can control the retrys and set a timer or failure counter if required
//The radio will auto-clear everything in the FIFO as long as CE remains high


while ( (read_register(FIFO_STATUS) & _BV(FIFO_FULL))){ //Blocking only if FIFO is full. This will loop and block until TX is successful

if( get_status() & _BV(MAX_RT)){
write_register(STATUS,_BV(MAX_RT) ); //Clear max retry flag
reUseTX(); //Set re-transmit
ce(LOW); //Re-Transfer packet
ce(HIGH);
delayMicroseconds(15); //CE needs to stay high for 10us, for TX_REUSE to engage
return 0; //Return 0. The previous payload has been retransmitted
//From the user perspective, if you get a 0, just keep trying to send the same payload
}

}
//Start Writing
startWrite(buf,len);

return 1;
}



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

//Per the documentation, we want to set PTX Mode when not listening. Then all we do is write data and set CE high
Expand Down
1 change: 1 addition & 0 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class RF24
void txStandBy();
bool writeBlocking( const void* buf, uint8_t len );
void reUseTX();
bool writeFast( const void* buf, uint8_t len ); //Fills FIFO buffer, uses packet re-use function of the chip and returns 0 if packet failed and re-sent

/**
* @name Primary public interface
Expand Down

0 comments on commit 281ace4

Please sign in to comment.