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

PC to nRF52832 DK using UART(wired)

Hi

I am using nRF52832 DK, with SES as IDE on Ubuntu-16.04 OS PC. I want to stream some data from PC to DK. The DK is connected to PC for power supply and programming the chip. So I thought of using a USB to UART converter and connect USB to PC and UART pins to DK. I looked at /examples/peripheral/uart example. I want to print the data in debug terminal, to verify that the data received is correct. How do I do that? Does this sound like a good approach to send data from PC to DK? I want to stream data for quite long time(for an hour or so). Can someone help me with this?

Thanks,                                                                                                                                                                                                                                                                                                      Sai Kiran.

  • Hi,

    The Segger chip on the nRF52 DK already includes UART to USB serial bridge (Virtual COM port) which you can use. The serial port should show up as ttyACMx (where x = port number) in /dev/ when you connect the DK to your PC.

    Note: the serial port usually requires root permissions by default. You can change that by installing this package: https://github.com/NordicSemiconductor/nrf-udev

  • Hi,

    There are no permission issues. I have written a python script to send data through serial port. Here is the Python Code.

    import serial
    ser = serial.Serial('/dev/ttyACM0', 115200)  # open serial port
    print(ser.name)         # check which port was really used
    ser.write(b'Hello')     # write a string
    ser.close()

    On the DK, I am using UART example, found in <SDK_Root>/examples/peripheral/uart/pca10040/blank/ses. I want to see the text "hello" on debug terminal. So, here is the corresponding code for that(am not sure if this is the correct approach).

    main.c file: - 
    
    int main(void)
    {
        uint32_t err_code;
        log_init();
        bsp_board_init(BSP_INIT_LEDS);
        
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              UART_HWFC,
              false,
    #if defined (UART_PRESENT)
              NRF_UART_BAUDRATE_115200
    #else
              NRF_UARTE_BAUDRATE_115200
    #endif
          };
    
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    
    #ifndef ENABLE_LOOPBACK_TEST
        //printf("\r\nUART example started.\r\n");
        NRF_LOG_INFO("UART example started");
    
        while (true)
        {
            uint8_t cr;
            while (app_uart_get(&cr) != NRF_SUCCESS);
            while (app_uart_put(cr) != NRF_SUCCESS);
            
            /* Custom code START */
            //uart_init();
            NRF_LOG_INFO("START"); 
            NRF_LOG_INFO("%s", cr); 
            
            /* Custom code START */
    
    
    
            if (cr == 'q' || cr == 'Q')
            {
                printf(" \r\nExit!\r\n");
    
                while (true)
                {
                    // Do nothing.
                }
            }
        }

    I just added NRF_LOG_INFO(cr) line, to the available example. When I run the code, I do not see any message in Debug terminal. I am able to see hello message in Putty however.

  • Hi,

    I don't think it's possible to connect the Debug terminal in SES to a "COM" port. We only use it for RTT logging. 

    // Config settings to enable RTT logging

    NRF_LOG_BACKEND_RTT_ENABLED 1

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0

  • SO does this mean that I will be able to see UART messages only using RTT. I have checked sdk_config.h. NRF_LOG_BACKEND_RTT_ENABLED option is not there. Should I add it to use RTT?

  • Most examples support logging over both UART and RTT, but not all. Maybe the UART/Serial Port Emulation over BLE  example in  \examples\ble_peripheral\ble_app_uart would be a better starting point for you.

Related