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

nRF52 wirting GPIOS direct with immediate effect

Hi I have ported a simple function from nRF51 to nRF52 which Outputs PWM coded Startup Diagnose Information via a GPIO. The Timing is generated by wait Loops and GPIO will be toggled by direct writing to OUTSET Register. I have noticed that the Timing is no longer precise on the nRF52. It seems, that writing to the OUTSET Register not always takes effect immediately. I guess it is an effect caused by the System bus write buffer.

Qustions: What is the correct way to force a GPIO to react immediately? I have tried the following to toggle the GPIO which seems to work:

  • read OUTSET Register
  • write OUTSET Register
  • read OUTSET Register

Where can i get more Information about the System bus write buffer?

Thank you for help. Kind regards Paul

  • Hi,

    The GPIO peripheral runs off the 16MHz peripheral clock while the CPU runs off the 64MHz CPU clock, so the timing will be determined by this. See here.

    If you want exact timing you should consider using PPI and GPIOTE. You should also enable constant latency mode so that CPU wakeup latency and the PPI task response will be constant and kept at a minimum. The drawback of this is that some resources are forced on while in sleep so the current consumption will increase. Enable the constant latency mode like this (not SoftDevice safe):

    NRF_POWER->TASK_CONSTLAT = 1;
    

    You may also want to use the crystal clock instead of the internal oscillator as this has much better accuracy. Start the clock like this (not SoftDevice safe):

    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    

    There is some delay when using PPI and GPIOTE, but this should be constant when using constant latency mode.

    Ole

  • Hi I have solved the problem by implementing the function using a Timer, PPI channels and GPIOTE as you have proposed. Thank you very much. Paul

Related