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.

CC2650DK run uartecho fun

Other Parts Discussed in Thread: CC2650, CC2560, CC2640, SYSBIOS

I want to know if I running project uartecho_CC2650F128 ,

Can I see any messages from my PC , I want to see data use this software:

Thank you.

  • Yes, you will see "Echoing characters:" on PC UART terminal console if you connect it to your PC.
  • Hello Yikai:

    Thank you . It' really can working if I use serial port to read / write data .

    but I have one question , that code define

    UART TX is IDIO_2 //RF1.7  

    UART RX is IDIO_3 //RF1.9

    where is RF1.7 and RF1.9 , I can't find it on SmartRF06DK board ?

  • You can refer to SmartRF06EB user guide (www.ti.com/.../swru321a.pdf). RF1.7 and RF1.9 are on P412 which should be on right-bottom corner of SmatRF06EB.
  • I find it . Thank you.

  • You are welcome.
  • Hello Yikai:

    I run project "uartecho_CC2650F128" , there is a echoFxn :

    readReturnMode = UART_RETURN_FULL means what type key in , it's will return type? 


    UART_write means I type one String "1" , UART_read will read String "1" ?


    Thank you.

  • 1. readReturnMode can be set to UART_RETURN_FULL or UART_RETURN_NEWLINE. UART_RETURN_FULL unblocks or performs a callback when the read buffer has been filled. UART_RETURN_NEWLINE unblocks or performs a callback whenever a newline character has been received.
    2. When you type a char on UART terminal, UART_read will receive that char.
    3. Yes, Board_initUART is necessary.
  • About 2 : When you type a char on UART terminal, UART_read will receive that char.
    If I connect another sensor use UART_RX and UART_TX , I refer this code :
    ------------------------------------------------------------------------------------------------
    String inputstring = ""; //a string to hold incoming data from the PC
    String sensorstring = ""; //a string to hold the data from the sensor
    boolean input_string_complete = false; //have we received all the data from the PC
    boolean sensor_string_complete = false; //have we received all the data from the sensor
    float sensorValue;
    inputstring.reserve(10); //set aside some bytes for receiving data from the PC
    sensorstring.reserve(30); //set aside some bytes for receiving data from sensor
    void serialEvent()
    {
    inputstring = Serial.readStringUntil(13); //read the string until we see a <CR>
    input_string_complete = true; //set the flag used to tell if we have received a completed string from the PC
    }

    if (input_string_complete){ //if a string from the PC has been received in its entirety
    myserial.print(inputstring); //send that string to the sensor
    myserial.print('\r'); //add a <CR> to the end of the string
    inputstring = ""; //clear the string
    input_string_complete = false; //reset the flag used to tell if we have received a completed string from the PC
    } end of if

    if (myserial.available() > 0) { //if we see that the sensor has sent a character
    char inchar = (char)myserial.read(); //get the char we just received
    sensorstring += inchar; //add the char to the var called sensorstring
    if (inchar == '\r') { //if the incoming character is a <CR>
    sensor_string_complete = true; //set the flag
    }
    } //end of if

    if (sensor_string_complete = = true) { //if a string from the sensor has been received in its entirety
    Serial.println(sensorstring); //send that string to the PC's serial monitor
    if (isdigit(sensorstring[0])) ; //if the first character in the string is a digit
    sensorValue = sensorstring.toFloat(); //convert the string to a floating point number
    if (sensorValue >= 7.0) {
    printf("high");
    }
    }
    I want to see sensorValue on my Serical port , how modify that code ? Thank you.
  • I am confused by your descriptions. Do you have a system diagram for this?
  • In fact , It's arduino code , the sensor is PH sensor , and they only PO Arduino code .

    #include <SoftwareSerial.h>                                  //we have to include the SoftwareSerial library, or else we can't use it

    #define rx 2                                                             //define what pin rx is going to be

    #define tx 3                                                            //define what pin tx is going to be

    SoftwareSerial myserial(rx, tx);                           //define how the soft serial port is going to work

    String inputstring = "";                                          //a string to hold incoming data from the PC

    String sensorstring = "";                                      //a string to hold the data from the Atlas Scientific product

    boolean input_string_complete = false;        //have we received all the data from the PC

    boolean sensor_string_complete = false;      //have we received all the data from the Atlas Scientific product

    float pH;                                             //used to hold a floating point number that is the pH

    void setup() {                                        //set up the hardware

     Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600

     myserial.begin(9600);                               //set baud rate for the software serial port to 9600

     inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC

     sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product

    }

    void serialEvent() {                                                          //if the hardware serial port_0 receives a char

     inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>

     input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC

    }

    void loop() {                                  

     if (input_string_complete) {                        //if a string from the PC has been received in its entirety

       myserial.print(inputstring);                      //send that string to the Atlas Scientific product

       myserial.print('\r');                                         //add a <CR> to the end of the string

       inputstring = "";                                                      //clear the string

       input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC

     }

     if (myserial.available() > 0) {                                //if we see that the Atlas Scientific product has sent a character

       char inchar = (char)myserial.read();              //get the char we just received

       sensorstring += inchar;                           //add the char to the var called sensorstring

       if (inchar == '\r') {                             //if the incoming character is a <CR>

         sensor_string_complete = true;                  //set the flag

       }

     }

     if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been received in its entirety

       Serial.println(sensorstring);                     //send that string to the PC's serial monitor

       if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit

         pH = sensorstring.toFloat();                    //convert the string to a floating point number so it can be evaluated by the Arduino

         if (pH >= 7.0) {                                           //if the pH is greater than or equal to 7.0

           Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string

         }

         if (pH <= 6.999) {                                    //if the pH is less than or equal to 6.999

           Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string

         }

       }

       sensorstring = "";                                                      //clear the string

       sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product

     }

    }

    sensor datasheet : pH_EZO_datasheet.pdf

  • I have shown you how to do UART read/write so I suppose you can do this sensor communication by yourself.
  • Thank you.

    I refer project uartecho_CC2650F128 , and copy two lines :

    and paste that code on SimpleBLEPeripheral.c

    static void SimpleBLEPeripheral_init(void)

    {  

         char input;
         const char echoPrompt[] = "\fEchoing characters:\r\n";

         UART_Params_init(&uartParams);
         uartParams.writeDataMode = UART_DATA_TEXT;
         uartParams.readDataMode = UART_DATA_TEXT;
         uartParams.readReturnMode = UART_RETURN_FULL;
         uartParams.readEcho = UART_ECHO_OFF;
         uartParams.baudRate = 9600;

         /* UART Open */
        uart = UART_open(CC2650_UART0, &uartParams);
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
        while (1) {
           UART_read(uart, &input, 1);
           UART_write(uart, &input, 1);
        }

    ledPinHandle = PIN_open(&ledPins, ledPinsTable);


    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);    //It's not work?

    Do I miss something?

  • You have a while (1) blocking there and that's why all functions after it doesn't work.

  • If I mark while(1), the UART cycle is not working.

    and if I while(1) , the process go on , but just like you said , blocking all function.

    where you  suggestion ?

  • You could create separate task/thread to do these two jobs.
  • I refer uartecho , it is a echoFxn :
    Void echoFxn(UArg arg0, UArg arg1)
    {
    char input;
    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";

    /* 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 = 9600;

    /* UART Open */
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
    System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    /* Loop forever echoing */
    while (1) {
    UART_read(uart, &input, 1);
    UART_write(uart, &input, 1);
    }
    }

    you mean I can use that fxn to add SimpleBLEPeripheral.c :
    static void SimpleBLEPeripheral_init(void)
    {
    ....................
    Void echoFxn(UArg arg0, UArg arg1);
    ........................
    }

    or I create a new task behind SimpleBLEPeripheral_init fxn?
    static void SimpleBLEPeripheral_init(void)
    {
    ...........
    ...........
    } //end of SimpleBLEPeripheral_init

    static void echoFxn(UArg arg0, UArg arg1)
    {
    .....................
    } //end of echoFxn
  • Hi Tzuyu,

    Can you please describe what your desired result is in words. From what I understand you want to add a PH sensor to the SensorTag and you're trying to adapt some Arduino code to the SensorTag?
  • You should use the following code to init echoFxn task.

    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);
  • Hello Sean2:
    Yes , I do really use CC2560 to connect PH sensor via UART , But I only have Arduino code can reference.
    I ask sensor supplier about sample code , they tell me only arduino code can refer. they also tell me , the sensor
    only use RX and TX to connect SmartRF06 EVM Board UART_RX and UART_TX , It's easy.
    So , I refer uartecho sample code , and modify SimpleBLEPeripheral sample code .
    In fact , my purpose is very simple , just read sensor data via UART , That's all , but I try almost three weeks ,
    no progress.
  • Hello,Yikai:

    I know how to read data via UART , and I am sucessed.

    but I want to know your idea , seems very good.

    so I modify echo fxn behide void SimpleBLEPeripheral_createTask(void) :

    void uart_createTask(void)

    {

        Task_Params_init(&taskParams);
         taskParams.stackSize = TASKSTACKSIZE;
        taskParams.stack = &task0Stack;
        Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);

    }

    and it's not working

  • In section 6.3.2 UART of SWRU393_CC2640_BLE_Software_Developer's_Guide.pdf, it shows you how to add UART support to SimpleBLEPeripheral. Why don't you use it?
  • Hello Yikai:
    I did really add section 6.3.2 UART on SimpleBLEPeripheral_inin(void) fux ,
    and it's OK , but if I am not connect any sensor to CC2650 , that code will stop on
    UART_write(....) , it waiting UART data , so I think, if I create another task ,
    maybe even the CC2650 can't read UART data , the process can still continue.
  • You can use the following codes to replace the code in main.c of SimpleBLEPeripheral. I have test it and see it works fine.


    #include <xdc/runtime/Error.h>

    #include <ti/sysbios/family/arm/cc26xx/Power.h>
    #include <ti/sysbios/BIOS.h>

    #include "ICall.h"
    #include "bcomdef.h"
    #include "peripheral.h"
    #include "simpleBLEPeripheral.h"

    /* Header files required to enable instruction fetch cache */
    #include <inc/hw_memmap.h>
    #include <driverlib/vims.h>
    #include <ti/drivers/UART.h>
    #include <ti/sysbios/knl/Task.h>

    #ifndef USE_DEFAULT_USER_CFG

    #include "bleUserConfig.h"

    // BLE user defined configuration
    bleUserCfg_t user0Cfg = BLE_USER_CFG;

    #endif // USE_DEFAULT_USER_CFG

    /**
     * Exception handler
     */
    void exceptionHandler()
    {
        volatile uint8_t i = 1;
        while(i){}
    }

    #ifdef FEATURE_OAD
    #if defined(__IAR_SYSTEMS_ICC__)
    extern uint32_t __vector_table;
    #elif defined (__TI_COMPILER_VERSION__)
    extern uint32_t ti_sysbios_family_arm_m3_Hwi_resetVectors;
    #endif //Compiler
    #endif //FEATURE_OAD

    /*
     *  ======== echoFxn ========
     *  Task for this function is created statically. See the project's .cfg file.
     */
    Void echoFxn(UArg arg0, UArg arg1)
    {
        char input;
        UART_Handle uart;
        UART_Params uartParams;
        const char echoPrompt[] = "\fEchoing characters:\r\n";

        /* 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 = 9600;
        uart = UART_open(CC2650_UART0, &uartParams);

        if (uart == NULL) {
            //System_abort("Error opening the UART");
            return;
        }

        UART_write(uart, echoPrompt, sizeof(echoPrompt));

        /* Loop forever echoing */
        while (1) {
            UART_read(uart, &input, 1);
            UART_write(uart, &input, 1);
        }
    }
    #define TASKSTACKSIZE     768

    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];

    /*
     *  ======== main ========
     */
    int main()
    {
      PIN_init(BoardGpioInitTable);
      Task_Params taskParams;

          /* Call board init functions */
      UART_init();

          /* Construct BIOS objects */
          Task_Params_init(&taskParams);
          taskParams.stackSize = TASKSTACKSIZE;
          taskParams.stack = &task0Stack;
          Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);

    #ifndef POWER_SAVING
        /* Set constraints for Standby, powerdown and idle mode */
        Power_setConstraint(Power_SB_DISALLOW);
        Power_setConstraint(Power_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING
        
        /* Initialize ICall module */
        ICall_init();

        /* Start tasks of external images - Priority 5 */
        ICall_createRemoteTasks();
        
        /* Kick off profile - Priority 3 */
        GAPRole_createTask();
        
        SimpleBLEPeripheral_createTask();

    #ifdef FEATURE_OAD
        {
          uint8_t counter;
          uint32_t *vectorTable =  (uint32_t*) 0x20000000;
    #if defined(__IAR_SYSTEMS_ICC__)
          uint32_t *flashVectors = &__vector_table;
    #elif defined(__TI_COMPILER_VERSION__)
          uint32_t *flashVectors = &ti_sysbios_family_arm_m3_Hwi_resetVectors;
    #endif //Compiler.
          
          // Write image specific interrupt vectors into RAM vector table.
          for(counter = 0; counter < 15; ++counter)
          {
            *vectorTable++ = *flashVectors++;
          }
        }
    #endif //FEATURE_OAD
        
        /* enable interrupts and start SYS/BIOS */
        BIOS_start();
        
        return 0;
    }

    /**
     * Error handled to be hooked into TI-RTOS
     */
    Void smallErrorHook(Error_Block *eb)
    {
      for (;;);
    }

    /**
     * HAL assert handler required by OSAL memory module.
     */
    void halAssertHandler(void)
    {
      for (;;);
    }

  • Thank you very much , the fxn is OK , at the same time , I also display data on LCD ,
    It's need to add
    #include "board_lcd.h"
    then I can use
    LCD_WRITE_STRING(....)
    Thank you again.
  • You are welcome.