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

What is a GPIO port and why would I use it?

The SDK defines functions for operating on "ports", which are the output space divided into 8-bit chunks:

  • nrf_gpio_port_clear
  • nrf_gpio_port_dir_set
  • nrf_gpio_port_read
  • nrf_gpio_port_set
  • nrf_gpio_port_write

These functions take an argument of nrf_gpio_port_select_t, a helpful enumeration that saves the programmer from counting to 4.

Internally, they just manipulate the 32-bit IO registers with shifts and masks.

They are used in nrf6310 example code for the 6.x SDK and earlier, but are not used since then.

These "ports" are a different abstraction than the GPIOTE "PORT" signal, or "gpio PORT" in the "GPIO" section of the nRF51 reference manual, or the "GPIO port" referred to in the SVD documentation for the OUT, OUTSET, OUTCLR, IN registers.

A search through the devzone for "nrf_gpio_port_" will yield many questions with realized or latent bugs due to this confusion:

What is the use of these functions? For porting 8-bit code?

Regards, Mark

Parents
  • Good point. I guess you are correct, the port term is a bit confusing.

    In the old days, the nRF6310 motherboard was used for 8-bit microcontrollers. The nRF6310 has headers for 32 GPIO pins, which was devided into 32/8=4 ports. The nRF51 first and second revision used primarily the nRF6310 as development platform, and in the nrf_gpio library you could use your mentioned functions to do operations on 8 pins at one time. I found it useful since there were 8 buttons and 8 leds on the nRF6310 board. Then I could for example configure all the leds at once with one port command. I dont find it very useful now when using the nRF51-DK board as it has 4 leds and 4 buttons.

Reply
  • Good point. I guess you are correct, the port term is a bit confusing.

    In the old days, the nRF6310 motherboard was used for 8-bit microcontrollers. The nRF6310 has headers for 32 GPIO pins, which was devided into 32/8=4 ports. The nRF51 first and second revision used primarily the nRF6310 as development platform, and in the nrf_gpio library you could use your mentioned functions to do operations on 8 pins at one time. I found it useful since there were 8 buttons and 8 leds on the nRF6310 board. Then I could for example configure all the leds at once with one port command. I dont find it very useful now when using the nRF51-DK board as it has 4 leds and 4 buttons.

Children
No Data
Related