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

nrf_gpio_cfg documentation leaves much unclear

I guess we need some help with definitions. Basically, we'd like to read data from an I2C line. Should be as simple as "set to input" and "read the pin". However...

In the documentation, the nrf_gpio_cfg call has several parameters. Some are obvious; others appear to lack definitions.

__STATIC_INLINE void nrf_gpio_cfg ( uint32_t pin_number, nrf_gpio_pin_dir_t dir, nrf_gpio_pin_input_t input, nrf_gpio_pin_pull_t pull, nrf_gpio_pin_drive_t drive, nrf_gpio_pin_sense_t sense )

I’m looking at what the settings should be for reading an I2C line while enabling the internal pullup.

  1. Presumably “pin direction” should be NRF_GPIO_PIN_DIR_INPUT. This seems clear enough.
  2. Input buffer: what is this? Do I need NRF_GPIO_PIN_INPUT_CONNECT to be able to read a pin? Or is input buffering an additional optional feature?
  3. For pullup we presumably set NRF_GPIO_PIN_PULLUP
  4. For drive, we set NRF_GPIO_PIN_SOD1 to correspond to I2C standards
  5. Sense mode: what is this? What does “sense” mean? Does this correspond to generating an interrupt on an edge? For a binary value, what’s the difference between sensing high and sensing low or not sensing at all? How does this affect the ability to just read the value of the pin using the nrf_gpio_pin_read() call?

Thanks!

Parents
  • So the first thing to do is read the chapters in the manual about GPIO and GPIOTE which explains all these terms, has diagrams showing how the GPIOs work and detail the register settings which in the end is all that macro is doing, setting bits in the register.

    1. yes

    2. yes you need connect in order to actually read the value of an input pin, input buffers use power so they need to be enabled. Pin configured as Input with no buffer basically means unused, no power use, default state.

    3. yes

    4. not really. This is an input pin, drive is used for output pins.

    5. used for generating interrupts, see the GPIOTE PORT event.

    Also there are specialisations of the nrf_gpio_cfg() macro for input/output/input+sense etc which specify only the relevant parameters, rarely do you need to use the generic nrf_gpio_cfg() macro itself, and the code is clearer if you use the relevant one, which in your case would be nrf_gpio_cfg_input().

Reply
  • So the first thing to do is read the chapters in the manual about GPIO and GPIOTE which explains all these terms, has diagrams showing how the GPIOs work and detail the register settings which in the end is all that macro is doing, setting bits in the register.

    1. yes

    2. yes you need connect in order to actually read the value of an input pin, input buffers use power so they need to be enabled. Pin configured as Input with no buffer basically means unused, no power use, default state.

    3. yes

    4. not really. This is an input pin, drive is used for output pins.

    5. used for generating interrupts, see the GPIOTE PORT event.

    Also there are specialisations of the nrf_gpio_cfg() macro for input/output/input+sense etc which specify only the relevant parameters, rarely do you need to use the generic nrf_gpio_cfg() macro itself, and the code is clearer if you use the relevant one, which in your case would be nrf_gpio_cfg_input().

Children
No Data
Related