@@ -19,9 +19,15 @@ void RF24::csn(int mode)
19
19
// divider of 4 is the minimum we want.
20
20
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
21
21
#ifdef ARDUINO
22
+ #if !defined( __AVR_ATtiny85__ ) && !defined( __AVR_ATtiny84__)
22
23
SPI.setBitOrder (MSBFIRST);
23
24
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
25
31
#endif
26
32
digitalWrite (csn_pin,mode);
27
33
}
@@ -273,6 +279,8 @@ uint8_t RF24::getPayloadSize(void)
273
279
274
280
/* ***************************************************************************/
275
281
282
+ #if !defined (MINIMAL)
283
+
276
284
static const char rf24_datarate_e_str_0[] PROGMEM = " 1MBPS" ;
277
285
static const char rf24_datarate_e_str_1[] PROGMEM = " 2MBPS" ;
278
286
static const char rf24_datarate_e_str_2[] PROGMEM = " 250KBPS" ;
@@ -328,6 +336,7 @@ void RF24::printDetails(void)
328
336
printf_P (PSTR (" PA Power\t = %S\r\n " ),pgm_read_word (&rf24_pa_dbm_e_str_P[getPALevel ()]));
329
337
}
330
338
339
+ #endif
331
340
/* ***************************************************************************/
332
341
333
342
void RF24::begin (void )
@@ -440,6 +449,7 @@ void RF24::powerDown(void)
440
449
void RF24::powerUp (void )
441
450
{
442
451
write_register (CONFIG,read_register (CONFIG) | _BV (PWR_UP));
452
+ delay (2 );
443
453
}
444
454
445
455
/* *****************************************************************/
@@ -484,8 +494,9 @@ bool RF24::writeBlocking( const void* buf, uint8_t len, unsigned long timeout )
484
494
485
495
if ( get_status () & _BV (MAX_RT)){ // If MAX Retries have been reached
486
496
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
487
498
}
488
- if ( millis () - timer > timeout){ return 0 ; } // If this payload has exceeded the user-defined timeout, exit and return 0
499
+
489
500
}
490
501
491
502
// Start Writing
@@ -548,32 +559,29 @@ void RF24::startFastWrite( const void* buf, uint8_t len ){ //TMRh20
548
559
549
560
// Added the original startWrite back in so users can still use interrupts, ack payloads, etc
550
561
// 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 ){
556
563
557
564
// Send the payload
558
- write_payload ( buf, len );
559
565
560
- // Allons!
566
+ write_payload ( buf, len );
561
567
ce (HIGH);
562
- delayMicroseconds (15 );
563
568
ce (LOW);
569
+
570
+
564
571
}
565
572
566
573
bool RF24::txStandBy (){
574
+
567
575
while ( ! (read_register (FIFO_STATUS) & _BV (TX_EMPTY)) ){
568
576
if ( get_status () & _BV (MAX_RT)){
569
577
write_register (STATUS,_BV (MAX_RT) );
578
+ ce (LOW);
570
579
flush_tx (); // Non blocking, flush the data
571
- ce (LOW); // Set STANDBY-I mode
572
580
return 0 ;
573
581
}
574
582
}
575
583
576
- ce (LOW); // Set STANDBY-I mode
584
+ ce (LOW); // Set STANDBY-I mode
577
585
return 1 ;
578
586
}
579
587
@@ -584,12 +592,11 @@ bool RF24::txStandBy(unsigned long timeout){
584
592
while ( ! (read_register (FIFO_STATUS) & _BV (TX_EMPTY)) ){
585
593
if ( get_status () & _BV (MAX_RT)){
586
594
write_register (STATUS,_BV (MAX_RT) );
587
- if (timeout > 0 ){
588
595
ce (LOW); // Set re-transmit
589
596
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
+ }
593
600
}
594
601
}
595
602
ce (LOW); // Set STANDBY-I mode
@@ -1051,5 +1058,51 @@ void RF24::setRetries(uint8_t delay, uint8_t count)
1051
1058
write_register (SETUP_RETR,(delay&0xf )<<ARD | (count&0xf )<<ARC);
1052
1059
}
1053
1060
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
1055
1108
0 commit comments