I have my own code for configuring digital IO pins. I'm using the PCA 10040 devKit board. When running in the debugger, on startup, the interrupts on the input pins seemed to worked 95% of the time. Every once in a while, it seemed that interrupts just weren't being triggered. It wasn't just my own digital input pins; it was also the buttons on the board. On the other hand, when not running in the debugger, I frequently had problems with the interrupts when I first powered the board. After cycling the power a bunch of times, it suddenly started working and everything was fine, so clearly there was some problem with the configuration code. It looks like I have fixed it, but I don't understand why, so I don't trust it.
I'm using the EVENTS_PORT event to capture the input pin changes. I'm not creating GPIOTE channels.
Here's my configuration routine.
void CpuPinInit(void) { CpuPinEnum i; //Disable the port event as an interrupt source during configuration. NRF_GPIOTE->INTENCLR = GPIOTE_INTENSET_PORT_Msk; for (i = CpuPinFIRST; i < CpuPinCOUNT; i++) { if (cpuPinConfigOnInit[i]) CpuPinConfigure(i); } //Clear any pending event port interrupt source. NRF_P0->LATCH = 0xFFFFFFFF; NRF_GPIOTE->EVENTS_PORT = 1; //Configure and enable the interrupt. NVIC_SetPriority(GPIOTE_IRQn, CPU_PIN_GPIO_IRQ_PRIORITY); NVIC_ClearPendingIRQ(GPIOTE_IRQn); NVIC_EnableIRQ(GPIOTE_IRQn); //Enable the port event as an interrupt source. NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk; }
I'm attempting to ensure there are no spurious interrupts on startup by clearing the latches and the EVENTS_PORT event register. As you can see in the code, I'm setting EVENTS_PORT to 1. That looks wrong to me. I should be setting it to 0, but setting it to 1 seemed to solve my problem. Can anyone shed some light on this?