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?

Parents
  • 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

  • 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.

  • We are using the nRF52833 running FreeRTOS.  We don't have the softdevice linked in yet as we aren't using BLE in our product just yet, but will be soon.   We have one simple uart and two enhanced uarts.  I see now that the simple UART is depracated and shares a base address with the first enhanced UARTE.  I expect that is why my code fails to compile.

    // <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver
    //==========================================================
    #ifndef NRFX_UARTE_ENABLED
    #define NRFX_UARTE_ENABLED 1
    #else
    #warning "NRFX_UARTE_ENABLED previously defined!"
    #endif
    
    // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance
    #ifndef NRFX_UARTE0_ENABLED
    #define NRFX_UARTE0_ENABLED 0
    #else
    #warning "NRFX_UARTE0_ENABLED previously defined!"
    #endif
    
    // <o> NRFX_UARTE1_ENABLED - Enable UARTE1 instance
    #ifndef NRFX_UARTE1_ENABLED
    #define NRFX_UARTE1_ENABLED 1
    #else
    #warning "NRFX_UARTE1_ENABLED previously defined!"
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
    
    // <0=> Disabled
    // <1=> Enabled
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_HWFC
    #define NRFX_UARTE_DEFAULT_CONFIG_HWFC 0
    #else
    #warning "NRFX_UARTE_DEFAULT_CONFIG_HWFC previously defined!"
    #endif

    The code fails in nrfx_uart.h at line 198.

    Is there a config tool that automates the #define configurations somehow?

  • You can use the the CMSIS configuarition wizard to parse the sdk_config file (SDK configuration header file), but this tool is more for visualising the various configuration settings, it does not automate anything. That said, I see you are using the NRFX_* configurations, did you try to the legacy configurations instead (e.g. UART1_ENABLED  instead of NRFX_UARTE1_ENABLED?

    I don't see any ASSERTion check at line 198 when I check the nrfx_uart.h hrader in SDK 17. What SDK version is your project based on?

  • Thanks for the tips on CMSIS.  We did try both the legacy and the nrfx drivers, but neither would let us use the old simple uart and the two enhanced uarts to get 3 uarts at a time.  So we will have to multiplex one of the uarts on to different pairs of pins to serve all three uart interfaces desired on our board.  

    Our SDK is version 17.0.2,

    Nordic -> /home/dgo/Nordic/nRF5_SDK_17.0.2_d674dde which looks like it is the most current version.  We also use Segger Embedded Studio 5.50d, the most current version.
  • It's not possible to operate 3 UART interfaces concurrently as there are only 2 physical interfaces, but it should be possible to multiplex one of the instances like you said.

    I think it might be easier to just use the same UARTE driver for all three. You can set the DMA receive buffers to 1 byte to make it behave more like the legacy driver (i.e. trigger RX event for every byte).

    idavenport said:
    Our SDK is version 17.0.2,
    idavenport said:
    The code fails in nrfx_uart.h at line 198

    I do not see any code or pre-proccessor checks at this line in nrfx_uart.h:

Reply
  • It's not possible to operate 3 UART interfaces concurrently as there are only 2 physical interfaces, but it should be possible to multiplex one of the instances like you said.

    I think it might be easier to just use the same UARTE driver for all three. You can set the DMA receive buffers to 1 byte to make it behave more like the legacy driver (i.e. trigger RX event for every byte).

    idavenport said:
    Our SDK is version 17.0.2,
    idavenport said:
    The code fails in nrfx_uart.h at line 198

    I do not see any code or pre-proccessor checks at this line in nrfx_uart.h:

Children
No Data
Related