Hi Everyone,
I'm having problems getting GPIOTE_IRQHandler_v() to run.
"NRF_GPIOTE->INTENSET = 1" causes my Nano 33 BLE to crash if "(GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos)" is enabled.
Otherwise it works as expected, i.e., when I connect an input signal from a 2nd Nano, "Serial.println("EVENTS_IN: Has Fired ++++")" executes successfully.
The following link is where I discovered how to set up the GPIOTE handler GPIOTE Handler
I'm compiling using the Arduino IDE and source files. Please let me know your ideas. Here's my program...
#include <nrf.h>
#define PIN_GPIO (2) // ~D10 = P1.02 ... Nano 33 BLE
#define PORT (1)
void setup()
{
Serial.begin(115200);
// Configure PIN_GPIO as input
// ---------------------------
NRF_GPIO->DIRSET = GPIO_DIRSET_PIN2_Input << GPIO_DIRSET_PIN2_Pos; // Not actually required based on "Input" being the default
// Configure GPIOTE
// ----------------
NRF_GPIOTE->CONFIG[0] =
(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) |
(GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos) | // (Commenting this line stops the board crashing. But: GPIOTE_IRQHandler_v() still doesn't run)
(PORT << GPIOTE_CONFIG_PORT_Pos) | // (Although it's actually pointless commenting the above line because then no IN[n] events will be generated)
(PIN_GPIO << GPIOTE_CONFIG_PSEL_Pos);
// NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos (same as INTENSET = 1)
NRF_GPIOTE->INTENSET = 1; // Set = 1 & [0] = Bit number 0 (Commenting this line stops the board crashing, which causes "EVENTS_IN: Has Fired ++++" to successfully be displayed periodically)
NVIC_EnableIRQ(GPIOTE_IRQn);
}
volatile bool action = false;
extern "C" void GPIOTE_IRQHandler_v()
{
if (NRF_GPIOTE->EVENTS_IN[0] != 0)
{
NRF_GPIOTE->EVENTS_IN[0] = 0;
action = true;
}
}
unsigned long currentTime = 0;
unsigned long previousTime = 0;
unsigned int deltaTime = 0;
void loop()
{
currentTime = micros();
deltaTime += currentTime - previousTime;
previousTime = currentTime;
if (deltaTime > 10000) // 100Hz
{
deltaTime = 0;
if (NRF_GPIOTE->EVENTS_IN[0] != 0)
{
NRF_GPIOTE->EVENTS_IN[0] = 0;
Serial.println("EVENTS_IN: Has Fired ++++");
}
else
Serial.println("EVENTS_IN: Has Not Fired ---");
if (action)
{
action = false;
Serial.println("In Action Loop ++++");
}
else
Serial.println("Not In Action Loop ---");
}
}