nRF52840DK uart - 921600 not working

I’m using the nRF52840DK to communicate with a module over uart. My problem is that the module has a baud rate of 921600 and as far as my understanding the nRF52840 is using a baud rate of 941176 when set to 921600.  This leads to my commands (13 bytes) only works around 10-20% of the times, and the data received is not as expected (startbytes etc.).

I have tried using nrf_serial_flush as well but then nothing works. Also tried setting the baud rate manually without succeeding.

Any tips?

  • Hi,

    The UART peripheral only supports some baud rates, but if you are close enough and the transfers are short enough it should be OK. It could be that there are other factors here as well. First of all, make sure you start the HFXO on the nRF. Without it you are using the HFINT, and  the frequency could be quite off (worst case up to ±8 % on the nRF52840, as you can see form the electrical specifications).

  • Will try!

    When trying to enable HFXO

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

    I get these fault messages and not sure why they occurs: 

  • Hi,

    Based on the compiler errors it looks like you put these 3 lines outside of a function. Try moving them into a function (for instance in the beginning of main()).

  • I enabled the HFXO but didn’t improve anything.

    Made a test (on/off signal to module every two seconds) and observed if the correct signal reached my module. Also observed my 13 bytes trough a usb to ttl module, and the bytes is always correct.

    What Correct Wrong
    With flush, with usb-2-ttl connected, without HFXO 16 34
    Without flush, with usb-2-ttl connected, without HFXO 12 38
    Without flush, with usb-2-ttl connected, with HFXO 13 37
    With flush, with usb-2-ttl connected, with HFXO 11 39
    With flush, without usb-2-ttl connected, without HFXO 10 40
    Eqvivalent python program module connected to ttl (no nRF52) 50 0

    Cannot understand why with the nRF52 it is struggling that much and the usb-2-ttl show the correct bytes from nRF52.

    Snip of code 

  • Hi,

    With this code you will be using the HFXO (though it would be cleaner to start it with the clock driver as you are anyway using that), so that should be OK. The difference in baud rate between the two devices here is a bit more than 2%, so with this short frame I would expect a lower error rate, but apparently that is not the case.

    The fact that the nRF cannot do exactly 921600 baud is a WH limitation, so that is just how it is. Does the other device support other baud rates? If so, can you pick one where there is a better match (assuming you can also live with a lower baudrate).

Related