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
  • Hi Sigurd The serial sample code is a not good code to control 2 UART. Because the code will entry while loop in nrf_serial_read(); It means if I used nrf_serial_read(0,x,x); and nrf_serial_read(1,x,x);in this code., it will entry nrf_serial_read(0,x,x); and wait data from UARTE0. When Get data from UARTE0 then run nrf_serial_read(1,x,x); then wait data from UARTE1.

    If it wait data from UARTE0 but get data from UARTE1, this data will keep in buffer and cannot write to UARTE1 port because the code is still in while loop of nrf_serial_read(0,x,x).

    Is it right?

    Thanks. Atlas

Reply
  • Hi Sigurd The serial sample code is a not good code to control 2 UART. Because the code will entry while loop in nrf_serial_read(); It means if I used nrf_serial_read(0,x,x); and nrf_serial_read(1,x,x);in this code., it will entry nrf_serial_read(0,x,x); and wait data from UARTE0. When Get data from UARTE0 then run nrf_serial_read(1,x,x); then wait data from UARTE1.

    If it wait data from UARTE0 but get data from UARTE1, this data will keep in buffer and cannot write to UARTE1 port because the code is still in while loop of nrf_serial_read(0,x,x).

    Is it right?

    Thanks. Atlas

Children
Related