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

nRF51 enable interrupt pin not working: nrf_drv_gpiote_in_event_enable

Hi,

on my board I have a nRF51 and a LIS2DH accelerometer. I want to enable an interrupt pin INT1, so if the LIS2DH sends an interrupt event (pin change from high to low or vice versa) because of an acceleration event, some actions like wake up or sleep the nRF mcu can be performed. To register the pin interrupt I use this code snippet:

void LIS2DH_INT1_init(nrf_drv_gpiote_pin_t pinIn){
// config INT1 interrupt to wake up mcu from accelerometer
ret_code_t err_code;

// DO NOT USE GPIOTE_CONFIG_IN_SENSE_LOTOHI(true), bug in this NRF51822 revision, individual pin interrupts (true)
// uses HF and 1mA current!

	
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); 	// false = no high accuracy												in_config.pull = NRF_GPIO_PIN_NOPULL;  	//NRF_GPIO_PIN_PULLUP; NRF_GPIO_PIN_NOPULL

// Initialize Interrupt Pin
err_code = nrf_drv_gpiote_in_init(pinIn, &in_config, LIS2DH_INT1_handler);		// interrupt handler for INT1
APP_ERROR_CHECK(err_code);

// Enable Interrupts from interrupt pin
nrf_drv_gpiote_in_event_enable(pinIn, true);		// pinIn = ACC_INT1_PIN

nrf_delay_ms(1000);
printf ("ACC Int pin %lu is %s\r\n", pinIn, nrf_drv_gpiote_in_is_set(pinIn) ? "enabled": "not enabled ERROR");}

The GPIO ACC_INT1_PIN for the Lis2DH accelerometer is 0.

But nrf_drv_gpiote_in_is_set() always returns false, so the pin is not enabled. GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS is increased to 8, because of the shared events of low power pins, but I can't get the pin working. I also tried various settings like GPIOTE_CONFIG_IN_SENSE_TOGGLE(true), which is high accuracy, but no success at all.

Any ideas?

Yours Johannes

BTW I use SDK 9.0

  • Is the event handler (LIS2DH_INT1_handler) called? You should check the state of the pin here.

  • Hi Ole, yes the LIS2DH_INT1_handler is called during the init() procedure and I can receive a NRF_GPIOTE_POLARITY_HITOLO action during init. I added nrf_drv_gpiote_in_is_set(ACC_INT1_PIN) to the LISDH_INT1_handler, but false is returned. The LIS2DH_INT1_handler is also only called once during startup, so the event changes (low-high-low) from the accelerometer are not detected. The accelerometer is working and i can get all accel data via SPI.

  • I meant is the event handler called when the pin changes state? You should not call it in your code, it should be called when pin changes state.

    Also make sure that your code spends as little time as possible in the interrupt. The pulse may be too short that you detect both the low to high and the high to low. Do you know how long the pulse is?

  • Hi Ole, thank you for going into my problem. Not really, the event handler is only called 1 times, if i switch power on the nRF. Then I see a High-to-Low action. But later, when the accelerometer goes into low power mode after 5 seconds of inactivity, the LIS2DH sends a low-to-high signal, which is never detected by the event handler. If the accelerometer wake-up again and a high-to-low signal is sent, this signal is also not detected by the event handler. Therefore I tried to check the pin status, which returns always false. I also used some nrf_delays to make sure to have enough time to detect the signal. I can't measure the pulse length, but as I understand the LIS2DH docu the pin stays on high until a new event (e.g.movement) occurs. So timing should not be the problem.

  • You are sure the pin is not configured some place else in your code? You should try to only run this part of your code and see if the problem is still there.

    I cannot see any problem with your initialization.

    I assume you have checked that the pin actually have changed and the code did not recognized it?

Related