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

Ensure GPIO initializes to default low

Using: NRF52840, SDK 14.2, S140

My GPIO initialization code is as follows. This is the first thing that happens in main.c.

nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 0));
nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 0));

nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 14));
nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 14));

Here are logic analyzer traces of 2 GPIOs (I can also scope them soon). Top one (P1.0) should be initialized low, bottom one (P1.14) should be initialized high.

PROBLEM 1: You can see in this picture that something spurious happens to both GPIOs upon powerup, where they both look like they're being initialized to the wrong value for ~4ms before being set to the proper values. This may be clearer in this zoom in view of the little blip at time B above: 

This blip lasts about 4 ms. Below is an example measured from a different trial. Across multiple trials, it appears that P1.0 always goes high before it goes low. This is concerning, because there can be suboptimal system behavior if P1.0 is not initialized properly. Why might this be happening?

PROBLEM 2: there is also a consistent blip high AFTER the device is powered off (or generally upon poweroff, hard to tell exact sequence) -- see time point A in the first image. What might this be?

Thank you!

Parents
  • Hi,

    how close is your initialization code to the start of main()?  As soon as your GPIO initialization is executed, the pins are set to the right state immediately, without any delay. As for powering off, you cannot contol pin state at this time with software. If your pins have some load that should be in known state while CPU is powering-on/powering-off/browned-out, you need hardware pull-up or pull-down resistors on that pins.

Reply
  • Hi,

    how close is your initialization code to the start of main()?  As soon as your GPIO initialization is executed, the pins are set to the right state immediately, without any delay. As for powering off, you cannot contol pin state at this time with software. If your pins have some load that should be in known state while CPU is powering-on/powering-off/browned-out, you need hardware pull-up or pull-down resistors on that pins.

Children
No Data
Related