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

nrf_serial_init triggers timing/clock problem

Hardware: nRF52840 DK

SDK: 16.0.0

FreeRTOS: 10.0.0

I am attempting to use UARTE1 for a Modbus port. UART0 is already in use for a Command Line Interface. I can set up and use UART0 with no issues. However when I call nrf_serial_init to setup UARTE1, something goes wrong with RTC2. I have RTC2 setup to generate a one second COMPARE 0 event which we used to keep track of time. After nrf_serial_init is called, the interrupt goes from firing once a second to firing once every 30 or 31 seconds. Stopping in the debugger I can see that the RTC2 registers are unchanged. The prescalar is 0, and the compare 0 register has a multiple of 32768 in it. I checked the CLOCK peripheral and it looks correct as well.

UARTE1 is set up on ports P1.2 (TX), and P1.3 (RX), no flow control. DMA is enabled for the channel. UARTE1 will successfully transmit and receive data. 

I'm looking for any thoughts on a) debug approach, or b) you know what this is!

Parents
  • Hello,

    Could it be that RTC2 is being reconfigured while already running? This will cause the RTC to keep running with the previous prescaler setting which may be different. Excerpt from the RTC chapter of the PS:

    "The PRESCALER register is read/write when the RTC is stopped. The PRESCALER register is read-only once the RTC is STARTed. Writing to the PRESCALER register when the RTC is started has no effect.

    The PRESCALER is restarted on START, CLEAR and TRIGOVRFLW, that is, the prescaler value is latched to an internal register (<<PRESC>>) on these tasks." RTC — Real-time counter

    Also, does Freertos use RTC1 or RTC2 in your case?

  • Hi Vidar,

    I think I figured out what was going on. Right before calling nrf_serial_init my UART driver that encapsulates the SDK serial and uart driver code configures a pullup on the rts pin (which is still just a gpio at that point). However in the case of my Modbus port there is no rts pin. So, it is manipulating P0.0 which probably messes up the 32KHz clock. Once I eliminated that nrf_serial_init did not cause any problems. 

    I missed that yesterday because I was getting pretty punchy at the end of the day.

    BTW: Our FreeRTOS uses RTC1 and tickless idle.

  • Thanks for the update! I did not think of that. I will keep this in mind next time I see someone experiencing similar behavior.

Reply Children
No Data
Related