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

NRF52840 UART1 not working in SDK 14

I'm trying to run two UARTs out of my NRF52840. Do you have an example in which both SoftDevice UARTs are used? The Nordic Infocenter SDK 14.0.0 documentation lists one of the advantages of the new serial port library as multi-instance capability, but there is no example demonstrating such usage.

I started in SDK 12 and wrote my own alternative to app_uart that would allow multiple UART instances. After enabling UART0 and UART1 in the SDK config, I was unable to get both working at the same time. When I initialized a single UART using the board's default TX/RX pins (6 & 8 for pca10056) and NRF_UARTE0 (0x0002000) I was able to see all my serial data come through fine. However, switching to use NRF_UARTE1 (0x40028000) causes the app to crash and restart on attempting to read or write data, despite my using the same pins and configuration parameters as with UART0.

I've seen other questions regarding similar issues, and the general response was that the SDK 14 serial class would resolve this issue. However, I have since downloaded SDK 14 and am seeing the same behavior. I can initialize one UART port with nrf_serial_init, provided the serial port instance uses NRF_UARTE0/NRF_UART0, but again the same parameters do not work with NRF_UARTE1.

  • Extending this example, I tried to read the data from rx pins of two UARTs and tried to display the read data into a single UART. 

    Something like this

    ret = nrf_serial_read(&serial0_uart, &c, sizeof(c), NULL, 500);

    (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);

    ret = nrf_serial_read(&serial1_uart, &c, sizeof(c), NULL, 500);

    (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);

    with default RX_PIN_NUMBER and TX_PIN_NUMBER used by serial0 and ARDUINO_SCL and SDA pins used as rx and tx by serial1. I expect the data to be read from rx of serial 1 and displayed on my console(because i'm writing the data received from serial 1 onto serial0) but in vain Disappointed

    What might be the issue here?







  • Hi,

    I am not sure if I got your case correctly. If you have the same connection schematic as I proposed you will not see anything on the console because your are not sending anything to PC. Instead you have looped message between UARTE0 and UARTE1.

    If you have different connection please let us know.

  • Hi Jakub,

    Yes, connections are different. I'm using Pins 6 and 8 for Serial0 and Pins 26 and 27 for Serial1. Also, I have made some progress wrt my last question.

    // UART0 -> RX_PIN_NUMBER, TX_PIN_NUMBER (DEFAULT)
    //UARTE1 -> ARDUINO_SDA_PIN, ARDUINO_SCL_PIN (DEFAULT)
            
            //In a loop
            
            ret = nrf_serial_read(&serial0_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);
            
            ret = nrf_serial_read(&serial1_uart, &c, sizeof(c), NULL, 1000);
            if (ret != NRF_SUCCESS)
            {
                continue;
            }
            (void)nrf_serial_write(&serial0_uart, &c, sizeof(c), NULL, 0);
            (void)nrf_serial_flush(&serial1_uart, 0);
            (void)nrf_serial_flush(&serial0_uart, 0);

    In the above-mentioned code, I have used Pin6 as tx pin for serial0. Hence, I'm using serial0 to print the data received from both serial0 and serial1. While doing so, the data received through rx (Pin8 for serial0 and Pin26 for serial1) is printed on the console only when I use the serial ports one at a time(by commenting out the other block). When I try to use both the ports simultaneously to read data, the code gets stuck after 1st iteration of while loop. What could be the issue here?

    PS: I'm using polling mode with following configs

    NRF_SERIAL_CONFIG_DEF(serial0_config, NRF_SERIAL_MODE_POLLING,
                          NULL, NULL, NULL, NULL);
    NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_POLLING,
                          NULL, NULL, NULL, NULL);
  • Hi,

    Possibly you have easy error or I still didn't get your case.

    Line 19 - you are writing to serial 0

    Line 20 - you are flushing serial 1 (but nothing has been sent to serial 1). What result you expected here?

  • I'm assuming that Flushing would clear out both Tx and Rx queues. So, even if I'm not sending anything to serial1, I intend to clear out Rx queue at least. Thus, I'm doing a flush on Serial1.

    In the next iteration, I expect to read serial 0 and serial 1 as usual. But the code gets stuck in line 6 in the second iteration. 

Related