Adding UART1 to a Project

Hi,

I have a project which uses nRF Logging module (NRF_LOG_INFO). I suppose by default it uses UART0. I have a peripheral that requires to use another serial port (UART1). The UART library (APP_UART_FIFO_INIT) does not give any provision to select the UART instance, so it will interfere with the logs if I use it as it is. How to add UART1 without disturbing the logs? They should work concurrently.

Thanks.

Parents
  • Hi,

    You can change the UART instance used by APP_UART library by changing APP_UART_DRIVER_INSTANCE in your sdk_config.h file. The UART instance used by the logger module is hardcoded to UARTE0 in the module code. APP_UART does not support multi-instance and can one be used with one UART at a time. The logger module uses the nrf_drv_uart API directly, so this does not interfere with the APP_UART module.

    In later SDK versions, we also provide a new library: Libuarte - advanced UARTE driver, which supports multi-instance, RX timeout, and many other features.

    Best regards,
    Jørgen

  • I have to make a few changes to use it for DMX for example:

    Fullscreen
    1
    2
    // Configure 2 stop bits
    NRF_UARTE1->CONFIG = (1U << UARTE_CONFIG_STOP_Pos);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    and

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // Create start sequence with modified baud rate
    NRF_UARTE1->BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud57600 << UARTE_BAUDRATE_BAUDRATE_Pos);
    while (app_uart_put(0) != NRF_SUCCESS);
    nrf_delay_us(191);
    // Change the baud rate back to 250k
    NRF_UARTE1->BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud250000 << UARTE_BAUDRATE_BAUDRATE_Pos);
    // Send Start Code
    while (app_uart_put(DMX_START_CODE) != NRF_SUCCESS);
    // Send DMX channel data
    for (int i = 0; i < DMX_CHANNEL_COUNT; i++)
    {
    while (app_uart_put(dmx_data[i]) != NRF_SUCCESS);
    }
    // Send Inter-Frame Gap (IFG)
    nrf_delay_us(16); // Two Mark Time periods (approximately)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    But I cannot see any data on logic analyzer. If I use UART0 with app_uart (UART instead of UARTE and NRF_UART0 instead of NRF_UARTE1 in above code), everything works.

  • OK, I got close to the issue. If I comment out line#10 in above code, the code works fine. However, omitting sending the 0 at start violates the DMX protocol, it has to be sent. I tried adding delay after line#7 but it does not resolve the issue. Any clues?  

  • Can you post your full code?

    How is DMX_START_CODE defined? 

    What is the error code returned from the call to app_uart_put() on line 10?

  • No error code is returned, it compiles and executes but this data is not sent. 

    Its defined like: #3define DMX_START_CODE 0x00

    However, I have tried sending 0 directly like: while (app_uart_put(0) != NRF_SUCCESS);

    Also tried to use a variable. In all cases same result.

  • I can't see any reasons that the app_uart code should prevent the sending of 0/NULL.

    Since you are already mixing direct register access with app_uart, could you try to simply use registers only to send the data? See for instance this example.

Reply
  • I can't see any reasons that the app_uart code should prevent the sending of 0/NULL.

    Since you are already mixing direct register access with app_uart, could you try to simply use registers only to send the data? See for instance this example.

Children
  • Hi, for now I have included the '0' start code in the dmx_data[] array and it works for me (not sending '0' separately now). But it's very strange for me. Also the same code works in the uart example in the SDK, infact I tested the code in the 'uart' example first and then included it into my main project. I had also tried direct register write method previously, dropped for some reason. I'll look into it again. Thanks for the help.