Skip to content

Commit

Permalink
ATTinyCore adjustments
Browse files Browse the repository at this point in the history
- use macros from SpenceKonde ATTinyCore
- add macros for CSN settling times for when using the ATTinyCore
  • Loading branch information
2bndy5 committed Dec 7, 2020
1 parent 5c46dbe commit 2c2775c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
8 changes: 4 additions & 4 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ void RF24::csn(bool mode)
}
else {
if (mode == HIGH) {
PORTB |= (1<<PINB2); // SCK->CSN HIGH
delayMicroseconds(100); // allow csn to settle.
PORTB |= (1<<PINB2); // SCK->CSN HIGH
delayMicroseconds(RF24_CSN_SETTLE_HIGH_DELAY); // allow csn to settle.
}
else {
PORTB &= ~(1<<PINB2); // SCK->CSN LOW
delayMicroseconds(11); // allow csn to settle
PORTB &= ~(1<<PINB2); // SCK->CSN LOW
delayMicroseconds(RF24_CSN_SETTLE_LOW_DELAY); // allow csn to settle
}
}
// Return, CSN toggle complete
Expand Down
4 changes: 2 additions & 2 deletions RF24_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
24 changes: 13 additions & 11 deletions examples/rf24_ATTiny/timingSearch3pin/timingSearch3pin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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 <RF24> 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) {
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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: ");
Expand All @@ -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=");
Expand Down
9 changes: 9 additions & 0 deletions utility/ATTiny/RF24_arch_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c2775c

Please sign in to comment.