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

  • Finally I was able to track it down. It was a strange issue with the LIS2DH and its register settings. When I flashed the nrf51, some registers of the LIS2DH were not set correctly. Noticed that, I flashed it again with the absolute identical hex-file, until the LIS2DH registers were set correctly. Very strange. So i use a work around and check the LIS2DH register settings in a loop and write the registers until the show the correct values. Strange and not elegant, but works.

Related