This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How does gpio_port functions interact with gpio_pin functions?

I'm wondering if the port and pin function can be used together to configure a set of pins.

For _port_dir_set, I assume it sets the whole port to the designated direction. Can I then use individual pin functions to change some? For instance, if I set port 0 direction to output, can I then change P0.03 to input with nrf_gpio_pin_dir_set?

I'd like to be able to set or clear a group of pins using a mask. Do _port_set and _port_clear only alter the pins that match the mask, without glitches on the non-masked pins?

Parents
  • Yes, you can use the port functions and pin functions together. Ultimately, all the functions write to the registers described in chapter 14 in the nRF51 series reference manual. If you have a look there, you will see that there are three ways to control the output value or the direction of the pins. You can write to the OUT or DIR registers directly, or you can use the xSET or the xCLR registers. The last ones will only set or clear the output or direction value for the bits that is set to '1'. The rest will be ignored.

    You should have a look in the nrf_gpio.h file to see which registers the different functions write to.

    To answer your questions:

    For _port_dir_set, I assume it sets the whole port to the designated direction. Can I then use individual pin functions to change some? For instance, if I set port 0 direction to output, can I then change P0.03 to input with nrf_gpio_pin_dir_set?

    Yes

    I'd like to be able to set or clear a group of pins using a mask. Do _port_set and _port_clear only alter the pins that match the mask, without glitches on the non-masked pins?

    Yes. nrf_gpio_port_set() writes to the OUTSET register, which sets all pins that match the mask, and ignores the other ones. There should be no glitches.

Reply
  • Yes, you can use the port functions and pin functions together. Ultimately, all the functions write to the registers described in chapter 14 in the nRF51 series reference manual. If you have a look there, you will see that there are three ways to control the output value or the direction of the pins. You can write to the OUT or DIR registers directly, or you can use the xSET or the xCLR registers. The last ones will only set or clear the output or direction value for the bits that is set to '1'. The rest will be ignored.

    You should have a look in the nrf_gpio.h file to see which registers the different functions write to.

    To answer your questions:

    For _port_dir_set, I assume it sets the whole port to the designated direction. Can I then use individual pin functions to change some? For instance, if I set port 0 direction to output, can I then change P0.03 to input with nrf_gpio_pin_dir_set?

    Yes

    I'd like to be able to set or clear a group of pins using a mask. Do _port_set and _port_clear only alter the pins that match the mask, without glitches on the non-masked pins?

    Yes. nrf_gpio_port_set() writes to the OUTSET register, which sets all pins that match the mask, and ignores the other ones. There should be no glitches.

Children
No Data
Related