Tagged: ,

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #15373
    maksz
    Participant

    Hi! I have a problem with SPI after wakeup. I use nrf24l01 radio. When I set powerDown arduino gets wrong data. The program lights diode when it receives 0 and vice versa. The problem is when it goes power down and wakes up from an interrupt (onReceive), it reads byte wrong. I checked on serial port and it reads 1 instead of 0, 0 instead of 1 and it randomly changes. The data which the radio receives is correct. If there is no power down the program is working as expected. I can’t figure it out. I use version 1.8. Thanks.

    #include <LowPower.h>
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    
    #define diode 5
    
    RF24 radio(7, 8); // CE, CSN
    
    const byte address[6] = "00001";
    
    volatile unsigned long pingTime = 0;;
    
    void onReceive(){
      bool message;
      radio.read(&message, sizeof(message));
      digitalWrite(diode, !message);
      pingTime = millis();
    }
    
    void connectionLost(){
      digitalWrite(diode, LOW);
      delay(424);
      digitalWrite(diode, HIGH);
      delay(424);
    }
    
    void setup() {
      pinMode(diode, OUTPUT);
      digitalWrite(diode, HIGH);
      radio.begin();
      radio.openReadingPipe(0, address);
      radio.setPALevel(RF24_PA_MAX);
      radio.maskIRQ(1,1,0);
      radio.setChannel(29);
      radio.setDataRate(RF24_2MBPS);
      radio.startListening();
      attachInterrupt(0, onReceive, LOW);
      
      if (radio.available()){
        onReceive();
      }
      pingTime = millis();
    }
    
    void loop() {
      unsigned long timeNow = millis();
      noInterrupts();
      bool isTimeout = timeNow - pingTime > 9000;
      bool ISRErrCheck = pingTime <= timeNow;
      interrupts();
      if(isTimeout && ISRErrCheck){
        connectionLost();
      }
      LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); //NOT working if present
    }
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.