This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/LAUNCHXL-CC2650: Using UART_write() to print

Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: CC2650

Tool/software: TI C/C++ Compiler

Hello,

I am using cc2650 Launch pad with simple Peripheral example to print some data as Char values. I am able to do that, but I also want to print the data on COM port using UART_write() function.

I tried to print data using UART_echo example as a reference. In main.c file of simple_ble_peripheral example I added 

    UART_Handle uart;
    UART_Params uartParams;
    const char print[] = "\fPrinting data\r\n";

    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;

    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);

    UART_write(uart, print, sizeof(print));

It successfully prints "Printing data" on comport, but if I try to print anything else using UART_write(), it does not print anything. Is there a way to print integers, array using UART_write()?

Also, how can I implement UART print function inside the application? I tried doing it but didn't work for me.

Please let me know how to use UART_write() or any other function to print the necessary data on COM Port within the application.

Thank you,

Rathna

  • To print integers, array using UART_write, do can use sprintf to format integers/array contents into a buffer and use UART_write to print the buffer.
  • int data[] = {12, 345, 6789, 101112};
    char buff[128], *pos = buff;
    for (int i = 0 ; i != 4 ; i++) {
        if (i) {
            pos += sprintf(pos, ", ");
        }
        pos += sprintf(pos, "%d", data[i]);
    }
    
    UART_write(uart, buff, sizeof(buff));

    Thank you for the response. So, if I do this, will it print? Or are you suggesting something else?

    Also let me know if you know how I can do it inside the application.

    Regards

  • You can check contents in buff after doing sprintf. If that’s what you want, it’s OK to use UART_write to print it it.
  • I am able to do it when I use it in the main.c file. But, if I use it anywhere else in the application, I don't see anything printing on the screen.
    Do you have any idea how to go about that?

    Thanks,
    Rathna
  • Can you elaborate where you put UART_write and it doesn't work?

  • Inside

    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)

  • I test the following code in SimpleBLEPeripheral_taskFxn and I can see UART output without problem. Make sure you call UART_init in your code before you use other UART APIs.

    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fSimpleBLEPeripheral_taskFxn:\r\n";
    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimpleBLEPeripheral_init();
      UART_init();
      /* Create a UART with data processing off. */
      UART_Params_init(&uartParams);
      uartParams.writeDataMode = UART_DATA_BINARY;
      uartParams.readDataMode = UART_DATA_BINARY;
      uartParams.readReturnMode = UART_RETURN_FULL;
      uartParams.readEcho = UART_ECHO_OFF;
      uartParams.baudRate = 115200;
      uart = UART_open(Board_UART0, &uartParams);

      if (uart != NULL) {
          UART_write(uart, echoPrompt, sizeof(echoPrompt));
      }
      // Application main loop
      for (;;)
      {
        // Waits for a signal to the semaphore associated with the calling thread.
        // Note that the semaphore associated with a thread is signaled when a
        // message is queued to the message receive queue of the thread or when
        // ICall_signal() function is called onto the semaphore.
        ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);

    ....

  • It worked for me. Thank you so much, but I am facing another problem, I have connected to a different sensor from Launchpad, which has Rx_Tx connected to IOID_3, so when I try to change the pins in the Board.h file and get the UART messages, I don't see anything on COMport.

    If you know of something that I could try, please let me know.

    Thanks,
    Rathna
  • I couldn’t understand your latest descriptions and question. Can you elaborate?
  • If you are using the CC2650 LP, UART_TX is connected to IOID_3, and you cannot change this without changing your HW.