Interrupts doesn't work on NRF5

  • Hello,
    Sorry for my bad english, I'm from Germany and my school english is about 20 years ago.
    I'm trying to get this board working with Interrupts.

    I try the sketch from NeverDie and modify the pin configuration, but it doen't work. Then I take an example from ReadBearLabs and transfer MySensor routines into it. But this also doesn't work. Only when I use "My_Core_only" then the Interrupts are working pretty well, but when I disable "My_Core_only" the Interrupt doesn't work.

    // SUMMARY: This demo sketch runs on the AM612 PIR v607 PCBto transmit battery voltage (heartbeat) and motion detections to a MySensors gateway using MySensors protocols.
    // Note: because this is a passive node, node ID must be set manually to a unique sensor node ID:
    #define MY_NODE_ID 143  // Passive mode requires static node ID
    //#define MY_CORE_ONLY
    #define MY_PASSIVE_NODE
    #define MY_RADIO_NRF5_ESB
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     * Created by Henrik Ekblad <>
     * Copyright (C) 2013-2017 Sensnology AB
     * Full contributor list:
     * Documentation:
     * Support Forum:
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     * Version 1.0 - tekka
     * Passive node example: This is a passive & independent reporting node
    // This demo sketch also draws from the MySensor's example MotionSensor sketch.
    #define IS_NRF51  //true iff the target is an nRF51.  If an nRF52, then comment this line out!
    #define SHORT_WAIT 50
    // Enable debug prints
    //#define MY_DEBUG
    #define PIN_LED1                (4) // 4 is sensor LED , 1 is onboard LED
    #define LED_BUILTIN          PIN_LED1
    #define PIN_SENSOR1                (10) // 2 is waterleak, 10 is PIR , 3 is Pin5/INT
    #define SENSOR1         PIN_SENSOR1
    #include <MySensors.h>
    //#define CHILD_ID_TEMP 1  //definitions contributed by smilvert (see above credit)
    #define CHILD_ID 2   // Id of the motion sensor child
    #define ID_S_MULTIMETER        28
    // Initialize general message
    //MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msg(CHILD_ID, V_TRIPPED);
    float batteryVoltage=0;  
    /*#include "nrf_temp.h"
    float read_temp_value(){
      float temp=0;
      // Starten Sie die Temperaturmessung. 
      // Warten Sie, bis die Temperaturmessung abgeschlossen ist.
      while (NRF_TEMP->EVENTS_DATARDY == 0){
        // Do nothing.}
      // Lesen Sie den Temperaturwert vom Sensor ab
      // Die Genauigkeit beträgt 0,25 Grad Celsius <=> 1 Einheit = 0,25 Grad Celsius
      // Teile durch 4, um einen C-Wert zu erhalten
      temp = ((float)nrf_temp_read() / 4.);
      // Hoàn thành quá trình đo. 
      NRF_TEMP->TASKS_STOP = 1; 
      return temp;
    void blinkityBlink(uint8_t repetitions) {
      for (int x=0;x<repetitions;x++) {
        digitalWrite(LED_BUILTIN ,HIGH);
        digitalWrite(LED_BUILTIN ,LOW);
        digitalWrite(LED_BUILTIN ,HIGH);
        digitalWrite(LED_BUILTIN ,LOW);    
        if (x<(repetitions-1)) {  //skip waiting at the end of the final repetition
    void handle_irq3(void) {
      if(HIGH == digitalRead(SENSOR1)){
          digitalWrite(LED_BUILTIN , HIGH);
          send(msg.set("1"));  // motion detected
          digitalWrite(LED_BUILTIN , LOW);
           send(msg.set("0"));  // send all-clear to prepare for future detections
    void presentation()
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("NRF Motion Sensor", "1.0");
       // wait(SHORT_WAIT);
       // present(CHILD_ID_TEMP, S_TEMP,"Onboard Temperature");
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_MOTION,"Motion Sensor");
      present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Station");
    void setup() {
        // put your setup code here, to run once:
      pinMode(LED_BUILTIN , OUTPUT);
        digitalWrite(LED_BUILTIN , LOW);
      blinkityBlink(5);  //signify power-up and start of operations
      // set interrupts, pin default is HIGH
      attachInterrupt(SENSOR1, handle_irq3, CHANGE);
    void loop() {
      // put your main code here, to run repeatedly:
      batteryVoltage=((float)hwCPUVoltage())/1000.0;  //take voltage measurement after transmission to hopefully measure lowest voltage that occurs. 
      send(msg_S_MULTIMETER_V_VOLTAGE.set(batteryVoltage,3));  //send battery voltage with 3 decimal places
      sleep(900000); //sleep 15 min

  • Nobody can help?

  • Hardware Contributor

    @tiwo85 said in Interrupts doesn't work on NRF5:

    Nobody can help?

    Hello, it seems everyone missed it last time you post it... Maybe the best would be to tag @NeverDie he should have a script working somewhere.

    Have you tried to use interrupts the "normal" way with mysensors sleep function in the new 2.3 version ?
    There's also an hardware problem with nrf51 (not on NRF52) that makes it use a lot of power (around 1mA) in sleep with the "normal" interrupt, so it needs some tricks to either use low power comparator (LPCOMP, search for it you should find a script using it from @NeverDie) or interrupt with PORT mode but that's more complex to implement. I made a script using it in the big NRF5 thread but with only one interrupt to use go for the LPCOMP version.

  • My lib is still on 2.2 and I think I installed it not in the right way. I will give it a try.

Log in to reply

Suggested Topics

  • 3
  • 24
  • 2
  • 1
  • 2
  • 2