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.

CC2650: How to send data from Arduino to CC2650 over UART

Part Number: CC2650


Hello,

I tried the following example at sunmaysky blog and it's working. It says pressing Ctlr+Enter it will send character "0x0A".to launchpad .By typing input and prassing "Ctrl+enter"it takes inputs.I checked this code.

https://sunmaysky.blogspot.com/2017/11/using-contiki-udp-client-to-send-onoff.html

I modified the code to give any keyboard input(By using a for loop to convert input to hex) from pc to launchpad and viewed from teraterm and it worked.Then I tried to give a serial input from an arduino(rx,tx) to cc2650 launchpad (DIO3-rx,DIO2-tx) and view from tera term.But it seems no results give.Is it a problem with "Ctrl+Enter"?????.. Should we code Arduino to give "ctrl+enter" at the end of each input line..So how to trigger the launchpad serial port to get  the input.????I tried so many times by coding arduino by serial.write   \n,\r\n,\r,0x0A  ike that after the input datal.It seems nothing happen.

The simple arduino code as follows,

int no=10;
void setup() {
Serial.begin(15200);

}

void loop() {

Serial.print(no);
delay(5);
Serial.write(0x0A);



delay(500);


no++;

}

  • Wow!!! It's working!!!!

    I can't understand how you know all these stuff!!

    Dear YK Chen,

    Currently we are finalizing this project.We will no longer with this project in few weeks. The aspects of our project were to read electricity meter data via coap, design nodes in a less power consuming way using cc2650, attach a current sensing circuit so that we can read power consumption of any node via coap, implementing network monitoring tool(analyzing of links),Over the air firmware update, Design nodes under cost of $5 per node etc. Then using cooja we simulated the network also. We completed all these things by now.

    It's confirmed that project will  divide into few projects and continue seeking different aspects like implementing mesh network for mobility scenarios(revising the routing protocols etc.) , critical situation warning like(fire/gas/floods  etc.) and many more.

    I have never learned c language or contiki OS when I started. I remember I leaned step by step from you,

    Running hello-world

    coding udp-client,udp-server according to requirements

    taking serial input from a device like arduino and how to take them,

    How to code to sense analog sensing of dio 23 pin

    how to interact with a device which needs a request from node and how to take serial inputs.

    How to code them in web-demo.c 

    You helped me to debugging lot of things also.

    (We  are students and do not get paid for any of these developments. But government provide funds to cover all the purchasing of materials to develop).

    I hope you will help them also and will post the progress in few days. 

    I'm in a question that are you doing a job ? as you reply instantly every time.

  • Yes, I have a job and I am willing to help people.

  • Dear sir,

    when testing CC2650 launchpad at outside scenario, we observed a noticeable RSSI value drop down around node distance 20-30m(for one link.] udp-client.bin for one node and udp-server.bin for another node-line of sight). Do you know to explain it using contiki MAC protocols or any other thing? How is the antenna pattern of this and is it the reason for this?

    Thanks.

  • I would guess there’s interference causing such issue.

  • Do you mean there were obstacles?Actually no interference. we  tested in two grounds.There were no any obstacle.Any ground reflection of antenna pattern can affect this??

  • I don’t mean obstacles. CC2650 runs on 2.4G and there are lots of things run on 2.4G. It’s quite noisy. By t way, what do you mean “we  tested in two grounds”?

  • I meant two open spaces without obstacles.

  • If you test it at clean open space like beach area, it should be able to reach 50-60 meters at least.

  • Yes.It has a maximum range of about 150m- 200m. From 0m to 150m we observe a gradual decrease of RSSI. In around 25m RSSI drops and again it rises to the normal behavior of graph. That's why I asked what happened? Hope that is interference.

  • You can try to test range at different site to see if the same situation happens.

  • in arduino c coding there is a data type "byte"

    ex- byte Array[];

    in contiki "byte" type is not defined. Is it "uint8_c"?????

  • Yes, you can use uint8_t.

  • Imagine the coap resource value is a float value.

    in res-net.c ( here bxxxx is "extern float bxxxx" i);

    "snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "n %f n", bxxxx);" will give output as " n     n"..no data is displayed.

    but if I use %u or %x there is a some value shown as when requesting coap data.

    Can't we snprintf a float value in contiki????

  • If I remember correctly, you cannot snprintf a float value in contiki. The alternative is to split float value into integer and fraction when you use snprintf.

  • Dear sir,

    This question on periodically collecting meter readings to variables in cc26xx-web-demo.c

    First I tried with editing " meter process" to collectt data periodically. But it didn't work.

    Then I tried with editing "udp-client process" in web-demo.c to periodically collecting data. It periodically request from the meter and meter replies come to the cc2650 launchpad also. The first request is working finely.but after the first  iteration unfortunately "if(ev == serial_line_event_message) is not trigerring after success of the first request. First try is trigerring. Do you see any problem here????

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Here "etimer periodic" doen't expire/////////////////////////////////////////////

    PROCESS(meter_process,"METER process");
    static struct etimer periodic;


    PROCESS_THREAD(meter_process, ev, data)

    {
    PROCESS_BEGIN();
    cc26xx_uart_set_input(serial_line_input_byte);

    etimer_set(&periodic, 5 * CLOCK_SECOND);
    while(1) {







    PROCESS_YIELD();

    if(ev == serial_line_event_message) {
    leds_on(LEDS_RED);


    for(int i=0;i< 64;i=i+1)def_rt_strr[i]=0x0;

    for(int i=0;i<strlen(data);i=i+1){
    def_rt_strr[i]=((char*)data)[i];


    }

    uint8_t incomingByteVal [4] = {};

    for (int i = 0; i < 4; i++) {

    incomingByteVal[i] = def_rt_strr[i + 3];
    }

    const char byteString[32] = "";

    array_to_string(incomingByteVal, 4, byteString);    //calculations starts here
    union {
    uint32_t i;
    float f;
    } data;

    data.i = strtoul(byteString, NULL, 16);

    rus1 = data.f;

    printf("rus1 = %d",rus1);
    float rusfrac = data.f - rus1;
    rus2 = trunc(rusfrac * 10000);      //calculations end here
    printf("rus2= %d",rus2);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic));
    if (etimer_expired(&periodic)) {
    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    etimer_reset(&periodic);


    }


    }

    }
    leds_off(LEDS_RED);
    PROCESS_END();

    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////here first request works fine.if(ev == serial_line_event_message) is trig erring and in first request data are stored in relevant variables and fine. udp-client process request data from the meter periodically.Meter also replies. I checked all these things. But from the second request if(ev == serial_line_event_message) and the data are not stored in relevant variables.  ///////////////////////

    PROCESS_THREAD(udp_client_process, ev, data)
    {
    static struct etimer periodic_timer;
    static struct etimer send_timer;
    static char buf[32];
    static unsigned message_number;
    uip_ipaddr_t fixed_addr;


    PROCESS_BEGIN();

    simple_udp_register(&unicast_connection, UDP_PORT,
    NULL, UDP_PORT, receiver);

    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {


    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));

    if (etimer_expired(&periodic_timer){
    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    etimer_reset(&periodic_timer);

    etimer_set(&send_timer, SEND_TIME);

    }



    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));

    uip_ip6addr(&fixed_addr, 0xfd00, 0, 0, 0, 0, 0, 0, 1);

    uip_debug_ipaddr_print(&fixed_addr);
    sprintf(buf, "Message %d", message_number);
    message_number++;
    simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &fixed_addr);

    }

    PROCESS_END();
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • You should not put “PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic));” in your METER process.

  • Sorry. That way is not working. in" meter process ",I have defined in this way. etimer_set(&periodic, 5 * CLOCK_SECOND);.So it should be going to printf loop within at least 10 minutes right?? I checked about 20 min.Still not going to that line......

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    In" Udp-client process" if I edit the code in above  way. the timer functions are working. cc2650 periodically request from the meter and meter replies come to rx 0f  cc2650. But as I previously said "if(ev==serial_line_event_message) is not trig erring. I can't understand why it happens.

  • I think that is due to you put wait timer event in “if(ev == serial_line_event_message)...”

  • No.I removed" PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic));" in "meter process ??? Do you mean process yield() ????

  • I couldn’t understand your descriptions and questions.

  • Okay. The problem is cc2650 launchpad is connected with electricity meter. The problem is meter readings are not updating. 

    In cc26xx-web-demo.c, inside the" PROCESS_THREAD(cc26xx_web_demo_process, ev, data)" I have printf these commands.

    process_start(&udp_client_process,NULL);

    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    process_start(&meter_process,NULL);

     


    when restarting the cc2650 ,after this request message meter replies and the process goes to " meter_process" while loop . So using coap I can see the meter readings using the values stored in " rus1 and rus2" variables. 

    In meter process I wrote to periodically update the readings. But the readings do not update(no  printf of "commands "happens).

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    PROCESS(meter_process,"METER process");
    static struct etimer periodic;


    PROCESS_THREAD(meter_process, ev, data)

    {
    PROCESS_BEGIN();
    cc26xx_uart_set_input(serial_line_input_byte);

    etimer_set(&periodic, 5 * CLOCK_SECOND);
    while(1) {







    PROCESS_YIELD();

    if(ev == serial_line_event_message) {
    leds_on(LEDS_RED);


    for(int i=0;i< 64;i=i+1)def_rt_strr[i]=0x0;

    for(int i=0;i<strlen(data);i=i+1){
    def_rt_strr[i]=((char*)data)[i];


    }

    uint8_t incomingByteVal [4] = {};

    for (int i = 0; i < 4; i++) {

    incomingByteVal[i] = def_rt_strr[i + 3];
    }

    const char byteString[32] = "";

    array_to_string(incomingByteVal, 4, byteString);    //calculations starts here
    union {
    uint32_t i;
    float f;
    } data;

    data.i = strtoul(byteString, NULL, 16);

    rus1 = data.f;

    printf("rus1 = %d",rus1);
    float rusfrac = data.f - rus1;
    rus2 = trunc(rusfrac * 10000);      //calculations end here
    printf("rus2= %d",rus2);


    if (etimer_expired(&periodic)) {
    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    etimer_reset(&periodic);


    }


    }

    }
    leds_off(LEDS_RED);
    PROCESS_END();

    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    ***************************************************************************************************

    When this not happens I tried with editing udp-client process to periodically request data from meter. So I did it in following manner.

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    PROCESS_THREAD(udp_client_process, ev, data)
    {
    static struct etimer periodic_timer;
    static struct etimer send_timer;
    static char buf[32];
    static unsigned message_number;
    uip_ipaddr_t fixed_addr;


    PROCESS_BEGIN();

    simple_udp_register(&unicast_connection, UDP_PORT,
    NULL, UDP_PORT, receiver);

    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {


    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));

    if (etimer_expired(&periodic_timer){
    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    etimer_reset(&periodic_timer);

    etimer_set(&send_timer, SEND_TIME);

    }



    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));

    uip_ip6addr(&fixed_addr, 0xfd00, 0, 0, 0, 0, 0, 0, 1);

    uip_debug_ipaddr_print(&fixed_addr);
    sprintf(buf, "Message %d", message_number);
    message_number++;
    simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &fixed_addr);

    }

    PROCESS_END();
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    So now cc2650 is requesting data from the meter periodically(printf of commads going), meter also replies. But in "meter_process" if(ev == serial_line_event_message) is not trigerring (Serial input is not getting).

    My target is to periodically update meter readings. That's my problem.

    Thanks.

  • I suppose you should use one process to send UART command periodically and use another process to do UART receiving. Don’t mess UART TX and RX in the same process.

  • Okay ,as you said I added a new process to uart print. Now that process every 14 seconds sends a request message to meter and meter also replies. I checked with using UART to USB  converter and using serial monitor.  To Rx of cc2650 rmeter replies come every 14 seconds now. But in meter_process (if(ev == serial_line_event_message)  is not trigerring. my recently defined process as follows,

    //////////////////////////////////////////////////////

    PROCESS(print_process,"PRINT process");


    PROCESS_THREAD(print_process, ev, data)
    {
    static struct etimer prin;
    PROCESS_BEGIN();

    etimer_set(&prin, CLOCK_SECOND * 14);
    while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&prin)) {

    leds_on(LEDS_RED);

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command6[]={0x02};
    static const uint8_t *command7[]={0x71};
    static const uint8_t *command8[]={0xCB};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    leds_off(LEDS_RED);

    etimer_restart(&prin);
    }
    }
    PROCESS_END();
    }

    ////////////////////////////////////////////////////////

  • Please look my previous post also. First iteration is working fine. from Second iteration values are not updating. The variable values keep remain as first iteration values becuase in meter_process(if(ev == serial_line_event_message) is not trigerring.

  • Can you post your latest codes in meter process?

  • Sure.

    ////////////////////////////////////////////////

    In web-demo.c

    char def_rt_strr[64];
    int rus1;
    int rus2;

    these I defined as extern in web-demo.h as,

    extern char def_rt_strr[64];
    extern int rus1;
    extern int rus2;

    //////////////////////////////////////////////////////////

    PROCESS(meter_process,"METER process");
    static struct etimer periodic;


    PROCESS_THREAD(meter_process, ev, data)

    {
    PROCESS_BEGIN();
    cc26xx_uart_set_input(serial_line_input_byte);

    etimer_set(&periodic, 5 * CLOCK_SECOND);
    while(1) {







    PROCESS_YIELD();

    if(ev == serial_line_event_message) {

    for(int i=0;i< 64;i=i+1)def_rt_strr[i]=0x0;

    for(int i=0;i<strlen(data);i=i+1){
    def_rt_strr[i]=((char*)data)[i];


    }

    uint8_t incomingByteVal [4] = {};

    for (int i = 0; i < 4; i++) {

    incomingByteVal[i] = def_rt_strr[i + 3];                                           //here i'm doing from received 9 bytes converting to meter reading 
    }

    const char byteString[32] = "";

    array_to_string(incomingByteVal, 4, byteString);
    union {
    uint32_t i;
    float f;
    } data;

    data.i = strtoul(byteString, NULL, 16);

    rus1 = data.f;                                                                              //as my converted meter value is a float value i'm getting two variables rus 1 and rus2

    float rusfrac = data.f - rus1;

    rus2 = trunc(rusfrac * 10000);                                                       // rus1 represents full number part rus2 represent fraction part

    etimer_reset(&periodic);



    }

    }
    leds_off(LEDS_RED);
    PROCESS_END();

    }

    /////////////////////////////////////////////////////////////

  • If you try to send UART messages manually, can your meter process receive the messages?

  • I tested this. Process is capable of successfully trigger if(ev == serial_line_event_message)  for the first received message. After onwards it doesn't happen.

  • I suggest you to check if serial-line.c sends serial_line_event_message event first.

  • I think it is not an issue with serial_line_event_message. If I restart the cc2650 it updates with new meter reading value . To update I have to give restart. I don't know why it happens.and How to check the function of "serial_line_event_message"??

  • If you revise serial-line.c, I remember it should send serial_line_event_message when there is any byte received in UART RX, right?

  • No.Now I have revised the code in following manner.

    ///////////////////////////////////////////////////////////////

    PROCESS_THREAD(serial_line_process, ev, data)

    {
    static char buf[BUFSIZE];
    static int ptr;

    PROCESS_BEGIN();

    serial_line_event_message = process_alloc_event();
    ptr = 0;

    while(1) {
    /* Fill application buffer until newline or empty */
    int q = ringbuf_get(&rxbuf);

    if(q == -1) {
    /* Buffer empty, wait for poll */
    PROCESS_YIELD();
    } else {
    if(q != END) {
    if(ptr < BUFSIZE-1) {
    buf[ptr++] = (uint8_t)q;
    if(ptr==9){
    process_post(PROCESS_BROADCAST, serial_line_event_message, buf);


    }
    } else {
    /* Ignore character (wait for EOL) */
    }
    } else {
    /* Terminate */
    buf[ptr++] = (uint8_t)'\0';

    /* Broadcast event */

    /*process_post(PROCESS_BROADCAST, serial_line_event_message, buf);rusiri changed*/
    /* Wait until all processes have handled the serial line event */
    if(PROCESS_ERR_OK ==
    process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL)) {
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE);
    }
    ptr = 0;
    }
    }
    }

    PROCESS_END();
    }

    ////////////////////////////////////////////////////////////

    I'm collecting whole meter reply (9 bytes) at a time and then sends a serial_line_event_message. 

    I checked with serial monitor. meter reply only consists with 9 bytes only at one time.

    Another observation is imagine cc2650 is working,but meter is not powered. As usually for rus1 & rus2 variables are 0 & 0. 

    After some iterations if I power on meter, the next iteration is collecting values for rus1 and rus2. But after that iteration no updating happens.

  • I think there’s something wrong in your logic since I don’t see a clear logic that how your ptr would be reset to 0.

  • Exactly. That was the problem. Many Many thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Dear sir,

    Now the code is okay.I'm trying to remove all unnecessary code parts from the each code.

    /////////////////////////////////////////////////////////////////////////////////////////////

    /////////////////////////////// Read Meter //////////////////////////////////////////////
    static void
    res_get_meter_reading(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
    {


    unsigned int accept = -1;
    /*char def_rt_str[64];*/

    REST.get_header_accept(request, &accept);

    /*memset(def_rt_strr, 0, sizeof(def_rt_strr)); isuru commented*/

    if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
    REST.set_header_content_type(response, REST.type.TEXT_PLAIN);


    snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%d", rus1,rus2);

    REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer));
    } else if(accept == REST.type.APPLICATION_JSON) {
    REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
    snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{\"Parent\":\"%s\"}",
    def_rt_strr);

    REST.set_response_payload(response, buffer, strlen((char *)buffer));
    } else if(accept == REST.type.APPLICATION_XML) {
    REST.set_header_content_type(response, REST.type.APPLICATION_XML);
    snprintf((char *)buffer, REST_MAX_CHUNK_SIZE,
    "<parent=\"%s\"/>", def_rt_strr);

    REST.set_response_payload(response, buffer, strlen((char *)buffer));
    } else {
    REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
    REST.set_response_payload(response, coap_server_supported_msg,
    strlen(coap_server_supported_msg));
    }

    }
    //////////////////////////////////////////////////////////////////////////////////////////

    Here in "res_get_meter_reading" in res-net.c do you see any unnecessary part  that i can remove from the code??????

  • I cannot check unnecessary codes of your application for you. You should do this by yourself.

  • Dear sir,,

    when printf commands in following manner creates warnings as follows.Do you know a method to remove these warnings???

    static const uint8_t *command1[]={0x01};
    static const uint8_t *command2[]={0x04};
    static const uint8_t *command4[]={0x46};
    static const uint8_t *command5[]={0x02};
    static const uint8_t *command6[]={0x90};
    static const uint8_t *command7[]={0x1E};

    printf(command1);
    printf(command2);
    printf("%c",0x00);
    printf(command4);
    printf("%c",0x00);
    printf(command5);
    printf(command6);
    printf(command7);

    ///////////////////////////////////////////////////////////////////

    cc26xx-web-demo.c:381:4: warning: (near initialization for 'command2[0]')
    cc26xx-web-demo.c:382:4: warning: initialization makes pointer from integer without a cast
    static const uint8_t *command4[]={0x46};
    ^
    cc26xx-web-demo.c:382:4: warning: (near initialization for 'command4[0]')
    cc26xx-web-demo.c:383:4: warning: initialization makes pointer from integer without a cast
    static const uint8_t *command5[]={0x02};
    ^
    cc26xx-web-demo.c:383:4: warning: (near initialization for 'command5[0]')
    cc26xx-web-demo.c:384:4: warning: initialization makes pointer from integer without a cast
    static const uint8_t *command6[]={0x90};
    ^
    cc26xx-web-demo.c:384:4: warning: (near initialization for 'command6[0]')
    cc26xx-web-demo.c:385:4: warning: initialization makes pointer from integer without a cast
    static const uint8_t *command7[]={0x1E};
    ^
    cc26xx-web-demo.c:385:4: warning: (near initialization for 'command7[0]')
    cc26xx-web-demo.c:387:11: warning: passing argument 1 of 'printf' from incompatible pointer type

    /////////////////////////////////////////////////////////////

  • For such C language question, you can google it and get answer such as stackoverflow.com/.../initialization-makes-pointer-from-integer-without-a-cast-c

  • Dear sir,

    This is on a question about feasibility of an enhancement of our project.

    IN SDM120 modbus electricity meter capable of reply various data like current,voltage,energy,frequency etc. according to various  commands.

    Imagine in cc26xx-web-demo.c I defined three different processes to printf various commamds at defined  etimer intervals inside that processes.

    1. Is there anyway for me to periodically and sequentially printf commands ??(I mean first printf process1 printf commands , next printf process 2 printf commands, then process 3 commands.I think defining all in same process is infeasible as after printf command meter replies,so if ev==serial_line_event_message triggers,also adding delays cannot be done because cc2650 will miss meter replies.)

    2. Then Meter's reply doesn't contain the data saying for which command it is replying.[device adress + reading+CRC](The reply doesn't contain any byte saying that this is the reply for current request command, voltage request command etc.). 

    It is good if we can display all the meter reading data of one node. Enegy consumption,frequency, voltage,current  etc.

    I coded 3 different processes to printf various request commands, so using coap we can see those data,but without the name.(Imagine I edited web-demo.c to request frequency,voltage and Current meter periodically.) So using coap I can see 49.88,225.78,0.6,50.8,50.4,0.9,234.12,234.57

    The problem is I cannot do a thing like this  "snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "V=%d.%d,F=%d.%d,C=%d.%d", rus1volt,rus2volt,rus1freq,rus2freq,rus1current,rus2current);


    Did you get my point??

    In cc26xx-web-demo.c I'm facing a problem that I cannot identify for which command meter is replying.because ev==serial_line_event_message triggers for all.

  • I suggest you to create different process with different periodic event to send different Uart command to your meter.

  • Exactly yes. I should create different processes to printf different commands. But problem is in electricity meter's reply(inside the message) it doesn't contain for which command it is replying. So I cannot identify for which command is replying. Because for every reply serial_line_event_message is trigerring. Did you get my point? So I'm in a trouble I cannot assign variables for them.

  • Do you mean that you cannot tell the differences from UART receiving current,voltage,energy,frequency. etc?

  • Yes. In Meters reply it doesn't give any identification of the reply subject( current,voltage,energy,frequency. etc). (Currently I have implemented processes so I can  request one of above Functions) ex- i can cc2650 to request energy,i can cc2650 to request voltage etc.But only one function.  Even though I can define different printf processes for various functions , meters reply doesn't conatain any information for which function it is replying. That's my problem. Any method to implement this?or is it impossible to handle various functions?

  • I suppose you can use single meter process to send current,voltage,energy,frequency. etc UART command one by one and use a global count to keep a record of what command you send. For example, count=1 means current, count=2 means voltage, etc. When receiving, you can check count value to know which one you receive.

  • Dear sir,
    As I asked yesterday to remove uint8_t warnings. Still I couldn't identify the solution.
    //////////////////////////////////////////////////////////////////////////////////////
    uint8_t *command1[]={0x01};
    uint8_t *command2[]={0x04};
    uint8_t *command6[]={0x02};
    uint8_t *command7[]={0x71};
    uint8_t *command8[]={0xCB};


    printf(command1 );
    printf(command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf(command6);
    printf(command7);
    printf(command8);

    Only this format is giving relavant output correctly. But this gives warnings as follows.
    ///////////////////////////////////////////////////////////////////////////////////////
    ######################these are the warnings################
    cc26xx-web-demo.c: In function 'process_thread_print_process':
    cc26xx-web-demo.c:325:4: warning: initialization makes pointer from integer without a cast
    uint8_t *command1[]={0x01};
    ^
    cc26xx-web-demo.c:325:4: warning: (near initialization for 'command1[0]')
    cc26xx-web-demo.c:326:4: warning: initialization makes pointer from integer without a cast
    uint8_t *command2[]={0x04};
    ^
    cc26xx-web-demo.c:326:4: warning: (near initialization for 'command2[0]')
    cc26xx-web-demo.c:327:4: warning: initialization makes pointer from integer without a cast
    uint8_t *command6[]={0x02};
    ^
    cc26xx-web-demo.c:327:4: warning: (near initialization for 'command6[0]')
    cc26xx-web-demo.c:328:4: warning: initialization makes pointer from integer without a cast
    uint8_t *command7[]={0x71};
    ^
    cc26xx-web-demo.c:328:4: warning: (near initialization for 'command7[0]')
    cc26xx-web-demo.c:329:4: warning: initialization makes pointer from integer without a cast
    uint8_t *command8[]={0xCB};
    ^
    cc26xx-web-demo.c:329:4: warning: (near initialization for 'command8[0]')
    cc26xx-web-demo.c:332:11: warning: passing argument 1 of 'printf' from incompatible pointer type
    printf(command1 );
    ^
    In file included from /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/string.h:10:0,
    from ../../../core/./net/ip/uip.h:89,
    from ../../../core/./net/ip/tcpip.h:88,
    from ../../../core/./contiki-net.h:39,
    from cc26xx-web-demo.c:41:
    /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/stdio.h:177:5: note: expected 'const char * restrict' but argument is of type 'uint8_t **'
    int _EXFUN(printf, (const char *__restrict, ...)
    ^
    cc26xx-web-demo.c:333:11: warning: passing argument 1 of 'printf' from incompatible pointer type
    printf(command2);
    ^
    In file included from /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/string.h:10:0,
    from ../../../core/./net/ip/uip.h:89,
    from ../../../core/./net/ip/tcpip.h:88,
    from ../../../core/./contiki-net.h:39,
    from cc26xx-web-demo.c:41:
    /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/stdio.h:177:5: note: expected 'const char * restrict' but argument is of type 'uint8_t **'
    int _EXFUN(printf, (const char *__restrict, ...)
    ^
    cc26xx-web-demo.c:337:11: warning: passing argument 1 of 'printf' from incompatible pointer type
    printf(command6);
    ^
    In file included from /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/string.h:10:0,
    from ../../../core/./net/ip/uip.h:89,
    from ../../../core/./net/ip/tcpip.h:88,
    from ../../../core/./contiki-net.h:39,
    from cc26xx-web-demo.c:41:
    /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/stdio.h:177:5: note: expected 'const char * restrict' but argument is of type 'uint8_t **'
    int _EXFUN(printf, (const char *__restrict, ...)
    ^
    cc26xx-web-demo.c:338:11: warning: passing argument 1 of 'printf' from incompatible pointer type
    printf(command7);
    ^
    In file included from /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/string.h:10:0,
    from ../../../core/./net/ip/uip.h:89,
    from ../../../core/./net/ip/tcpip.h:88,
    from ../../../core/./contiki-net.h:39,
    from cc26xx-web-demo.c:41:
    /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/stdio.h:177:5: note: expected 'const char * restrict' but argument is of type 'uint8_t **'
    int _EXFUN(printf, (const char *__restrict, ...)
    ^
    cc26xx-web-demo.c:339:11: warning: passing argument 1 of 'printf' from incompatible pointer type
    printf(command8);
    ^
    In file included from /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/string.h:10:0,
    from ../../../core/./net/ip/uip.h:89,
    from ../../../core/./net/ip/tcpip.h:88,
    from ../../../core/./contiki-net.h:39,
    from cc26xx-web-demo.c:41:
    /home/user/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/include/stdio.h:177:5: note: expected 'const char * restrict' but argument is of type 'uint8_t **'
    int _EXFUN(printf, (const char *__restrict, ...)
    ^


    ##########################################################

    I tried with following things. But they will not give the output which I expect.(Printf hex as bytes will not happen in the hardware). Another warnings appear.
    uint8_t *command1[]={0x01};
    uint8_t *command2[]={0x04};
    uint8_t *command6[]={0x02};
    uint8_t *command7[]={0x71};
    uint8_t *command8[]={0xCB};


    printf("%c",command1 );
    printf("%c",command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",command6);
    printf("%c",command7);
    printf("%c",command8);

    I also checked with %x,%u,%02x,%02hhx and many more referring to google searches. Non of above works. But still I couldn't find any solution.


    can you suggest me any solution???

  • Do you google the solution by yourself and try to solve the issue?

  • Yes. of course. it's about casting uint_8. I tried so many on stackoverflow.But  couldn't find any method. when casting ,

    uint8_t *command1[]={0x01};
    uint8_t *command2[]={0x04};
    uint8_t *command6[]={0x02};
    uint8_t *command7[]={0x71};
    uint8_t *command8[]={0xCB};


    printf("%c",command1 );
    printf("%c",command2);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",command6);
    printf("%c",command7);
    printf("%c",command8);

    removes all the warnings regarding the matter. But when this is done cc2650 launchpad is not working.I think uint8_t cannot cast to %c  . I tried so many other methods like casting to %x.,%02x,%hhx,  and all other methods which I found. when this done uart output is wrong(not as expected).

  • Do you mean to output characters "0x01" to UART? If so, why don't you hard code it to printf directly?

  • I need to printf hex values as bytes. If I look the output from a serial terminal(hex enabled) it should be like this.{01}{04}{00}{00}{00}(02}{71}{CB}.

    That's why. Hardcoding in following ways will not working. you mean this way right?

    printf("%c",0x01 );
    printf("%c",0x04);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x00);
    printf("%c",0x02);
    printf("%c",0x71);
    printf("%c",0xCB);

    even %x,%hhx,%02x, etc will not give expected output. I checked every output using  serial monitor using uart to usb converter.

  • I remember we had discussed format in the beginning of this thread. Do you see problem in the beginning?