Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Simplest way to continuously toggle a GPIO pin for a fixed amount of time then stop?

Experienced developer new to embedded C programming here, so please forgive me if I'm missing something obvious. I already went through the GPIOTE example from the nRF52 SDK (v15) and this app timer tutorial.

I want to continuously (say, every 100ms) toggle a GPIO pin between high and low but stop that loop after 20 seconds. I also want to be able to start and stop (don't need the ability to resume) this 20-second sequence on demand.

It looks like either a GPIOTE task or a repeating app timer could handle the continuous toggling for me, but I'm not sure how best to stop it after 20 seconds. Could I start a GPIOTE task to perform the repeated GPIO toggling inside a single-shot 20-second timer then start/stop that timer whenever I please? Given that both GPIOTE tasks and the app timer use the LFCLK, I want to make sure that they will not conflict with one another.

Any high-level example code you could share would be much appreciated. Thanks!

Related