0

When I call the delay() function on the ATtiny84 micro, it delays for the expected time, until I call the init() function on an RH_ASK object. After this, the micro seems to freeze.

#include <RH_ASK.h>
RH_ASK driver();

void setup() {
    delay(100); // works ok
    driver.init();
    delay(100); // freezes a long time (or maybe forever?)
}

1 Answer 1

2

After reading the source code, RH_ASK.cpp, I found a commented out macro.

// RH_ASK on ATtiny8x uses Timer 0 to generate interrupts 8 times per 
// bit interval. Timer 0 is used by Arduino platform for millis()/micros() 
// which is used by delay()
// Uncomment the define RH_ASK_ATTINY_USE_TIMER1 bellow, if you want to use 
// Timer 1 instead of Timer 0 on ATtiny
// Timer 1 is also used by some other libraries, e.g. Servo. Alway check 
// usage of Timer 1 before enabling this.
// Should be moved to header file
//#define RH_ASK_ATTINY_USE_TIMER1

In other words, the default behaviour of RadioHead ASK init() is to use Timer 0, which causes delay() (which uses millis()/micro()) to behave incorrectly.

To fix: Tell RadioHead ASK to use Timer 1. Because the RH_ASK_ATTINY_USE_TIMER1 macro is in the source and not the header (for now), you have to modify the actual RadioHead ASK source file, RH_ASK.cpp*. Un-comment the line #define RH_ASK_ATTINY_USE_TIMER1 which will use Timer 1 instead of Timer 0. Re-compile your code, and delay() should start working properly again.

* RH_ASK.cpp can be found in %USERPROFILE%\Documents\Arduino\libraries\RadioHead on Windows, if you installed RadioHead via the Arduino IDE library manager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.