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:

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

    and

    // 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)

    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?  

Reply Children
No Data
Related