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

GPIO byte writes

I wonder if GPIO could safely be used for byte writes to the OUT port. I have an 8bit (+control signals) peripheral connected to the GPIO and so far I was doing read-modify-write, which is slow and not all that atomic either.

I have used the peripheral (and the code to drive it) on LPC13xx CPU, which has a bit-masking GPIO - you mask out bits to keep and bits to modify by writing to different address, and that was really handy for this use case. But nRF51 doesn't have such a feature.

I have only now noticed the nrf_gpio.h uses byte access to the (sections of the) OUT port, apparently to the same effect although with 8bit granularity. So, is this the official, supported way to do masked GPIO writes? Are those still 1or 2 cycle writes? Is there some other/better way to modify a group of pins?

Parents
  • Hi,

    If you are talking about writing 8bits to 8GPIO pins, then using nrf_gpio_port_write will work with same 2-3 cycles write same as writing to a single pin.

    Thing to remember is that the ports are pre-selected pins

    typedef enum
    {
        NRF_GPIO_PORT_SELECT_PORT0 = 0,           ///<  Port 0 (GPIO pin 0-7)
        NRF_GPIO_PORT_SELECT_PORT1,               ///<  Port 1 (GPIO pin 8-15)
        NRF_GPIO_PORT_SELECT_PORT2,               ///<  Port 2 (GPIO pin 16-23)
        NRF_GPIO_PORT_SELECT_PORT3,               ///<  Port 3 (GPIO pin 24-31)
    } nrf_gpio_port_select_t;
    
Reply
  • Hi,

    If you are talking about writing 8bits to 8GPIO pins, then using nrf_gpio_port_write will work with same 2-3 cycles write same as writing to a single pin.

    Thing to remember is that the ports are pre-selected pins

    typedef enum
    {
        NRF_GPIO_PORT_SELECT_PORT0 = 0,           ///<  Port 0 (GPIO pin 0-7)
        NRF_GPIO_PORT_SELECT_PORT1,               ///<  Port 1 (GPIO pin 8-15)
        NRF_GPIO_PORT_SELECT_PORT2,               ///<  Port 2 (GPIO pin 16-23)
        NRF_GPIO_PORT_SELECT_PORT3,               ///<  Port 3 (GPIO pin 24-31)
    } nrf_gpio_port_select_t;
    
Children
No Data
Related