Skip to content

Commit 2f7e448

Browse files
committed
Fix: Ext. timeout hang, examples, board support
- Initial support for Due and ATTiny boards - Fix for 0 timeout period causing hang - Remove unnecessary delays from startWrite - Cleaned up/Updated example files - Optimization is nearing completion
1 parent 6263bcc commit 2f7e448

31 files changed

+1341
-2542
lines changed

README.md

+27-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# Optimized High Speed Arduino driver for nRF24L01 2.4GHz Wireless Transceiver
2-
3-
Note: March 2014, this fork was just published and is still undergoing fine tuning.
4-
5-
Class documenation is now available at http://tmrh20.github.io/RF24/class_r_f24.html
6-
7-
See http://TMRh20.blogspot.com for an overview of the new functionality.
8-
9-
Design Goals: This library is designed to be...
10-
11-
* More compliat with the manufacturer specified operation of the chip
12-
* Utilize the capabilities of the radio to their full potential via Arduino
13-
* More reliable and feature rich
14-
* Easy for beginners to use
15-
* Consumed with a public interface that's similiar to other Arduino standard libraries
16-
* Built against the standard SPI library.
17-
18-
Please refer to:
19-
20-
* [Documentation Main Page](http://tmrh20.github.io/)
21-
* [Class Reference]( http://tmrh20.github.io/RF24/class_r_f24.html)
22-
* [Source Code](https://github.com/tmrh20/RF24)
23-
* [Downloads](https://github.com/tmrh20/RF24/archives/master)
24-
* [Chip Datasheet](http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf)
25-
26-
This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
27-
the SPI hardware will go into 'slave' mode.
2+
3+
Design Goals: This library is designed to be...
4+
5+
* More complianct with the manufacturer specified operation of the chip
6+
* More reliable and feature rich
7+
* Easy for beginners to use
8+
* Consumed with a public interface that's similiar to other Arduino standard libraries
9+
* Built against the standard SPI library.
10+
11+
March 2014: Optimization begun
12+
April 2014: Optimization nearing completion
13+
* The library has been tweaked to allow full use of the FIFO buffers for maximum transfer speeds
14+
* Changes to read() functionality have increased reliability and response
15+
* Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
16+
* Delays have been removed where possible to ensure maximum efficiency
17+
* More! See the links below and class documentation for more info.
18+
19+
Please refer to:
20+
21+
* [Documentation Main Page](http://tmrh20.github.io/)
22+
* [Class Reference]( http://tmrh20.github.io/RF24/classRF24.html)
23+
* [Source Code](https://github.com/tmrh20/RF24)
24+
* [Downloads](https://github.com/TMRh20/RF24/archive/master.zip)
25+
* [Chip Datasheet](http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf)
26+
27+
This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
28+
the SPI hardware will go into 'slave' mode.
2829

RF24.cpp

+70-17
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ void RF24::csn(int mode)
1919
// divider of 4 is the minimum we want.
2020
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
2121
#ifdef ARDUINO
22+
#if !defined( __AVR_ATtiny85__ ) && !defined( __AVR_ATtiny84__)
2223
SPI.setBitOrder(MSBFIRST);
2324
SPI.setDataMode(SPI_MODE0);
24-
SPI.setClockDivider(SPI_CLOCK_DIV4);
25+
#ifdef __arm__ // Shouldn't need to set the clock divider on DUE
26+
SPI.setClockDivider(21);
27+
#else
28+
SPI.setClockDivider(SPI_CLOCK_DIV4);
29+
#endif
30+
#endif
2531
#endif
2632
digitalWrite(csn_pin,mode);
2733
}
@@ -273,6 +279,8 @@ uint8_t RF24::getPayloadSize(void)
273279

274280
/****************************************************************************/
275281

282+
#if !defined (MINIMAL)
283+
276284
static const char rf24_datarate_e_str_0[] PROGMEM = "1MBPS";
277285
static const char rf24_datarate_e_str_1[] PROGMEM = "2MBPS";
278286
static const char rf24_datarate_e_str_2[] PROGMEM = "250KBPS";
@@ -328,6 +336,7 @@ void RF24::printDetails(void)
328336
printf_P(PSTR("PA Power\t = %S\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
329337
}
330338

339+
#endif
331340
/****************************************************************************/
332341

333342
void RF24::begin(void)
@@ -440,6 +449,7 @@ void RF24::powerDown(void)
440449
void RF24::powerUp(void)
441450
{
442451
write_register(CONFIG,read_register(CONFIG) | _BV(PWR_UP));
452+
delay(2);
443453
}
444454

445455
/******************************************************************/
@@ -484,8 +494,9 @@ bool RF24::writeBlocking( const void* buf, uint8_t len, unsigned long timeout )
484494

485495
if( get_status() & _BV(MAX_RT)){ //If MAX Retries have been reached
486496
reUseTX(); //Set re-transmit and clear the MAX_RT interrupt flag
497+
if(millis() - timer > timeout){ return 0; } //If this payload has exceeded the user-defined timeout, exit and return 0
487498
}
488-
if(millis() - timer > timeout){ return 0; } //If this payload has exceeded the user-defined timeout, exit and return 0
499+
489500
}
490501

491502
//Start Writing
@@ -548,32 +559,29 @@ void RF24::startFastWrite( const void* buf, uint8_t len ){ //TMRh20
548559

549560
//Added the original startWrite back in so users can still use interrupts, ack payloads, etc
550561
//Allows the library to pass all tests
551-
void RF24::startWrite( const void* buf, uint8_t len )
552-
{
553-
// Transmitter power-up
554-
write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );
555-
delayMicroseconds(150);
562+
void RF24::startWrite( const void* buf, uint8_t len ){
556563

557564
// Send the payload
558-
write_payload( buf, len );
559565

560-
// Allons!
566+
write_payload( buf, len );
561567
ce(HIGH);
562-
delayMicroseconds(15);
563568
ce(LOW);
569+
570+
564571
}
565572

566573
bool RF24::txStandBy(){
574+
567575
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
568576
if( get_status() & _BV(MAX_RT)){
569577
write_register(STATUS,_BV(MAX_RT) );
578+
ce(LOW);
570579
flush_tx(); //Non blocking, flush the data
571-
ce(LOW); //Set STANDBY-I mode
572580
return 0;
573581
}
574582
}
575583

576-
ce(LOW); //Set STANDBY-I mode
584+
ce(LOW); //Set STANDBY-I mode
577585
return 1;
578586
}
579587

@@ -584,12 +592,11 @@ bool RF24::txStandBy(unsigned long timeout){
584592
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
585593
if( get_status() & _BV(MAX_RT)){
586594
write_register(STATUS,_BV(MAX_RT) );
587-
if(timeout > 0){
588595
ce(LOW); //Set re-transmit
589596
ce(HIGH);
590-
if(millis() - start > timeout){ ce(LOW); flush_tx(); return 0; }
591-
592-
}
597+
if(millis() - start >= timeout){
598+
ce(LOW); flush_tx(); return 0;
599+
}
593600
}
594601
}
595602
ce(LOW); //Set STANDBY-I mode
@@ -1051,5 +1058,51 @@ void RF24::setRetries(uint8_t delay, uint8_t count)
10511058
write_register(SETUP_RETR,(delay&0xf)<<ARD | (count&0xf)<<ARC);
10521059
}
10531060

1054-
// vim:ai:cin:sts=2 sw=2 ft=cpp
1061+
1062+
1063+
1064+
1065+
1066+
#if defined (ATTINY)
1067+
1068+
#include "pins_arduino.h"
1069+
1070+
#if defined( __AVR_ATtiny85__ )
1071+
const static uint8_t _CS = PB4;
1072+
const static uint8_t _MOSI = PB1;
1073+
const static uint8_t _MISO = PB0;
1074+
const static uint8_t _SCK = PB2;
1075+
#endif
1076+
1077+
#if defined( __AVR_ATtiny84__ )
1078+
const static uint8_t _CS = 3;
1079+
const static uint8_t _MOSI = 5;
1080+
const static uint8_t _MISO = 4;
1081+
const static uint8_t _SCK = 6;
1082+
#endif
1083+
1084+
SPIClass SPI;
1085+
1086+
void SPIClass::begin() {
1087+
1088+
pinMode(_SCK, OUTPUT);
1089+
pinMode(_MOSI, OUTPUT);
1090+
pinMode(_MISO,INPUT);
1091+
1092+
digitalWrite(_MISO,HIGH);
1093+
digitalWrite(_SCK, LOW);
1094+
digitalWrite(_MOSI, LOW);
1095+
}
1096+
1097+
void SPIClass::end() {
1098+
1099+
pinMode(_SCK, INPUT);
1100+
pinMode(_MOSI, INPUT);
1101+
pinMode(_MISO,INPUT);
1102+
}
1103+
1104+
void SPIClass::setDataMode(byte mode){}
1105+
void SPIClass::setClockDivider(byte rate){}
1106+
1107+
#endif
10551108

0 commit comments

Comments
 (0)