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

How to enable UARTE in nRF52840

Hi,

I need to use two uarts for the project requirement. UART0 is enabled and working successfully. And I am trying to initialize UARTE, but I am not getting any output on the pins if I probe. Here is my code:

        #define U_RXD ((1 << 5) | (3 & 0x1F))   //P1.03
        #define U_TXD ((1 << 5) | (4 & 0x1F))   //P1.04

        const  uint8_t buffer[4] = {0x41,0x42,0x43,0x44};
         NRF_UARTE_Type * u_reg;

         nrf_gpio_cfg_input(U_RXD,NRF_GPIO_PIN_NOPULL);
         nrf_gpio_cfg_output(U_TXD);
         nrf_gpio_pin_set(U_TXD);

        u_reg->CONFIG = NRF_UARTE_PARITY_EXCLUDED |  NRF_UARTE_HWFC_DISABLED;
        u_reg->PSEL.TXD = U_TXD;
        u_reg->PSEL.RXD = U_RXD;

   u_reg->BAUDRATE = NRF_UARTE_BAUDRATE_115200;
   u_reg->ENABLE = UARTE_ENABLE_ENABLE_Enabled;

    u_reg->TXD.PTR    = (uint32_t)buffer;
    u_reg->TXD.MAXCNT = 4;

     nrf_uarte_task_trigger(u_reg, NRF_UARTE_TASK_STARTTX);
      while(!nrf_uarte_event_check(u_reg, NRF_UARTE_EVENT_ENDTX) );

Help me if the configuration is wrong. Is it possible to use both UART0 and UARTE at a time?

  • Hi Atlas,

    When you call the function nrf_serial_read(...) you can set the timeout(timeout_ms) you want. You can pass 0 to operate in non blocking mode.

  • I see that the examples/peripheral/serial code in the SDK has been removed.  Is that replaced by the examples/peripheral/libuarte project?  If so, it seems we have the same problem with app_uart_fifo only supporting one instance.  I didn't find a library named serial either in components/libraries/ just the libuarte library again which seems to get limited by app_uart_fifo's only working with one instance.

  • Hello,

    app_uart_fifo is actaully another library that you can use on top of the UARTE driver (this is the library used in the ble_app_uart sample). But you are right in that Libuarte library replaced the serial library, and this library does not limit you to one UART instance either.

    You may also consider using the driver directly if you don't need additional features offered by libuarte. Instructions on how to use the driver APIs can be found in the SDK documentation here: UART

  • I was hoping to have FIFO functionality on top of the libuarte driver on two easy DMA uarts as well as one traditional uart for debug.  But it sounds like I would need to rewrite app_uart_fifo to support more than one instance.
    There is a clue in the doc you linked, regarding the simpler configuration, and why my configuration is being corrupted by apply_config.h which basically takes what we have configured and changes it.

    We are currently working to re-factor the app_uart_fifo.c to allow for three instances. The build error after enabling the other two instances is that the first channel is being instantiated correctly, 2nd & 3rd not; looking at configuration, apply_config is disabling the 2nd & 3rd instances in part of the code, but not all of it everywhere.  We have been struggling with the nRF and nRFx libraries. We are digging into the documentation to see what we missed.   It appears what we are configuring is correct, but is then being mangled.

  • When you say 3 instances, I assume you mean 3 physical UART interfaces? Please note that there are only 2 on the nRF52840, UART0/UARTE0 and UART1/UARTE1.

    idavenport said:
    apply_config is disabling the 2nd & 3rd instances in part of the code, but not all of it everywhere.  We have been struggling with the nRF and nRFx libraries. We are digging into the documentation to see what we missed.   It appears what we are configuring is correct, but is then being mangled.

     To avoid your configuration setting from getting overridden by apply_config,  please make sure you apply your changes to the nrf_drv_uart settings and not the corresponding nrfx_uarte settings. As an example, to enable the UARTE1 instance, you should set UART1_ENABLED and not NRFX_UARTE1_ENABLED.

    Excerpt from the Migration guide for nrfx drivers

    Continue using nrf_drv drivers
    If you want to continue using the nrf_drv drivers, no changes are required. You can use the drivers as before, but without taking advantage of any new functionalities introduced to the nrfx drivers.

    The old configuration entries are translated to the new NRFX_* format in the apply_old_config.h file located in integration/nrfx/legacy. In case you continue using the nrf_drv drivers, if you use any of the new NRFX_* entries in your configuration file that also contains old entries, the old entry settings take precedence.

Related