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

nRF52840 output the 32.768kHz clock on any GPIO in SPI Communication.

Dear Nordic Developer Zone,

I am working on MAX30003 ECG (https://datasheets.maximintegrated.com/en/ds/MAX30003.pdf)  with Nrf52840-DK. My sensor is work on the 32.768kHz external clock. 

but in Nrf I don't know which GPIO_PIN is assigned for that.

I visited below link but I unable to find solutions: 

https://devzone.nordicsemi.com/f/nordic-q-a/23474/nrf52832-fclk-pin/92210#92210

https://devzone.nordicsemi.com/f/nordic-q-a/15996/can-the-nrf52-output-the-32-768khz-clock-on-a-gpio

I am referring (SDK15.2 -PCA10056-spi code)

I have some questions about that:

1) Can I do the merging of timer and gpiote example code into SPI?

2) please give me detail about how to generate 32.768kHz clock ?

I have stuck  on below issue, 

https://maximsupport.microsoftcrmportals.com/en-us/knowledgebase/article/000096610

Thanks,

Rohit Patil

Parents
  • 1) Yes of course.

    2) You can't output the 32.768 clock on a GPIO. What you can do is share an external 32.768kHz clock with both the MAX30003 and the nRF52840 by setting the BYPASS and EXTERNAL bits in the LFCLKSRC register. 

  • Here is how you output exactly 32,768Hz.

    What do you need?

    1. LFCLK powered by a 32768Hz crystal.

    2. 1x TIMER, 1x RTC, 3x PPI channels. 1x GPIOTE channel

    How to configure the peripherals

    1. Configure a GPIOTE channel to drive the GPIO you want to output the clock to

    2. Configure a TIMER to count at 16MHz (PRESCALER = 0), in 16 bit timer mode

    3. Set CC[0] = 1 and CC[1] = 245. This will generate the 32,768 Hz with almost 50% duty cycle

    4. Use a PPI channel to connect the COMPARE[0] event to the GPIOTE->TASKS_SET

    5. Use a second PPI channel to connect the COMPARE[1] event to the GPIOTE->TASKS_CLR

    6. configure an RTC to generate the tick event (PRESCALER = 0)

    7. Use a third PPI channel to connect the RTC TICK event to the TIMER CLEAR task

    8. start the timer

    How it works?

    The timer will count at 16MHz (0.0625us per tick). When the timer reaches the value 1 it will set the output GPIO. When it reaches 245 (244 ticks later) it will clear the output GPIO. This will give a high pulse of 244 * 0.0625 = 15.25us which is roughly half of the 32,768Hz period (hence, close to 50% duty cycle).

    The timer will keep counting and would overflow if it reached 0xFFFF but it will never reach that value because the RTC will keep resetting it at the 32,768Hz frequency.

    Enjoy!

Reply
  • Here is how you output exactly 32,768Hz.

    What do you need?

    1. LFCLK powered by a 32768Hz crystal.

    2. 1x TIMER, 1x RTC, 3x PPI channels. 1x GPIOTE channel

    How to configure the peripherals

    1. Configure a GPIOTE channel to drive the GPIO you want to output the clock to

    2. Configure a TIMER to count at 16MHz (PRESCALER = 0), in 16 bit timer mode

    3. Set CC[0] = 1 and CC[1] = 245. This will generate the 32,768 Hz with almost 50% duty cycle

    4. Use a PPI channel to connect the COMPARE[0] event to the GPIOTE->TASKS_SET

    5. Use a second PPI channel to connect the COMPARE[1] event to the GPIOTE->TASKS_CLR

    6. configure an RTC to generate the tick event (PRESCALER = 0)

    7. Use a third PPI channel to connect the RTC TICK event to the TIMER CLEAR task

    8. start the timer

    How it works?

    The timer will count at 16MHz (0.0625us per tick). When the timer reaches the value 1 it will set the output GPIO. When it reaches 245 (244 ticks later) it will clear the output GPIO. This will give a high pulse of 244 * 0.0625 = 15.25us which is roughly half of the 32,768Hz period (hence, close to 50% duty cycle).

    The timer will keep counting and would overflow if it reached 0xFFFF but it will never reach that value because the RTC will keep resetting it at the 32,768Hz frequency.

    Enjoy!

Children
No Data
Related