I am new to NRF52832. I want to monitor continuously PIN 3 where I have connected USB to check whether my USB is connected or not. How can I do that. Please reply ASAP.
I am new to NRF52832. I want to monitor continuously PIN 3 where I have connected USB to check whether my USB is connected or not. How can I do that. Please reply ASAP.
Hi..Amit
first define PIN 3 and After that ,create timer instance for repeated mode and start it.
then initalize , configure nrf_drv_gpiote_init driver based on ur configuration and enable input event on it.
for more information u can look at example pin_change_int in SDK example folder.
Regards.
Hi Thanks for the prompt reply. I had looked into the example and what I can find out is in any of the case whether the PIN 3 changes from Low to High or High to Low the control goes to the in_pin_handler function. How can I trace whether the PIN has gone to low to high or high to low? Sorry for asking simple question but I am new.
Regards, Amit
it is very simple. just configure "sense" in nrf_drv_gpiote_in_config_t struct. then it will generate event when change.
I had configured "sense" but the issue i am facing is it is either sensing Low to High or High to Low not both
The code I am using is as follows-
int x=-99;
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { //nrf_drv_gpiote_out_toggle(PIN_OUT); nrf_drv_gpiote_in_config_t in_config1;
if( in_config1.sense == NRF_GPIO_PIN_SENSE_HIGH)
{
LEDS_OFF(1 << 17);
LEDS_ON(1 << 18);
}
else if ( in_config1.sense == NRF_GPIO_PIN_SENSE_LOW)
{
LEDS_OFF(1 << 18);
LEDS_OFF(1 << 17);
}
// if( (nrf_gpio_pins_read() & (1 << 3)) == NRF_GPIO_PIN_SENSE_LOW)
// {
// LEDS_OFF(1 << 17);
// LEDS_ON(1 << 18);
// }
//
//
// if( (nrf_gpio_pins_read() & (1 << 3)) == NRF_GPIO_PIN_SENSE_HIGH)
// {
// LEDS_OFF(1 << 17);
// LEDS_OFF(1 << 18);
// }
//
//
//
//
} /**
@brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
and configures GPIOTE to give an interrupt on pin change. */ static void gpio_init(void) { ret_code_t err_code;
err_code = nrf_drv_gpiote_init(); APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config); APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true); in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(3, &in_config, in_pin_handler); APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(3, true); }
/**
@brief Function for application main entry. */ int main(void) { LEDS_CONFIGURE(LEDS_MASK); gpio_init();
while (true) {
} }
/** @} */