From 2c2775c07a4e14d127e331257052a42547e93b7d Mon Sep 17 00:00:00 2001 From: brendan <2bndy5@gmail.com> Date: Sun, 6 Dec 2020 20:39:35 -0800 Subject: [PATCH] ATTinyCore adjustments - use macros from SpenceKonde ATTinyCore - add macros for CSN settling times for when using the ATTinyCore --- RF24.cpp | 8 +++---- RF24_config.h | 4 ++-- .../timingSearch3pin/timingSearch3pin.ino | 24 ++++++++++--------- utility/ATTiny/RF24_arch_config.h | 9 +++++++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 83146b1a0..520d48a76 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -21,12 +21,12 @@ void RF24::csn(bool mode) } else { if (mode == HIGH) { - PORTB |= (1<CSN HIGH - delayMicroseconds(100); // allow csn to settle. + PORTB |= (1<CSN HIGH + delayMicroseconds(RF24_CSN_SETTLE_HIGH_DELAY); // allow csn to settle. } else { - PORTB &= ~(1<CSN LOW - delayMicroseconds(11); // allow csn to settle + PORTB &= ~(1<CSN LOW + delayMicroseconds(RF24_CSN_SETTLE_LOW_DELAY); // allow csn to settle } } // Return, CSN toggle complete diff --git a/RF24_config.h b/RF24_config.h index 448c5da58..361e70486 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -24,7 +24,7 @@ //#define MINIMAL //#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO - + /** * User access to internally used delay time (in microseconds) during RF24::powerUp() * @warning This default value compensates for all supported hardware. Only adjust this if you @@ -53,7 +53,7 @@ #include "utility/includes.h" //ATTiny -#elif defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny2313__) || defined (__AVR_ATtiny4313__) || defined (__AVR_ATtiny861__) +#elif defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny2313__) || defined (__AVR_ATtiny4313__) || defined (__AVR_ATtiny861__) || defined (__AVR_ATtinyX5__) || defined (__AVR_ATtinyX4__) || defined (__AVR_ATtinyX313__) || defined (__AVR_ATtinyX61__) #define RF24_TINY #include "utility/ATTiny/RF24_arch_config.h" diff --git a/examples/rf24_ATTiny/timingSearch3pin/timingSearch3pin.ino b/examples/rf24_ATTiny/timingSearch3pin/timingSearch3pin.ino index df78804ce..ea1cd6ac3 100644 --- a/examples/rf24_ATTiny/timingSearch3pin/timingSearch3pin.ino +++ b/examples/rf24_ATTiny/timingSearch3pin/timingSearch3pin.ino @@ -6,8 +6,9 @@ */ /* - * This sketch can be used to determine the best settle time values to use for - * RF24::csDelay in RF24::csn(). + * This sketch can determine the best settle time values to use for + * macros, defined as RF24_CSN_SETTLE_HIGH_DELAY and RF24_CSN_SETTLE_LOW_DELAY, + * in RF24::csn(). * The settle time values used here are 100/20. However, these values depend * on the actual used RC combiniation and voltage drop by LED. The * intermediate results are written to TX (PB3, pin 2 -- using Serial). @@ -47,9 +48,12 @@ #define MAX_LOW 100 #define MINIMAL 8 -uint8_t csnHighSettle = MAX_HIGH; -uint8_t csnLowSettle = MAX_LOW; -uint8_t status; // for storing the status byte captured over MISO +// Use these adjustable variables to test for best configuration to be used on +// the ATTiny chips. These variables are defined as macros in the library's +// RF24/utility/ATTiny/RF24_arch_config.h file. To change them, simply define +// the corresponding macro(s) before #include in your sketch. +uint8_t csnHighSettle = MAX_HIGH; // defined as RF24_CSN_SETTLE_HIGH_DELAY +uint8_t csnLowSettle = MAX_LOW; // defined as RF24_CSN_SETTLE_LOW_DELAY /****************************************************************************/ void ce(bool level) { @@ -76,7 +80,7 @@ void csn(bool mode) { uint8_t read_register(uint8_t reg) { csn(LOW); - status = SPI.transfer(R_REGISTER | reg); + SPI.transfer(R_REGISTER | reg); uint8_t result = SPI.transfer(0xff); csn(HIGH); return result; @@ -86,7 +90,7 @@ uint8_t read_register(uint8_t reg) void write_register(uint8_t reg, uint8_t value) { csn(LOW); - status = SPI.transfer(W_REGISTER | reg); + SPI.transfer(W_REGISTER | reg); SPI.transfer(value); csn(HIGH); } @@ -131,8 +135,6 @@ void setup(void) { uint8_t result; // used to compare read/write results with read/write cmds bool success = true; - uint8_t csnHigh = MAX_HIGH; - uint8_t csnLow = MAX_LOW; uint8_t bottom_success; bool bottom_found; uint8_t value[] = {5, 10}; @@ -184,7 +186,7 @@ void setup(void) { bottom_success++; } } - } + } // while (bottom_success < 255) Serial.print("Settle value found for "); if (k == 0) { Serial.print("csnHigh: "); @@ -194,7 +196,7 @@ void setup(void) { Serial.println(limit[k], DEC); advice[k] = limit[k] + (limit[k] / 10); limit[k] = 100; - } + } // for (uint8_t k = 0; k < 2; k++) Serial.print("Advised Settle times are: csnHigh="); Serial.print(advice[0], DEC); Serial.print(" csnLow="); diff --git a/utility/ATTiny/RF24_arch_config.h b/utility/ATTiny/RF24_arch_config.h index 0d17172e8..4b527a899 100644 --- a/utility/ATTiny/RF24_arch_config.h +++ b/utility/ATTiny/RF24_arch_config.h @@ -27,6 +27,15 @@ #define _SPI SPI +#if !defined(RF24_CSN_SETTLE_LOW_DELAY) +#define RF24_CSN_SETTLE_LOW_DELAY 11 +#endif + +#if !defined(RF24_CSN_SETTLE_HIGH_DELAY) +#define RF24_CSN_SETTLE_HIGH_DELAY 100 +#endif + + #ifdef SERIAL_DEBUG #define IF_SERIAL_DEBUG(x) ({x;}) #else