Commit 9da3eac0 authored by TMRh20's avatar TMRh20

Fix: Multicast pipe0 address handling issue

Previous behaviour:
1. Radio #1: Pipe 0 opened for writing (Address1), pipe 1 opened for
reading (Address2)
2. The radio would end up listening on the following pipes/addresses,
because pipe0 was not assigned a separate reading address.
Pipe0: Address1
Pipe1: Address2
3. This is generally not a problem with 2 radios, but when multicasting
with three. If two of the radios transmit to the same address, then
start listening, all three radios will be listening to the same address
on pipe0, unless pipe0 has been assigned a separate reading address

New behaviour:
1. Radio #1: Pipe 0 opened for writing (Address1), pipe 1 opened for
reading (Address2)
2. When calling radio.startListening() pipe0 is closed, because it is
not assigned a reading address
3. Pipe0 is re-opened for writing only, unless a reading address is
assigned to pipe0

This wouldn't really affect things while using auto-ack, because two
radios should not be writing to the same pipe/address.

- Add closeReadingPipe for RPi
- Also adjusted timing for startListening();
- Fix failure detect variable on RPi
parent 9e12c236
...@@ -510,7 +510,9 @@ void RF24::startListening(void) ...@@ -510,7 +510,9 @@ void RF24::startListening(void)
// Restore the pipe0 adddress, if exists // Restore the pipe0 adddress, if exists
if (pipe0_reading_address[0] > 0){ if (pipe0_reading_address[0] > 0){
write_register(RX_ADDR_P0, pipe0_reading_address, addr_width); write_register(RX_ADDR_P0, pipe0_reading_address, addr_width);
}else{
closeReadingPipe(0);
} }
// Flush buffers // Flush buffers
...@@ -519,23 +521,30 @@ void RF24::startListening(void) ...@@ -519,23 +521,30 @@ void RF24::startListening(void)
// Go! // Go!
ce(HIGH); ce(HIGH);
} }
/****************************************************************************/ /****************************************************************************/
static const uint8_t child_pipe_enable[] PROGMEM =
{
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
};
void RF24::stopListening(void) void RF24::stopListening(void)
{ {
ce(LOW); ce(LOW);
//#if defined(__arm__) #if defined(__arm__)
delayMicroseconds(140); delayMicroseconds(300);
//#endif #endif
delayMicroseconds(130);
flush_tx(); flush_tx();
//flush_rx(); //flush_rx();
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) ); write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
delayMicroseconds(140); //Found that adding this delay back actually increases response time write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0]))); // Enable RX on pipe0
delayMicroseconds(100);
} }
/****************************************************************************/ /****************************************************************************/
...@@ -865,7 +874,8 @@ void RF24::openWritingPipe(uint64_t value) ...@@ -865,7 +874,8 @@ void RF24::openWritingPipe(uint64_t value)
write_register(RX_ADDR_P0, reinterpret_cast<uint8_t*>(&value), addr_width); write_register(RX_ADDR_P0, reinterpret_cast<uint8_t*>(&value), addr_width);
write_register(TX_ADDR, reinterpret_cast<uint8_t*>(&value), addr_width); write_register(TX_ADDR, reinterpret_cast<uint8_t*>(&value), addr_width);
//const uint8_t max_payload_size = 32; //const uint8_t max_payload_size = 32;
//write_register(RX_PW_P0,min(payload_size,max_payload_size)); //write_register(RX_PW_P0,min(payload_size,max_payload_size));
write_register(RX_PW_P0,payload_size); write_register(RX_PW_P0,payload_size);
...@@ -894,10 +904,7 @@ static const uint8_t child_payload_size[] PROGMEM = ...@@ -894,10 +904,7 @@ static const uint8_t child_payload_size[] PROGMEM =
{ {
RX_PW_P0, RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5 RX_PW_P0, RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5
}; };
static const uint8_t child_pipe_enable[] PROGMEM =
{
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
};
void RF24::openReadingPipe(uint8_t child, uint64_t address) void RF24::openReadingPipe(uint8_t child, uint64_t address)
{ {
......
This diff is collapsed.
...@@ -510,6 +510,8 @@ void RF24::startListening(void) ...@@ -510,6 +510,8 @@ void RF24::startListening(void)
// Restore the pipe0 adddress, if exists // Restore the pipe0 adddress, if exists
if (pipe0_reading_address[0] > 0){ if (pipe0_reading_address[0] > 0){
write_register(RX_ADDR_P0, pipe0_reading_address,addr_width); write_register(RX_ADDR_P0, pipe0_reading_address,addr_width);
}else{
closeReadingPipe(0);
} }
// Flush buffers // Flush buffers
//flush_rx(); //flush_rx();
...@@ -523,6 +525,11 @@ void RF24::startListening(void) ...@@ -523,6 +525,11 @@ void RF24::startListening(void)
} }
/****************************************************************************/ /****************************************************************************/
static const uint8_t child_pipe_enable[] =
{
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
};
void RF24::stopListening(void) void RF24::stopListening(void)
{ {
...@@ -532,6 +539,7 @@ void RF24::stopListening(void) ...@@ -532,6 +539,7 @@ void RF24::stopListening(void)
//flush_rx(); //flush_rx();
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_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])));
delayMicroseconds(130); delayMicroseconds(130);
} }
...@@ -874,10 +882,6 @@ static const uint8_t child_payload_size[] = ...@@ -874,10 +882,6 @@ static const uint8_t child_payload_size[] =
{ {
RX_PW_P0, RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5 RX_PW_P0, RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5
}; };
static const uint8_t child_pipe_enable[] =
{
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
};
void RF24::openReadingPipe(uint8_t child, uint64_t address) void RF24::openReadingPipe(uint8_t child, uint64_t address)
{ {
...@@ -946,6 +950,13 @@ void RF24::openReadingPipe(uint8_t child, const uint8_t *address) ...@@ -946,6 +950,13 @@ void RF24::openReadingPipe(uint8_t child, const uint8_t *address)
/****************************************************************************/ /****************************************************************************/
void RF24::closeReadingPipe( uint8_t pipe )
{
write_register(EN_RXADDR,read_register(EN_RXADDR) & ~_BV(pgm_read_byte(&child_pipe_enable[pipe])));
}
/****************************************************************************/
void RF24::toggle_features(void) void RF24::toggle_features(void)
{ {
bcm2835_spi_transfer( ACTIVATE ); bcm2835_spi_transfer( ACTIVATE );
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
* @endcode * @endcode
**/ **/
#if defined (FAILURE_HANDLING) #if defined (FAILURE_HANDLING)
bool failureDetect; bool failureDetected;
#endif #endif
private: private:
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */ uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
...@@ -966,6 +966,13 @@ public: ...@@ -966,6 +966,13 @@ public:
void setAddressWidth(uint8_t a_width); void setAddressWidth(uint8_t a_width);
/**
* Close a pipe after it has been previously opened.
* Can be safely called without having previously opened a pipe.
* @param pipe Which pipe # to close, 0-5.
*/
void closeReadingPipe( uint8_t pipe ) ;
/**@}*/ /**@}*/
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment