Commit b7c24a81 authored by TMRh20's avatar TMRh20

Updated address assignment

- Added setAddressWidth()  - allows address widths of 3 to 5 bytes
(24,32 or 40 bits)
- Addresses can now be specified via a byte array
- Thanks to Zephyrr for suggestion
parent b7e4a09a
...@@ -330,8 +330,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty) ...@@ -330,8 +330,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
RF24::RF24(uint8_t _cepin, uint8_t _cspin): RF24::RF24(uint8_t _cepin, uint8_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), wide_band(false), p_variant(false), ce_pin(_cepin), csn_pin(_cspin), wide_band(false), p_variant(false),
payload_size(32), dynamic_payloads_enabled(false), payload_size(32), dynamic_payloads_enabled(false),addr_width(5)//,pipe0_reading_address(0)
pipe0_reading_address(0)
{ {
} }
...@@ -515,7 +514,7 @@ void RF24::startListening(void) ...@@ -515,7 +514,7 @@ void RF24::startListening(void)
// Restore the pipe0 adddress, if exists // Restore the pipe0 adddress, if exists
if (pipe0_reading_address){ if (pipe0_reading_address){
write_register(RX_ADDR_P0, reinterpret_cast<const uint8_t*>(&pipe0_reading_address), 5); write_register(RX_ADDR_P0, pipe0_reading_address, addr_width);
} }
// Flush buffers // Flush buffers
...@@ -821,7 +820,20 @@ void RF24::openWritingPipe(uint64_t value) ...@@ -821,7 +820,20 @@ void RF24::openWritingPipe(uint64_t value)
} }
/****************************************************************************/ /****************************************************************************/
void RF24::openWritingPipe(const uint8_t *address)
{
// Note that AVR 8-bit uC's store this LSB first, and the NRF24L01(+)
// expects it LSB first too, so we're good.
write_register(RX_ADDR_P0,address, addr_width);
write_register(TX_ADDR, address, 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);
}
/****************************************************************************/
static const uint8_t child_pipe[] PROGMEM = static const uint8_t child_pipe[] PROGMEM =
{ {
RX_ADDR_P0, RX_ADDR_P1, RX_ADDR_P2, RX_ADDR_P3, RX_ADDR_P4, RX_ADDR_P5 RX_ADDR_P0, RX_ADDR_P1, RX_ADDR_P2, RX_ADDR_P3, RX_ADDR_P4, RX_ADDR_P5
...@@ -841,7 +853,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) ...@@ -841,7 +853,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
// openWritingPipe() will overwrite the pipe 0 address, so // openWritingPipe() will overwrite the pipe 0 address, so
// startListening() will have to restore it. // startListening() will have to restore it.
if (child == 0) if (child == 0)
pipe0_reading_address = address; pipe0_reading_address = reinterpret_cast<uint8_t*>(&address);
if (child <= 6) if (child <= 6)
{ {
...@@ -860,6 +872,44 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) ...@@ -860,6 +872,44 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
} }
} }
/****************************************************************************/
void RF24::setAddressWidth(uint8_t a_width){
if(a_width -= 2){
write_register(SETUP_AW,a_width%4);
addr_width = (a_width%4) + 2;
}
}
/****************************************************************************/
void RF24::openReadingPipe(uint8_t child, const uint8_t *address)
{
// If this is pipe 0, cache the address. This is needed because
// openWritingPipe() will overwrite the pipe 0 address, so
// startListening() will have to restore it.
if (child == 0)
pipe0_reading_address = address;
if (child <= 6)
{
// For pipes 2-5, only write the LSB
if ( child < 2 ){
write_register(pgm_read_byte(&child_pipe[child]), address, addr_width);
}else{
write_register(pgm_read_byte(&child_pipe[child]), address, 1);
}
write_register(pgm_read_byte(&child_payload_size[child]),payload_size);
// Note it would be more efficient to set all of the bits for all open
// pipes at once. However, I thought it would make the calling code
// more simple to do it this way.
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
}
}
/****************************************************************************/ /****************************************************************************/
void RF24::closeReadingPipe( uint8_t pipe ) void RF24::closeReadingPipe( uint8_t pipe )
......
...@@ -51,7 +51,8 @@ private: ...@@ -51,7 +51,8 @@ private:
bool p_variant; /* False for RF24L01 and true for RF24L01P */ bool p_variant; /* False for RF24L01 and true for RF24L01P */
uint8_t payload_size; /**< Fixed size of payloads */ uint8_t payload_size; /**< Fixed size of payloads */
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */ bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */ const uint8_t *pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
uint8_t addr_width;
public: public:
...@@ -163,24 +164,26 @@ public: ...@@ -163,24 +164,26 @@ public:
bool write( const void* buf, uint8_t len ); bool write( const void* buf, uint8_t len );
/** /**
* Open a pipe for writing * New: Open a pipe for writing
* *
* Only one pipe can be open at once, but you can change the pipe * Only one pipe can be open at once, but you can change the pipe
* you'll listen to. Do not call this while actively listening. * you'll write to. Call stopListening() first.
* Remember to stopListening() first.
* *
* Addresses are 40-bit hex values, e.g.: * Addresses are assigned via a byte array, default is 5 byte address length
*
* Usage is exactly the same as before, except for declaring the array
* *
* @code * @code
* openWritingPipe(0xF0F0F0F0F0); * uint8_t addresses[][6] = {"1Node","2Node"};
* openWritingPipe(addresses[0]);
* @endcode * @endcode
* @see setAddressWidth
* *
* @param address The 40-bit address of the pipe to open. This can be * @param address The address of the pipe to open. Coordinate these pipe
* any value whatsoever, as long as you are the only one writing to it
* and only one other radio is listening to it. Coordinate these pipe
* addresses amongst nodes on the network. * addresses amongst nodes on the network.
*/ */
void openWritingPipe(uint64_t address);
void openWritingPipe(const uint8_t *address);
/** /**
* Open a pipe for reading * Open a pipe for reading
...@@ -189,24 +192,25 @@ public: ...@@ -189,24 +192,25 @@ public:
* reading pipes, and then call startListening(). * reading pipes, and then call startListening().
* *
* @see openWritingPipe * @see openWritingPipe
* @see setAddressWidth
* *
* @warning Pipes 1-5 should share the first 32 bits. * @warning Pipes 1-5 should share the same address, except the first byte.
* Only the least significant byte should be unique, e.g. * Only the first byte in the array should be unique, e.g.
* @code * @code
* openReadingPipe(1,0xF0F0F0F0AA); * uint8_t addresses[][6] = {"1Node","2Node"};
* openReadingPipe(2,0xF0F0F0F066); * openReadingPipe(1,addresses[0]);
* openReadingPipe(2,addresses[1]);
* @endcode * @endcode
* *
* @warning Pipe 0 is also used by the writing pipe. So if you open * @warning Pipe 0 is also used by the writing pipe. So if you open
* pipe 0 for reading, and then startListening(), it will overwrite the * pipe 0 for reading, and then startListening(), it will overwrite the
* writing pipe. Ergo, do an openWritingPipe() again before write(). * writing pipe. Ergo, do an openWritingPipe() again before write().
* *
* @todo Enforce the restriction that pipes 1-5 must share the top 32 bits
*
* @param number Which pipe# to open, 0-5. * @param number Which pipe# to open, 0-5.
* @param address The 40-bit address of the pipe to open. * @param address The 24, 32 or 40 bit address of the pipe to open.
*/ */
void openReadingPipe(uint8_t number, uint64_t address);
void openReadingPipe(uint8_t number, const uint8_t *address);
/** /**
* Close a pipe after it has been previously opened. * Close a pipe after it has been previously opened.
...@@ -584,6 +588,14 @@ public: ...@@ -584,6 +588,14 @@ public:
*/ */
void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready); void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
/**
* Set the address width from 3 to 5 bytes (24, 32 or 40 bit)
*
* @param a_width The address width to use: 3,4 or 5
*/
void setAddressWidth(uint8_t a_width);
/**@}*/ /**@}*/
/**@}*/ /**@}*/
...@@ -759,6 +771,48 @@ public: ...@@ -759,6 +771,48 @@ public:
*/ */
void disableCRC( void ) ; void disableCRC( void ) ;
/**@}*/
/**
* @name Deprecated
*
* Methods provided for backwards compabibility.
*/
/**@{*/
/**
* Open a pipe for reading
* @note For compatibility with old code only, see new function
*
* @warning Pipes 1-5 should share the first 32 bits.
* Only the least significant byte should be unique, e.g.
* @code
* openReadingPipe(1,0xF0F0F0F0AA);
* openReadingPipe(2,0xF0F0F0F066);
* @endcode
*
* @warning Pipe 0 is also used by the writing pipe. So if you open
* pipe 0 for reading, and then startListening(), it will overwrite the
* writing pipe. Ergo, do an openWritingPipe() again before write().
*
* @param number Which pipe# to open, 0-5.
* @param address The 40-bit address of the pipe to open.
*/
void openReadingPipe(uint8_t number, uint64_t address);
/**
* Open a pipe for writing
* @note For compatibility with old code only, see new function
* Addresses are 40-bit hex values, e.g.:
*
* @code
* openWritingPipe(0xF0F0F0F0F0);
* @endcode
*
* @param address The 40-bit address of the pipe to open.
*/
void openWritingPipe(uint64_t address);
private: private:
/** /**
...@@ -1085,6 +1139,7 @@ private: ...@@ -1085,6 +1139,7 @@ private:
* - Delays have been removed where possible to ensure maximum efficiency * - Delays have been removed where possible to ensure maximum efficiency
* - Full Due support with extended SPI functions * - Full Due support with extended SPI functions
* - ATTiny 24/44/84 25/45/85 now supported. * - ATTiny 24/44/84 25/45/85 now supported.
* - Raspberry Pi now supported
* - More! See the links below and class documentation for more info. * - More! See the links below and class documentation for more info.
* *
* If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a> * If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a>
...@@ -1114,6 +1169,7 @@ private: ...@@ -1114,6 +1169,7 @@ private:
* Note: ATTiny support is built into the library. Do not include SPI.h. <br> * Note: ATTiny support is built into the library. Do not include SPI.h. <br>
* ATTiny 85: D0(pin 5): MISO, D1(pin6) MOSI, D2(pin7) SCK, D3(pin2):CSN/SS, D4(pin3): CE <br> * ATTiny 85: D0(pin 5): MISO, D1(pin6) MOSI, D2(pin7) SCK, D3(pin2):CSN/SS, D4(pin3): CE <br>
* ATTiny 84: PA6:MISO, PA5:MOSI, PA4:SCK, PA7:CSN/SS, CE as desired <br> * ATTiny 84: PA6:MISO, PA5:MOSI, PA4:SCK, PA7:CSN/SS, CE as desired <br>
* - Raspberry Pi Support: See the readme at https://github.com/TMRh20/RF24/tree/master/RPi
* *
* @section More More Information * @section More More Information
* *
......
...@@ -265,8 +265,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty) ...@@ -265,8 +265,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
RF24::RF24(uint8_t _cepin, uint8_t _cspin, uint32_t _spi_speed): RF24::RF24(uint8_t _cepin, uint8_t _cspin, uint32_t _spi_speed):
ce_pin(_cepin), csn_pin(_cspin), spi_speed(_spi_speed), wide_band(true), p_variant(false), ce_pin(_cepin), csn_pin(_cspin), spi_speed(_spi_speed), wide_band(true), p_variant(false),
payload_size(32), dynamic_payloads_enabled(false), payload_size(32), dynamic_payloads_enabled(false),addr_width(5)//,pipe0_reading_address(0)
pipe0_reading_address(0)
{ {
} }
...@@ -477,7 +476,7 @@ bool RF24::begin(void) ...@@ -477,7 +476,7 @@ bool RF24::begin(void)
toggle_features(); toggle_features();
write_register(FEATURE,0 ); write_register(FEATURE,0 );
write_register(DYNPD,0); write_register(DYNPD,0);
// Reset current status // Reset current status
// Notice reset and flush is the last thing we do // Notice reset and flush is the last thing we do
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
...@@ -509,9 +508,9 @@ void RF24::startListening(void) ...@@ -509,9 +508,9 @@ void RF24::startListening(void)
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
// Restore the pipe0 adddress, if exists // Restore the pipe0 adddress, if exists
if (pipe0_reading_address) if (pipe0_reading_address){
write_register(RX_ADDR_P0, reinterpret_cast<const uint8_t*>(&pipe0_reading_address), 5); write_register(RX_ADDR_P0, pipe0_reading_address, addr_width);
}
// Flush buffers // Flush buffers
flush_rx(); flush_rx();
flush_tx(); flush_tx();
...@@ -805,6 +804,20 @@ void RF24::openWritingPipe(uint64_t value) ...@@ -805,6 +804,20 @@ void RF24::openWritingPipe(uint64_t value)
write_register(RX_PW_P0,payload_size); write_register(RX_PW_P0,payload_size);
} }
/****************************************************************************/
void RF24::openWritingPipe(const uint8_t *address)
{
// Note that AVR 8-bit uC's store this LSB first, and the NRF24L01(+)
// expects it LSB first too, so we're good.
write_register(RX_ADDR_P0,address, addr_width);
write_register(TX_ADDR, address, 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);
}
/****************************************************************************/ /****************************************************************************/
static const uint8_t child_pipe[] = static const uint8_t child_pipe[] =
...@@ -826,7 +839,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) ...@@ -826,7 +839,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
// openWritingPipe() will overwrite the pipe 0 address, so // openWritingPipe() will overwrite the pipe 0 address, so
// startListening() will have to restore it. // startListening() will have to restore it.
if (child == 0) if (child == 0)
pipe0_reading_address = address; pipe0_reading_address = reinterpret_cast<uint8_t*>(&address);
if (child <= 6) if (child <= 6)
{ {
...@@ -847,6 +860,45 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) ...@@ -847,6 +860,45 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
/****************************************************************************/ /****************************************************************************/
void RF24::setAddressWidth(uint8_t a_width){
if(a_width -= 2){
write_register(SETUP_AW,a_width%4);
addr_width = (a_width%4) + 2;
}
}
/****************************************************************************/
void RF24::openReadingPipe(uint8_t child, const uint8_t *address)
{
// If this is pipe 0, cache the address. This is needed because
// openWritingPipe() will overwrite the pipe 0 address, so
// startListening() will have to restore it.
if (child == 0)
pipe0_reading_address = address;
if (child <= 6)
{
// For pipes 2-5, only write the LSB
if ( child < 2 ){
write_register(pgm_read_byte(&child_pipe[child]), address, addr_width);
}else{
write_register(pgm_read_byte(&child_pipe[child]), address, 1);
}
write_register(pgm_read_byte(&child_payload_size[child]),payload_size);
// Note it would be more efficient to set all of the bits for all open
// pipes at once. However, I thought it would make the calling code
// more simple to do it this way.
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
}
}
/****************************************************************************/
void RF24::toggle_features(void) void RF24::toggle_features(void)
{ {
bcm2835_spi_transfer( ACTIVATE ); bcm2835_spi_transfer( ACTIVATE );
......
This diff is collapsed.
...@@ -44,13 +44,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -44,13 +44,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint8_t pipes[][6] = {"1Node","2Node"};
//const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = true, role_pong_back = false;
bool role = role_pong_back;
// Print preamble: // Print preamble:
printf("RF24/examples/pingtest/\n"); printf("RF24/examples/pingtest/\n");
...@@ -94,7 +95,7 @@ int main(int argc, char** argv){ ...@@ -94,7 +95,7 @@ int main(int argc, char** argv){
radio.startListening(); radio.startListening();
} }
// forever loop // forever loop
while (1) while (1)
{ {
...@@ -144,6 +145,7 @@ int main(int argc, char** argv){ ...@@ -144,6 +145,7 @@ int main(int argc, char** argv){
// Try again 1s later // Try again 1s later
// delay(1000); // delay(1000);
sleep(1); sleep(1);
} }
...@@ -156,7 +158,7 @@ int main(int argc, char** argv){ ...@@ -156,7 +158,7 @@ int main(int argc, char** argv){
{ {
// if there is data ready // if there is data ready
//printf("Check available...\n"); //printf("Check available...\n");
//delay(3);
if ( radio.available() ) if ( radio.available() )
{ {
// Dump the payloads until we've gotten everything // Dump the payloads until we've gotten everything
...@@ -167,19 +169,20 @@ int main(int argc, char** argv){ ...@@ -167,19 +169,20 @@ int main(int argc, char** argv){
radio.read( &got_time, sizeof(unsigned long) ); radio.read( &got_time, sizeof(unsigned long) );
radio.stopListening(); radio.stopListening();
//delay(1);
// Seem to need a delay, or the RPi is too quick // Seem to need a delay, or the RPi is too quick
radio.write( &got_time, sizeof(unsigned long) ); radio.write( &got_time, sizeof(unsigned long) );
//delay(1);
// Now, resume listening so we catch the next packets. // Now, resume listening so we catch the next packets.
radio.startListening(); radio.startListening();
//delay(1);
// Spew it // Spew it
printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time); printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
} }
//delay(5);
} }
} // forever loop } // forever loop
return 0; return 0;
......
...@@ -38,7 +38,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -38,7 +38,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint8_t addresses[][6] = {"1Node","2Node"};
bool role_ping_out = 1, role_pong_back = 0, role = 0; bool role_ping_out = 1, role_pong_back = 0, role = 0;
......
...@@ -35,8 +35,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -35,8 +35,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
const int min_payload_size = 4; const int min_payload_size = 4;
const int max_payload_size = 32; const int max_payload_size = 32;
...@@ -47,6 +46,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating ...@@ -47,6 +46,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
printf("RF24/examples/pingpair_dyn/\n"); printf("RF24/examples/pingpair_dyn/\n");
......
...@@ -40,13 +40,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -40,13 +40,14 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
uint8_t data[32]; uint8_t data[32];
unsigned long startTime, stopTime, counter, rxTimer=0; unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10 // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(7,8); RF24 radio(7,8);
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate. byte addresses[][6] = {"1Node","2Node"};
// Set up roles to simplify testing // Set up roles to simplify testing
boolean role; // The main role variable, holds the current role identifier boolean role; // The main role variable, holds the current role identifier
...@@ -45,10 +46,9 @@ void setup() { ...@@ -45,10 +46,9 @@ void setup() {
radio.begin(); // Start up the radio radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
radio.openWritingPipe(addresses[1]); // Open a writing pipe on pipe 0, with address 1
radio.openReadingPipe(1,addresses[0]); // Open a reading pipe on pipe 1, with address 0
radio.startListening(); // Start listening radio.startListening(); // Start listening
radio.printDetails(); // Dump the configuration of the rf unit for debugging radio.printDetails(); // Dump the configuration of the rf unit for debugging
} }
...@@ -123,6 +123,7 @@ void loop(void){ ...@@ -123,6 +123,7 @@ void loop(void){
role = role_ping_out; // Become the primary transmitter (ping out) role = role_ping_out; // Become the primary transmitter (ping out)
radio.openWritingPipe(addresses[0]); radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]); radio.openReadingPipe(1,addresses[1]);
} }
else if ( c == 'R' && role == role_ping_out ) else if ( c == 'R' && role == role_ping_out )
{ {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10 // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(7,8); RF24 radio(7,8);
// Topology // Topology
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate. byte addresses[][6] = {"1Node","2Node"}; // Radio pipe addresses for the 2 nodes to communicate.
// Role management: Set up role. This sketch uses the same software for all the nodes // Role management: Set up role. This sketch uses the same software for all the nodes
// in this system. Doing so greatly simplifies testing. // in this system. Doing so greatly simplifies testing.
......
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