This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf and nrf_serial_write

Hi,

      In previous project, we enable RETARGET flag and include app_uart.h. After uart init we can use printf function to print some debug message very well.

Now, we have new project, this project need to exchange some data with other MCU by UART port. So I want to use nrf_serial function like nrf_serial_write()

But unfortunately I can't use printf. Below is my source code 

I can send Hello........to PC but I can't see "Sense App Start"

//Open real com port
    err_code = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
    APP_ERROR_CHECK(err_code);
    //uart_init();
    
    
    static char tx_message[] = "Hello nrf_serial!\n\r";

    err_code = nrf_serial_write(&serial_uart,
                           tx_message,
                           strlen(tx_message),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
    
        
    printf("Sense App Start\r\n");
 

Is there any way I can use both?

Thank you.

John.

Parents
  • Hi,

    Our retarget.c implementation that redirects printf() to UART only works with the app_uart library. One option could be to modify retarget.c to work with nrf_serial, but I think it would be easier to just replace the printf calls with nrf_serial_write(). You can use sprintf() if you need to format a string to place in the tx buffer.

    Also, it may be worth noting that nrf serial got replaced by the Libuarte - advanced UARTE driver in SDK 17.

    Best regards,

    Vidar

  • Hi Vidar,

        I understand it. I can replaced printf by the nrf_serial_write() function.

    Also, we use SDK 15. Does nrf_serial_write and nrf_serial_read have any bugs?

    Does it have to be changed to UARTE?

    Thank you.

    John.

          

  • Hi John,

    You don't have to change to libuarte. I mentioned it in case you plan to upgrade to SDK 17 in the future. I did not find any bugs listed for nrf_serial in the SDK release notes.

    Best regards,

    Vidar

Reply Children
Related