Board: nRF51-DK (nRF51422 chip)
SDK: 12.3.0
SoftDevice: S130
Compilation settings
- Optimization level O1
- Debug information generated
First GPIO pin is mapped to Button 1 (not shown in code) to wake up from SYSTEM OFF state.
Second GPIO pin is to detect interrupt signal INTB from a sensor.
For low power operation, I am using low accuracy GPIO pins.
- Initially I put system in SYSTEM OFF mode with interrupt enabled on Button 1 GPIO pin.
- After pressing Button 1 on the board, the chip wakes up from the SYSTEM OFF state
- After this, I enable I2C controller on nRF
- Then I use the second GPIO pin to detect interrupt signal INTB from the Sensor
- I need to first detect INTB going HI to LO in interrupt handler.
- After this I have to read an interrupt clear register in this sensor using I2C controller on nRF chip.
- Reading the interrupt clear register on sensor clears the interrupt signal INTB switching it from LO to HI. Interrupt handler for this GPIO pin needs to detect this positive edge on INTB
#define BOARD_SENSOR_INTB_PIN 7
volatile bool bIsSensorIntDet = false;
volatile bool bIsSensorIntClr = false;
static uint32_t init_gpio_sensor()
{
ret_code_t err_code = NRF_SUCCESS;
nrf_drv_gpiote_in_config_t sensor_int_pin_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
sensor_int_pin_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(BOARD_SENSOR_INTB_PIN,
&sensor_int_pin_config,
sensor_irq_handler);
APP_ERROR_CHECK(err_code);
return err_code;
}
static void sensor_irq_handler(nrf_drv_gpiote_pin_t const pin,
nrf_gpiote_polarity_t polarity)
{
switch(pin)
{
case BOARD_SENSOR_INTB_PIN:
if( NRF_GPIOTE_POLARITY_HITOLO == polarity){
ASSERT( false == bIsSensorIntDet );
bIsSensorIntDet = true;
NRF_LOG_INFO("[%d] nRF detected interrupt INTB from sensor.\r\n", order++);
} else if( NRF_GPIOTE_POLARITY_LOTOHI == polarity){
ASSERT( true == bIsSensorIntDet );
bIsSensorIntClr = true;
NRF_LOG_INFO("[%d] nRF cleared interrupt INTB from sensor. Sensor is ready for operation.\r\n", order++);
}
default:
/* TODO: report error */
break;
}
}
Within interrupt handler function sensor_irq_handler for INTB, I set boolean variable bIsSensorIntDet (Interrupt detected) to True to if HITOLO is detected and bIsSensorIntClr (Interrupt clear) to True when LOTOHI is detected.
However, I see that while configuring GPIO pin for interrupt signal, I have to specify whether I want to detect either HITOLO, LOTOHI or Toggle.
So, my questions is
- For a low accuracy GPIO pin
- While it is possible to additional GPIO pin to detect LOTOHI on INTB, I donot want use additional pin just for this. How can I detect HITOLO interrupt followed by a LOTOHI interrupt on the same GPIO pin ?
- Do I need to un-initialize the GPIO pin and then re-initialize it again with LOTOHI sense direction ?
- Or is there any other way to change the polarity direction without re-initializing ?
- Does the interrupt for a GPIO gets automatically disabled after the interrupt handler exits ?
- Can interrupt on the GPIO pin disabled inside its handler ?
- What is the difference between nrf_drv_gpiote_in_event_enable (pin, false) and nrf_drv_gpiote_in_event_disable() and which of them to use when ?
- Does disabling the interrupt disable wakeup mechanism from both SYSTEM OFF and SYSTEM ON modes ?
- Can the pin be used to wake up from both System OFF and ON modes ?
- While it is possible to additional GPIO pin to detect LOTOHI on INTB, I donot want use additional pin just for this. How can I detect HITOLO interrupt followed by a LOTOHI interrupt on the same GPIO pin ?