nRF5340 UART Interrupt mode send example

Hi all!
I'm currently working on the UART on the nRF5340 board. The SDK describes three options:
-polling API, -interrupt-driven API, -asynchronous API.
With Polling and Asynchronous - everything is clear and they do not suit me for various reasons.
Interrupt-driven doesn't have any APIs for starting (sending the first byte).
Searched everything.
Please share a link to an example.
Parents Reply
  • Hi Sergii

    Sigurd is currently unavailable, and I will help you with this case in the mean time. 

    Any particular reason why the async driver would not be suitable? If you are handling a lot of communication this should be more efficient. 

    The hci_uart sample in Zephyr uses the interrupt driver both in TX and RX, and you can have a look at that to see how you can handle the TX part in the interrupt. In particular have a look at this section in main.c.

    Best regards
    Torbjørn

Children
  • Thanks for the tip, Torbjorn.
    I guessed that for the first byte it is proposed to use blocking output, and all subsequent ones through the ring buffer is a classic. 
    And UART interrupts load the processor with noise much less, for example, when waiting for the start byte (STX), the rest are simply ignored.
    Best regads!

  • Hi

    The async driver also utilizes the DMA feature of the UARTE peripheral to avoid generating interrupts on every single byte. You need to provide buffers for the UART driver to use, and the larger you make the buffers the more rare the interrupts will be. 

    Best regards
    Torbjørn

  • Hi
    It is impossible to use DMA for reception in the real world, since in it (the real world) you can both lose a byte due to interference, and get +1 0xFF byte due to an interference pulse (start bit 0).
    And in wearable devices, it is quite easy to be near a thyristor regulator, a neon lamp or a contactless charger, and indeed there is a lot of interference in the real world.
    Best regads
    Sergey.

  • Hi Sergey

    DMA is just a different way to transfer data to and from a peripheral to RAM, and unless you transfer the data to RAM you won't be able to do anything with it.

    Most of the peripherals in the nRF5340 uses DMA, including the radio, crypto modules, ADC and serial interfaces, so if the simple act of using DMA would cause a lot of data corruption it would be apparent immediately. 

    In fact it is a bit imprecise of me to say that the async driver utilizes DMA, since all the UART drivers have to use the DMA feature to transfer data. The difference is that the async driver allows you to scale the RX buffers as you like (up to a maximum of 2^16 bytes) rather than process a single byte at a time, which means it utilizes the DMA feature in a more efficient way. 

    In some of our older devices like the nRF52832 there was a UART peripheral without DMA controller, but this peripheral was deprecated and removed in newer devices. 

    Best regards
    Torbjørn

  • Hi Torbjørn

    Of course, transferring between internal devices via DMA is preferable, but specifically with UART this can cause problems.

    Let me explain with an example: if you need to receive a packet of 8 bytes, and set DMA to 8 bytes, then the impulse noise, "lowering" the RxD line for the time of the start bit, will ruin everything, and the false byte will be received first, then the 7th will be received byte of the packet, and the 8th byte will be lost.

    And when using STX / ETX, the length of the packets can vary greatly due to the replacement of codes, and programming the DMA length will be a problem.

    p.s. EazyDMA is a great idea!

    Best regards, Sergey.

Related