Skip to content

Commit

Permalink
Fix: Multicast pipe0 address handling issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TMRh20 committed Aug 16, 2014
1 parent 9e12c23 commit 9da3eac
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 90 deletions.
31 changes: 19 additions & 12 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ void RF24::startListening(void)

// Restore the pipe0 adddress, if exists
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
Expand All @@ -519,23 +521,30 @@ void RF24::startListening(void)

// Go!
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)
{

ce(LOW);
//#if defined(__arm__)
delayMicroseconds(140);
//#endif
#if defined(__arm__)
delayMicroseconds(300);
#endif
delayMicroseconds(130);
flush_tx();
//flush_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);

}

/****************************************************************************/
Expand Down Expand Up @@ -865,7 +874,8 @@ void RF24::openWritingPipe(uint64_t value)

write_register(RX_ADDR_P0, 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;
//write_register(RX_PW_P0,min(payload_size,max_payload_size));
write_register(RX_PW_P0,payload_size);
Expand Down Expand Up @@ -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
};
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)
{
Expand Down
Loading

0 comments on commit 9da3eac

Please sign in to comment.