From cc7e0a2f19264852847edd42c4231584da8ec104 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Mon, 12 Sep 2011 19:11:37 -0700 Subject: [PATCH 1/5] Fixed a bug when pipe 0 was NOT being used for writing. --- RF24.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 6ad87e4..5ef182d 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -247,8 +247,9 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty) /****************************************************************************/ RF24::RF24(uint8_t _cepin, uint8_t _cspin): - ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false), payload_size(32), - ack_payload_available(false), dynamic_payloads_enabled(false) + ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false), + payload_size(32), ack_payload_available(false), dynamic_payloads_enabled(false), + pipe0_reading_address(0) { } @@ -381,8 +382,9 @@ void RF24::startListening(void) write_register(CONFIG, read_register(CONFIG) | _BV(PWR_UP) | _BV(PRIM_RX)); write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); - // Restore the pipe0 adddress - write_register(RX_ADDR_P0, reinterpret_cast(&pipe0_reading_address), 5); + // Restore the pipe0 adddress, if exists + if (pipe0_reading_address) + write_register(RX_ADDR_P0, reinterpret_cast(&pipe0_reading_address), 5); // Flush buffers flush_rx(); From dceef7b45ec2ae29025089fea2fa9dcdf411aea0 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Mon, 12 Sep 2011 19:13:07 -0700 Subject: [PATCH 2/5] Added more information about whether the write was successful. --- examples/pingpair/pingpair.pde | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/pingpair/pingpair.pde b/examples/pingpair/pingpair.pde index 05254c4..2bf2267 100644 --- a/examples/pingpair/pingpair.pde +++ b/examples/pingpair/pingpair.pde @@ -144,7 +144,12 @@ void loop(void) // Take the time, and send it. This will block until complete unsigned long time = millis(); printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); + bool ok = radio.write( &time, sizeof(unsigned long) ); + + if (ok) + printf("ok..."); + else + printf("failed.\n\r"); // Now, continue listening radio.startListening(); From 7ad1b409fe180b7c37aeecefb08bc4f93c503e5d Mon Sep 17 00:00:00 2001 From: Greg Copeland Date: Mon, 12 Sep 2011 19:21:49 -0700 Subject: [PATCH 3/5] More debugging information. --- RF24.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RF24.cpp b/RF24.cpp index 5ef182d..35eab2b 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -298,10 +298,12 @@ void RF24::printDetails(void) const char * rf24_datarate_e_str[] = { "1MBPS", "2MBPS", "250KBPS" }; const char * rf24_model_e_str[] = { "nRF24L01", "nRF24L01+" } ; const char * rf24_crclength_e_str[] = { "Disabled", "8 bits", "16 bits" } ; + const char * rf24_pa_dbm_e_str[] = { "PA_MIN", "PA_LOW", "LA_MED", "PA_HIGH"} ; printf_P(PSTR("Data Rate\t = %s\n\r"),rf24_datarate_e_str[getDataRate()]); printf_P(PSTR("Model\t\t = %s\n\r"),rf24_model_e_str[isPVariant()]); printf_P(PSTR("CRC Length\t = %s\n\r"),rf24_crclength_e_str[getCRCLength()]); + printf_P(PSTR("PA Power\t = %s\n\r"),rf24_pa_dbm_e_str[getPALevel()]); } /****************************************************************************/ From a4cabc66a2b15c45182718c9302385d7378b4447 Mon Sep 17 00:00:00 2001 From: Greg Copeland Date: Wed, 17 Aug 2011 12:02:51 -0500 Subject: [PATCH 4/5] Yet more merge cleanup. Changes default channel to be US/Internationally legal while ensuring no spectrum bleed. --- RF24.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RF24.cpp b/RF24.cpp index 35eab2b..1e87ef6 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -370,7 +370,9 @@ void RF24::begin(void) write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); // Set up default configuration. Callers can always change it later. - setChannel(100); + // This channel should be universally safe and not bleed over into adjacent + // spectrum. + setChannel(76); // Flush buffers flush_rx(); From a28e2361fc1bab48117cff68d07ab9ee9951948f Mon Sep 17 00:00:00 2001 From: maniacbug Date: Mon, 12 Sep 2011 19:27:27 -0700 Subject: [PATCH 5/5] SPI bus speed divider to 4, suggested by Greg Copeland. Also removed duplicated spi setup out of begin(), as it's all in csn() --- RF24.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 1e87ef6..eae7a45 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -28,9 +28,13 @@ void RF24::csn(int mode) { + // Minimum ideal SPI bus speed is 2x data rate + // If we assume 2Mbs data rate and 16Mhz clock, a + // divider of 4 is the minimum we want. + // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); - SPI.setClockDivider(SPI_CLOCK_DIV2); + SPI.setClockDivider(SPI_CLOCK_DIV4); digitalWrite(csn_pin,mode); } @@ -315,17 +319,7 @@ void RF24::begin(void) pinMode(csn_pin,OUTPUT); // Initialize SPI bus - // Minimum ideal SPI bus speed is 2x data rate - // If we assume 2Mbs data rate and 16Mhz clock, a - // divider of 4 is the minimum we want. - // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz - // We'll use a divider of 2 which will work up to - // MCU speeds of 20Mhz. - // CLK:BUS 8Mhz:4Mhz, 16Mhz:8Mhz, or 20Mhz:10Mhz (max) SPI.begin(); - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); - SPI.setClockDivider(SPI_CLOCK_DIV2); ce(LOW); csn(HIGH);