This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can't Get an Interrupt to Execute

Gentlemen:

I'm new to Nordic processors, but I have implemented projects with Silabs Gecko and ATTiny processors in the past.  I'm working on a project for a consumer product with an Arduino Nano 33 BLE that uses the Nordic RNF52840 processor (I picked this board because of its tiny footprint and unique peripherals).  Arduino, as yet, still hasn't offered their own software tools for timers and interrupts, so I'm largely using Nordic code.

I'm having a terrible time getting a simple hardware interrupt to work.  It's as if the interrupts are not properly enabled or something.  Here is my basic code.  I am using simple hex to set registers to be more understandable than the long variable names.  I'm a mechanical engineer by trade, so please excuse my poor coding technique.

#include <nrf.h>
#include "nrf_timer.h"
#include "nrf_gpio.h"

const int epin = 2;
int LED = LED_BUILTIN;
uint32_t last_ecount = 0;

void setup() {

    nrf_gpio_cfg_output(LED);                           //set built-in LED pin as output
    nrf_gpio_cfg_input(epin, NRF_GPIO_PIN_PULLUP);      //set pin 2 as pullup input

    NVIC_EnableIRQ(GPIOTE_IRQn);                        //enable interrupts
    NRF_GPIOTE->CONFIG[0] = 0x00010201;                 //low-to-high, pin2, event mode
    NRF_GPIOTE->INTENSET = 0x00000001;                  //enable IN[0]
    
    NRF_TIMER1->TASKS_STOP = 1;
    NRF_TIMER1->MODE = 0;
    NRF_TIMER1->BITMODE = 3;                            //timer1 32-bit mode
    NRF_TIMER1->PRESCALER = 0;                          //use full system clock for timer1: 16 MHz
    NRF_TIMER1->TASKS_CLEAR = 1;
    NRF_TIMER1->CC[0] = 0;                              //zero timer1
    NRF_TIMER1->TASKS_START = 1;                        //start timer1
...

}

void loop(){...}

void GPIOTE_IRQHandler(void){
    uint32_t count = 0;
    
    if(NRF_GPIOTE->EVENTS_IN[0] == 1){                  //filter interrupt for wave E
        NRF_GPIOTE->EVENTS_IN[0] = 0;                   //clear interrupt flag
        NRF_TIMER1->TASKS_CAPTURE[0] = 1;               //capture timer1 value in CC0
        count = NRF_TIMER1->CC[0] - last_ecount;        //time elaspsed for one wave (CC0)
        last_ecount = count;                            //reset for next count
    }
}

Pin2 gets a square wave and the object is to measure the period of the wave (which is then Bluetoothed to another processor). I have troubleshooted the input and know that I'm getting a signal on GPIO2 (I can light an LED using that input pin number).  But when I run the code I get no interrupt at all, ever.  I don't even get an interrupt flag NRF_GPIOTE->EVENTS_IN[0].

I feel like I've tried everything and I'm at wits end.  I'm hoping that there is something simple and stupid I'm doing/not doing. 

Does anyone see my error?  Thanks for your help.

Don

DG Devices

Parents Reply
  • I had originally tried the Arduino interrupt method.  I tried it again today to verify.  I even tried explicitly using the numeral "2" for the pin.  You can't get any simpler than this...

    void setup(){
    Serial.begin(9600); //start display serial
    while (!Serial);
    
    attachInterrupt(2, estring_ISR, RISING);
    }
    
    void loop(){
    }
    
    void estring_ISR(void){
    Serial.println("interrupt occurred");
    }

    When run, this code refuses to interrupt when a signal is applied to pin 2 (literally jumping pin 2 to 3.3V and to ground).  I know the pin is not bad because I can use it elsewhere just fine.

    It's as if I'm using the wrong pin.  I looked over the Arduino core code that you posted and it looks like my code should work.  I can't figure it out.

    Don

Children
No Data
Related