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?

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

Related