I set up a single nrf24l01 receiver and 2 transmitters. The way the transmission works is as follows:
- Power the nrf24l01 using a GPIO pin (HIGH) on an ATTINY84
- Send a message e.g. "A" as a fixed size payload of 32 bits (4 bytes)
- Power off the transmitting nrf24l01 by changing the GPIO pin to LOW
- Sleep ATTINY84
- Interrupt on digital pin (button press) wakes up the ATTINY84 and then it repeats
So essentially, every button press the attiny wakes up and sends a single message to the receiver and goes back to sleep again.
The problem now is that when the transmitter sends once then goes to sleep, the receiver only receives the first transmission but then does not receive anything. However, If I transmit a message from a different transmitter, the receiver receives it but it is also able to receive a message from the 1st transmitter. Basically, I cannot send consecutive messages rather I have to take turns transmitting from different transmitters in order to send multiple messages from the same transmitter.
FYI this issue didn't exist and I was able to send consecutive messages before but I am not sure what I did exactly to make it happen.
NOTE that when I give constant power to the nrf24l01 transmitter, I am able to send consecutive messages without an issue (as opposed to powering the GPIO ON when transmitting and OFF when sleeping)
#define CE_PIN 2
#define CSN_PIN 9
#define PIN_BTN 7
#define PIN_RFPOWER 8
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
RF24 radio(CE_PIN, CSN_PIN);
const uint16_t address = 0xE0E0;
char msg[32] = "A";
void setup() {
pinMode(PIN_BTN,INPUT);
pinMode(PIN_RFPOWER,OUTPUT);
digitalWrite(PIN_RFPOWER,HIGH);
radioInit();
}
void loop(void){
radio.flush_tx(); // Not sure why I
radio.flush_rx(); // added these tbh
radio.write(&msg, sizeof(unsigned long));
while(digitalRead(PIN_BTN) == HIGH){
// Prevents multiple messages from being sent when button is held down
}
delay(1000);
sleep();
radioInit();
// delay(1000); // I tried giving the nrf time to initialise but that didn't help
}
void radioInit(){
digitalWrite(PIN_RFPOWER,HIGH);
radio.begin(); // Start up the radio
radio.setAutoAck(true); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(address); // Write to device address 'SimpleNode'
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void sleep() {
GIMSK |= _BV(PCIE0); // Enable Pin Change Interrupts
PCMSK0 |= _BV(PCINT7); // Use PB7 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
digitalWrite(PIN_RFPOWER,LOW);
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK0 &= ~_BV(PCINT7); // Turn off PB3 as interrupt pin
sleep_disable(); // Clear SE bit
// ADCSRA |= _BV(ADEN); // ADC on
sei(); // Enable interrupts
} // sleep
ISR(PCINT0_vect) {
// This is called when the interrupt occurs, but I don't need to do anything in it
}
Any ideas on how I can get consecutive messages to be transmitted and received by the receiver?