I'm using an RFM69HW with a bare Atmega328p running at 8mHz. I'm able to communicate with the module just fine but calls to send or sendWithRetry seems to block forever. Any ideas about what might be going on?
Here's the code I'm running:
#include <Arduino.h>
#include <avr/sleep.h>
#include <RFM69.h>
#include <RFM69_ATC.h>
#include <SPI.h>
#define FREQUENCY RF69_915MHZ
#define SECRET "ABCDEFGHIJKLMNOP"
#define ATC_RSSI -75
#define NETWORK_ID 100
#define NODE_ID 2
#define RECEIVER_ID 1
#define BUTTON_PIN 3
RFM69_ATC radio;
static volatile uint8_t button_pressed = 0;
void isr() {
sleep_disable();
detachInterrupt(digitalPinToInterrupt(BUTTON_PIN));
button_pressed = 1;
}
void sleep() {
//radio.sleep();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
noInterrupts();
sleep_enable();
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), isr, FALLING);
interrupts();
// sleep
sleep_cpu();
// wake
sleep_disable();
}
void setup() {
Serial.begin(115200);
// button
pinMode(BUTTON_PIN, INPUT_PULLUP);
// radio initialization
if (!radio.initialize(FREQUENCY, NODE_ID, NETWORK_ID)) {
Serial.println("error: could not initialize RFM69");
while (1);
}
radio.encrypt(SECRET);
radio.setHighPower();
radio.enableAutoPower(ATC_RSSI);
Serial.println("ready");
}
void loop() {
Serial.println("loop");
if (button_pressed) {
button_pressed = 0;
Serial.println("sending...");
radio.sendWithRetry(RECEIVER_ID, "hello", 5);
Serial.println("sent");
// put radio in RX mode
radio.receiveDone();
}
Serial.println("sleep");
Serial.flush();
sleep();
}
The receiver does receive the sent message but only the first once since the sender locks up after the first send.
Here's what I see on a serial console:
ready
loop
sleep
loop
sending...
I'm pressing the button between the "sleep" and the second "loop" line.