2014 Contribution by tong67
Updated 2020 by 2bndy5 for the SpenceKonde ATTinyCore
The RF24 library uses the ATTinyCore by SpenceKonde
This sketch can be used to determine the best settle time values to use for RF24::csDelay in RF24::csn() (private function).
- See also
- RF24::csDelay
The settle time values used here are 100/20. However, these values depend on the actual used RC combination and voltage drop by LED. The intermediate results are written to TX (PB3, pin 2 – using Serial).
For schematic details, see introductory comment block in the rf24ping85.ino sketch.
26#if defined(ARDUINO) && !defined(__arm__)
27#if defined(__AVR_ATtinyX5__) || defined(__AVR_ATtinyX4__)
55uint8_t csnHighSettle = MAX_HIGH;
56uint8_t csnLowSettle = MAX_LOW;
65 if (CE_PIN != CSN_PIN) {
70 PORTB |= (1 << PINB2);
73 PORTB &= ~(1 << PINB2);
80uint8_t read_register(uint8_t reg) {
83 uint8_t result = SPI.transfer(0xff);
89void write_register(uint8_t reg, uint8_t value) {
99#ifndef __AVR_ATtinyX313__
103 Serial.begin(115200);
107 if (CSN_PIN != CE_PIN)
129 Serial.print(
"Scanning for optimal setting time for csn");
136 uint8_t bottom_success;
138 uint8_t value[] = { 5, 10 };
139 uint8_t limit[] = { MAX_HIGH, MAX_LOW };
140 uint8_t advice[] = { MAX_HIGH, MAX_LOW };
143 for (uint8_t k = 0; k < 2; k++) {
144 bottom_found =
false;
146 while (bottom_success < 255) {
147 csnHighSettle = limit[0];
148 csnLowSettle = limit[1];
151 while (i < 255 && success) {
152 for (uint8_t j = 0; j < 2; j++) {
153 write_register(
EN_AA, value[j]);
154 result = read_register(
EN_AA);
155 if (value[j] != result) {
163 Serial.print(
"Settle Not OK. csnHigh=");
164 Serial.print(limit[0], DEC);
165 Serial.print(
" csnLow=");
166 Serial.println(limit[1], DEC);
172 Serial.print(
"Settle OK. csnHigh=");
173 Serial.print(limit[0], DEC);
174 Serial.print(
" csnLow=");
175 Serial.println(limit[1], DEC);
178 if (limit[k] == MINIMAL) {
188 Serial.print(
"Settle value found for ");
190 Serial.print(
"csnHigh: ");
192 Serial.print(
"csnLow: ");
194 Serial.println(limit[k], DEC);
195 advice[k] = limit[k] + (limit[k] / 10);
198 Serial.print(
"Advised Settle times are: csnHigh=");
199 Serial.print(advice[0], DEC);
200 Serial.print(
" csnLow=");
201 Serial.println(advice[1], DEC);
#define pinMode(pin, direction)
#define delayMicroseconds(usec)
#define digitalWrite(pin, value)