RFM69 waking up MCU with IRQ



  • My RFM69 seems to be waking my Atmega328P from sleep using IRQ almost immediately after going to sleep (from the logs: MCO:SLP:WUP=1). From my understanding, the IRQ pin is used by the RFM69 in receive mode to wake up the MCU should it receive a message. However, as my node is purely a sensor node with no receive function, it is strange that it keeps getting awoken by IRQ. Is this triggered by the ACK message from the GW because it seems that the ACK is already handled after the sending of the message?
    If all else fails, is there any way to disable the IRQ in software or should I just cut the PCB trace?

    Any advice will be greatly appreciated.

    Logs:

    
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    208 MCO:BGN:INIT NODE,CP=RPNNA---,FQ=8,REL=255,VER=2.3.2
    335 TSM:INIT
    350 TSF:WUR:MS=0
    368 TSM:INIT:TSP OK
    389 TSF:SID:OK,ID=1
    411 TSM:FPAR
    430 ?TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2502 !TSM:FPAR:NO REPLY
    2527 TSM:FPAR
    2545 ?TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2779 TSF:MSG:READ,0-0-1,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    2836 TSF:MSG:FPAR OK,ID=0,D=1
    4622 TSM:FPAR:OK
    4638 TSM:ID
    4653 TSM:ID:OK
    4667 TSM:UPL
    4691 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4931 TSF:MSG:READ,0-0-1,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    4988 TSF:MSG:PONG RECV,HP=1
    5019 TSM:UPL:OK
    5036 TSM:READY:ID=1,PAR=0,DIS=1
    5079 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    5308 TSF:MSG:READ,0-0-1,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    5380 TSF:MSG:SEND,1-1-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    5464 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    7544 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=OK:Motion Sensor
    7639 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    7720 TSF:MSG:SEND,1-1-0-0,s=0,c=0,t=1,pt=0,l=0,sg=0,ft=0,st=OK:
    7794 TSF:MSG:SEND,1-1-0-0,s=1,c=0,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
    7872 TSF:MSG:SEND,1-1-0-0,s=2,c=0,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
    7948 TSF:MSG:SEND,1-1-0-0,s=3,c=0,t=23,pt=0,l=0,sg=0,ft=0,st=OK:
    8017 MCO:REG:REQ
    8044 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    8271 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    8329 MCO:PIM:NODE REG=1
    8355 MCO:BGN:STP
    8374 MCO:BGN:INIT OK,TSP=1
    8411 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    8488 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    8566 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    8644 TSF:MSG:SEND,1-1-0-0,s=3,c=1,t=24,pt=2,l=2,sg=0,ft=0,st=OK:0
    8724 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:0
    8794 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
    8847 TSF:TDI:TSL
    8865 MCO:SLP:WUP=1
    8886 TSF:TRI:TSB
    9117 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
    9195 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    9273 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    9351 TSF:MSG:SEND,1-1-0-0,s=3,c=1,t=24,pt=2,l=2,sg=0,ft=0,st=OK:0
    9428 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:0
    9498 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
    9553 TSF:TDI:TSL
    9572 MCO:SLP:WUP=1
    9592 TSF:TRI:TSB
    9619 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
    9697 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    9775 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    9852 TSF:MSG:SEND,1-1-0-0,s=3,c=1,t=24,pt=2,l=2,sg=0,ft=0,st=OK:0
    9930 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:0
    10002 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
    10057 TSF:TDI:TSL
    10076 MCO:SLP:WUP=1
    10096 TSF:TRI:TSB
    10127 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    10205 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    10489 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    10569 TSF:MSG:SEND,1-1-0-0,s=3,c=1,t=24,pt=2,l=2,sg=0,ft=0,st=OK:0
    10647 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:0
    10719 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
    10774 TSF:TDI:TSL
    10792 MCO:SLP:WUP=1
    10815 TSF:TRI:TSB
    10844 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
    10924 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    11001 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=OK:0
    11081 TSF:MSG:SEND,1-1-0-0,s=3,c=1,t=24,pt=2,l=2,sg=0,ft=0,st=OK:0
    11159 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:0
    11231 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
    11286 TSF:TDI:TSL
    

    Code:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_BAUD_RATE 9600
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    #define MY_RADIO_RFM69
    #define MY_RFM69_FREQUENCY RFM69_868MHZ
    //#define MY_RADIO_RFM95
    
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_NETWORKID 100
    #define MY_RFM69_TX_POWER_DBM 10
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 1200000; // Sleep time between reports (in milliseconds) 
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define LDR_SENSOR_1 A0
    #define LDR_SENSOR_2 A1
    #define BATTERY_SENSE_PIN A2
    
    
    // Initialize motion message
    MyMessage motion(0, V_TRIPPED); 
    MyMessage firstLDR(1, V_LEVEL);
    MyMessage secondLDR(2, V_LEVEL);
    MyMessage batteryMsg(3, V_VAR1);
    
    void setup()
    {
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      pinMode(LDR_SENSOR_1, INPUT);
      pinMode(LDR_SENSOR_2, INPUT);
      pinMode(BATTERY_SENSE_PIN, INPUT);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Motion Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(0, S_MOTION);
      present(1, S_LIGHT_LEVEL);
      present(2, S_LIGHT_LEVEL);
      present(3, S_CUSTOM);
    }
    
    void loop()
    {
      // Read digital motion value
      bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
      int light1 = analogRead(LDR_SENSOR_1);
      int light2 = analogRead(LDR_SENSOR_2); 
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      if(sensorValue > 930) sensorValue = 930;
      sensorValue = map(sensorValue,0,930,0,100);
      /*
      Serial.print("Motion: "); Serial.println(tripped);
      Serial.print("LDR 1: "); Serial.println(light1);
      Serial.print("LDR 2: "); Serial.println(light2);
      Serial.print("Battery Sensor Value: "); Serial.println(sensorValue);
      Serial.print("Battery Percentage: "); Serial.println(batteryPerc);
      */
      
      send(motion.set(tripped?"1":"0"));  // Send tripped value to gw
      send(firstLDR.set(light1));
      send(secondLDR.set(light2));
      send(batteryMsg.set(sensorValue));
      sendBatteryLevel(sensorValue);
    
      // Sleep until interrupt comes in on motion sensor. Send update every ten seconds for testing.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, 10000);
    }
    


  • A bit of testing and I've found the culprit of waking up from sleep. It turns out MCO:SLP:WUP=1 refers to the ATMEGA328P being woken up by the user-defined interrupt pin (sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, 10000);). This was connected to a RCWL-0516 motion sensor and it turns out the sensor is highly sensitive to any form of radio interference which in this case is the RFM69. As such this issue has nothing to do with the IRQ of the RFM69



  • This seems to be a fairly common problem with PIR motion sensors.
    One trick is to add a short sleep statement before your final one to let all the voltages settle:

    // Short sleep to let voltages settle  (change duration as needed)
    sleep(500);
    
      // Sleep until interrupt comes in on motion sensor. Send update every ten seconds for testing.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, 10000);
    code_text
    

Log in to reply
 

Suggested Topics

11
Online

11.4k
Users

11.1k
Topics

112.7k
Posts