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

nrf_gpio_port_read instructions

Hi,

I am using nrf_gpio_port_read to read port 1 (pins 8-15), and I want to know how long it takes to read the port, ie. how many instructions. I am doing this in an interrupt handler. Currently, I am measuring this by toggling a GPIO pin before and after nrf_gpio_port_read, and am measuring roughly 320ns. However, the GPIO toggling itself is adding some overhead, so I would like to know how many cycles nrf_gpio_port_read itself takes.

On a related note, what is the fastest way to read pins 8-15 at once? Is it nrf_gpio_port_read or is there a faster way?

Thanks,

-ujwal

Parents
  • The actual read of the port is single cycle. How many instructions depends on the actual assembler generated by your compiler at the given optimisation level. And how long that takes to execute is the sum of all the instruction execution times plus a couple of cycles overhead for the initial flash access. And add to that the overhead of getting to the interrupt handler in the first place.

    If you look at the code for nrf_gpio_port_read() you'll see it just does a single read from a pre-calculated address, there's nothing going to be faster than that. That will compile down to a relative load of a register with the address, then a load from the register address, 2 instructions.

    320ns is only 5 16MHz cycles, including your pin toggling overhead, it would be hard to imagine you're going to get anything any faster than 5 cycles no? (I assumed nrf51 series, if it's nrf52 series the clock is 64MHz so it's 20 cycles).

  • Thanks RK. I agree 5 cycles is pretty good. I was just checking if this was the best. Yes, this is for the nrf51 series.

Reply Children
No Data
Related