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.

Serial Communication between CC13xx device

Other Parts Discussed in Thread: CC1310

Hi everyone, I working with two cc13xx device and I would like to implement a serial communication between device. I think that used a HyperTerminal, but I read on UART and not communicate. 

  • Does not work.
  • Oops! Try to setup sensniff to check what happens over the air.
  • What should he go out on the Wireshark?
  • I couldn't understand you question. Please elaborate. When you post a question next time, please elaborate it. Don't shoot it arbitrarily.
  • I would like to communicate between two cc13xx via serial. Send a hello from a device and get the word hello from another device. Connecting the 6lbr and the two devices via pc do not get that. You told me to try with wireshark, but what can i see on wireshark?
  • If you just need to communicate between two cc13xx via serial, it's nothing to do with Wireshark.
  • Why did you tell me to configure the sensniff then?
  • Because you told me your MQTT doesn't work and we usually need to use Wireshark to verify sensor to 6lbr communication is good.
  • Ok, but now I would like work with net-uart
  • Do you want to communicate between two cc13xx via serial or do you want to test net-uart? If it's net-uart, you should read Network UART (net-uart) section in github.com/.../cc26xx-web-demo and make sure it works first.
  • I want communicate between two cc1310 via serial, with cc26xx-web-demo
  • I am not clear about your intention. Can you use a diagram to show me what you want to do?
  • I think you have to revise net-uart.c to achieve this by yourself.

  • I know, but can you communicate between two devices? I've also read uart-echo, can you help me?
  • I think this is your own application and you can only help yourself.
  • I do not want your help, I just asked if the uart-echo example helps me
  • No, I don’t think so. UART echo example is based on TI RTOS but you want to work on Contiki OS.
  • PROCESS_THREAD(cc1310_uart_demo_process, ev, data)
    {
    char *rxdata;
    static uint16_t count=0;
    char string[20];

    PROCESS_BEGIN();
    uart_set_input(1, serial_line_input_byte);
    etimer_set(&et, CLOCK_SECOND * 4);
    leds_toggle(LEDS_GREEN);

    while(1) {
    PROCESS_WAIT_UNTIL(etimer_expired(&et));
    sprintf(string, "sending string %u.\n", ++count);
    uart1_send_bytes((uint8_t *)string, sizeof(string) - 1);
    etimer_reset(&et);
    printf("string is being sent\n");

    PROCESS_YIELD();
    if(ev == serial_line_event_message) {
    leds_toggle(LEDS_RED);
    rxdata = data;
    printf("Data received over UART %s\n", rxdata);
    }
    }

    PROCESS_END();
    }

    What do you think about it?
  • Okay, I already read it. In PROCESS_THREAD, should I put the method to turn the LED on / off? Right? Did the example I sent you did not work well?

  • I don't test your code so I don't know if it works.
  • /*
     * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     * 1. Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     * 2. Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     * 3. Neither the name of the copyright holder nor the names of its
     *    contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     * OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    /**
     * \addtogroup cc26xx-web-demo
     * @{
     *
     * \file
     *     A process which receives data over UART and transmits them over UDP
     *     to a pre-defined IPv6 address and port. It also listens on the same UDP
     *     port for messages, which it prints out over UART.
     *
     *     For this example to work, you will have to modify the destination IPv6
     *     address by adjusting the set_dest_addr() macro below.
     *
     *     To listen on your linux or OS X box:
     *     nc -6ulkw 1 REMOTE_PORT
     *
     *     (REMOTE_PORT should be the actual value of the define below, e.g. 7777)
     *
     *     Once netcat is up and listening, type something to the CC26xx's terminal
     *     Bear in mind that the datagram will only be sent after a 0x0a (LF) char
     *     has been received. Therefore, if you are on Win, do NOT use PuTTY for
     *     this purpose, since it does not send 0x0a as part of the line end. On
     *     Win XP use hyperterm. On Win 7 use some other software (e.g. Tera Term,
     *     which can be configured to send CRLF on enter keystrokes).
     *
     *     To send data in the other direction from your linux or OS X box:
     *
     *        nc -6u \<node IPv6 address\> REMOTE_PORT
     */
    /*---------------------------------------------------------------------------*/
    #include "contiki-conf.h"
    #include "sys/process.h"
    #include "sys/etimer.h"
    #include "dev/serial-line.h"
    #include "dev/cc26xx-uart.h"
    #include "dev/leds.h"
    #include "net/ip/uip.h"
    #include "net/ip/uip-udp-packet.h"
    #include "net/ip/uiplib.h"
    #include "net-uart.h"
    #include "httpd-simple.h"
    #include "sys/cc.h"
    
    #include "ti-lib.h"
    
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    /*---------------------------------------------------------------------------*/
    #define DEBUG DEBUG_NONE
    #include "net/ip/uip-debug.h"
    /*---------------------------------------------------------------------------*/
    #define REMOTE_PORT  7777
    #define MAX_MSG_SIZE  100
    
    #define set_dest_addr() uip_ip6addr(&remote_addr, \
                                        0xBBBB, 0x0000, 0x0000, 0x0000, \
                                        0x3E07, 0x54FF, 0xFE74, 0x4885);
    /*---------------------------------------------------------------------------*/
    #define ADDRESS_CONVERSION_OK       1
    #define ADDRESS_CONVERSION_ERROR    0
    /*---------------------------------------------------------------------------*/
    static struct uip_udp_conn *udp_conn = NULL;
    
    static uint8_t buffer[MAX_MSG_SIZE];
    static uint8_t msg_len;
    static uip_ip6addr_t remote_addr;
    /*---------------------------------------------------------------------------*/
    #define IPV6_ADDR_STR_LEN       64
    /*---------------------------------------------------------------------------*/
    PROCESS(net_uart_process, "Net UART Process");
    /*---------------------------------------------------------------------------*/
    PROCESS(cc26xx_uart_demo_process, "cc26xx uart demo");
    AUTOSTART_PROCESSES(&cc26xx_uart_demo_process);
    
    static struct etimer et;
    /*---------------------------------------------------------------------------*/
    /*
     * \brief Attempts to convert a string representation of an IPv6 address to a
     * numeric one.
     * \param buf The buffer with the string to be converted.
     * \return ADDRESS_CONVERSION_OK or ADDRESS_CONVERSION_ERROR
     *
     * ToDo: Add support for NAT64 conversion in case the incoming address is a v4
     * This is now supported in the current master, so when we pull it in this will
     * be very straightforward.
     */
    static int
    set_new_ip_address(char *buf)
    {
      /*
       * uiplib_ip6addrconv will immediately start writing into the supplied buffer
       * even if it subsequently fails. Thus, pass an intermediate buffer
       */
      uip_ip6addr_t tmp_addr;
    
      int rv = uiplib_ip6addrconv(buf, &tmp_addr);
    
      if(rv == ADDRESS_CONVERSION_OK) {
        /* Conversion OK, copy to our main buffer */
        memcpy(&remote_addr, &tmp_addr, sizeof(remote_addr));
    
        PRINTF("Updated remote address ");
        PRINT6ADDR(&remote_addr);
        PRINTF("\n");
      }
    
      return rv;
    }
    /*---------------------------------------------------------------------------*/
    static void
    net_input(void)
    {
      if(uip_newdata()) {
        memset(buffer, 0, MAX_MSG_SIZE);
        msg_len = MIN(uip_datalen(), MAX_MSG_SIZE - 1);
    
        /* Copy data */
        memcpy(buffer, uip_appdata, msg_len);
        printf("%s", (char *)buffer);
      }
    
      return;
    }
    /*---------------------------------------------------------------------------*/
    static void
    release_uart(void)
    {
      cc26xx_uart_set_input(NULL);
    }
    /*---------------------------------------------------------------------------*/
    static void
    keep_uart_on(void)
    {
      cc26xx_uart_set_input(serial_line_input_byte);
    }
    /*---------------------------------------------------------------------------*/
    static int
    remote_port_post_handler(char *key, int key_len, char *val, int val_len)
    {
      int rv;
    
      if(key_len != strlen("net_uart_port") ||
         strncasecmp(key, "net_uart_port", strlen("net_uart_port")) != 0) {
        /* Not ours */
        return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
      }
    
      rv = atoi(val);
    
      if(rv <= 65535 && rv > 0) {
        cc26xx_web_demo_config.net_uart.remote_port = (uint16_t)rv;
      } else {
        return HTTPD_SIMPLE_POST_HANDLER_ERROR;
      }
    
      return HTTPD_SIMPLE_POST_HANDLER_OK;
    }
    /*---------------------------------------------------------------------------*/
    static int
    remote_ipv6_post_handler(char *key, int key_len, char *val, int val_len)
    {
      int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
    
      if(key_len != strlen("net_uart_ip") ||
         strncasecmp(key, "net_uart_ip", strlen("net_uart_ip")) != 0) {
        /* Not ours */
        return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
      }
    
      if(val_len > IPV6_ADDR_STR_LEN) {
        /* Ours but bad value */
        rv = HTTPD_SIMPLE_POST_HANDLER_ERROR;
      } else {
        if(set_new_ip_address(val)) {
          memset(cc26xx_web_demo_config.net_uart.remote_address, 0,
                 NET_UART_IP_ADDR_STRLEN);
          memcpy(cc26xx_web_demo_config.net_uart.remote_address, val, val_len);
          rv = HTTPD_SIMPLE_POST_HANDLER_OK;
        }
      }
    
      return rv;
    }
    /*---------------------------------------------------------------------------*/
    static int
    on_off_post_handler(char *key, int key_len, char *val, int val_len)
    {
      int rv;
    
      if(key_len != strlen("net_uart_on") ||
         strncasecmp(key, "net_uart_on", strlen("net_uart_on")) != 0) {
        /* Not ours */
        return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
      }
    
      rv = atoi(val);
    
      /* Be pedantic: only accept 0 and 1, not just any non-zero value */
      if(rv == 0) {
        cc26xx_web_demo_config.net_uart.enable = 0;
        release_uart();
      } else if(rv == 1) {
        cc26xx_web_demo_config.net_uart.enable = 1;
        keep_uart_on();
      } else {
        return HTTPD_SIMPLE_POST_HANDLER_ERROR;
      }
    
      return HTTPD_SIMPLE_POST_HANDLER_OK;
    }
    /*---------------------------------------------------------------------------*/
    HTTPD_SIMPLE_POST_HANDLER(remote_port, remote_port_post_handler);
    HTTPD_SIMPLE_POST_HANDLER(remote_ipv6, remote_ipv6_post_handler);
    HTTPD_SIMPLE_POST_HANDLER(on_off, on_off_post_handler);
    /*---------------------------------------------------------------------------*/
    static void
    set_config_defaults(void)
    {
      /* Set a hard-coded destination address to start with */
      set_dest_addr();
    
      /* Set config defaults */
      cc26xx_web_demo_ipaddr_sprintf(cc26xx_web_demo_config.net_uart.remote_address,
                                     NET_UART_IP_ADDR_STRLEN, &remote_addr);
      cc26xx_web_demo_config.net_uart.remote_port = REMOTE_PORT;
      cc26xx_web_demo_config.net_uart.enable = 1;
    }
    /*---------------------------------------------------------------------------*/
    PROCESS_THREAD(net_uart_process, ev, data)
    {
      PROCESS_BEGIN();
    
      printf("CC26XX Net UART Process\n");
    
      set_config_defaults();
    
      udp_conn = udp_new(NULL, UIP_HTONS(0), NULL);
      udp_bind(udp_conn, UIP_HTONS(REMOTE_PORT));
    
      if(udp_conn == NULL) {
        printf("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
      }
    
      httpd_simple_register_post_handler(&remote_port_handler);
      httpd_simple_register_post_handler(&remote_ipv6_handler);
      httpd_simple_register_post_handler(&on_off_handler);
    
      while(1) {
    
        PROCESS_YIELD();
    
        if(ev == serial_line_event_message) {
          /*
           * If the message contains a new IP address, save it and go back to
           * waiting.
           */
          if(set_new_ip_address((char *)data) == ADDRESS_CONVERSION_ERROR) {
            /* Not an IP address in the message. Send to current destination */
            memset(buffer, 0, MAX_MSG_SIZE);
    
            /* We need to add a line feed, thus never fill the entire buffer */
            msg_len = MIN(strlen(data), MAX_MSG_SIZE - 1);
            memcpy(buffer, data, msg_len);
    
            /* Add a line feed */
            buffer[msg_len] = 0x0A;
            msg_len++;
    
            uip_udp_packet_sendto(
              udp_conn, buffer, msg_len, &remote_addr,
              UIP_HTONS(cc26xx_web_demo_config.net_uart.remote_port));
          }
        } else if(ev == tcpip_event) {
          net_input();
        } else if(ev == cc26xx_web_demo_config_loaded_event) {
          /*
           * New config. Check if it's possible to update the remote address.
           * The port will have been updated already
           */
          set_new_ip_address(cc26xx_web_demo_config.net_uart.remote_address);
    
          if(cc26xx_web_demo_config.net_uart.enable == 1) {
            keep_uart_on();
          }
        } else if(ev == cc26xx_web_demo_load_config_defaults) {
          set_config_defaults();
        }
      }
    
      PROCESS_END();
    }
    /*---------------------------------------------------------------------------*/
    PROCESS_THREAD(cc26xx_uart_demo_process, ev, data)
     {
    char *rxdata;
    static uint16_t count=0;
    char string [20];
    
    PROCESS_BEGIN();
    uart_set_input(1, serial_line_input_byte);
    etimer_set(&et, CLOCK_SECOND * 4);
    leds_toggle (LEDS_YELLOW);
    
    while (1) {
    
    PROCESS_WAIT_UNTIL(etimer_expired(&et));
    printf(string, "Invia stringa %u.\n", ++count);
    uart1_send_bytes((uint8_t *)string, sizeof(string) -1);
    etimer_reset(&et);
    printf("stringa inviata\n");
    
    PROCESS_YIELD();
    if(ev == serial_line_event_message)  {
    leds_toggle(LEDS_RED);
    rxdata = data;
    printf("Dato ricevutosull'UART %s\n", rxdata);
      }  
    }
    PROCESS_END();
      }
    /*---------------------------------------------------------------------------*/
    /**
     * @}
     * @}
     */
    

    This is my Net-Uart.c, I don't have error, but in the UART i don't see nothing

  • For your reference, I use hello world to test example code in github.com/.../Input-and-output and it works fine.
  • This code of example, Is it inserted in net-uart or a new code?
  • I copy it into hello-world.c and build hello-world.bin to test it.
  • Should I create the file .h?
  • I have this error

  • What are you doing?
  • The file bin of my code that i have generate
  • What's your code?
  • #include "contiki.h"
    #include "dev/serial-line.h"
    #include "dev/leds.h"
    #include "dev/uart.h"
    #include <stdio.h>
    #include <stdint.h>
    
    PROCESS(test_serial, "Serial line test process");
    AUTOSTART_PROCESSES(&test_serial);
    
    PROCESS_THREAD(test_serial, ev, data)
    {
     char *rxdata;
     char string[20];
     
     PROCESS_BEGIN();
     uart_set_input(1, serial_line_input_byte);
     leds_toggle(LEDS_YELLOW);
     printf(string, "sending data %u.\n");
     uart1_send_bytes((uint8_t *)string, sizeof(string) - 1);
     printf("string is sent\n");
     
     PROCESS_YIELD();
     if(ev == serial_line_event_message) {
       leds_toggle(LEDS_RED);
       rxdata = data;
       printf(" data received over UART %s\n", rxdata);
       }}
       
       PROCESS_END();
       }
     
     

  • I see your code missing a closing “}” in the end.
  •  I resolved this error and I generate the file in hello-world. But now I have this error:

  • What is “uart_set_input”? I have told you to test code in github.com/.../Input-and-output . Why do you keep ignoring it? If you always ignore my suggestion, I don’t want to help anymore.
  • #include "contiki.h"
    #include "dev/serial-line.h"
    #include "dev/leds.h"
    #include "dev/cc26xx-uart.h"
    #include <stdio.h>
    #include <stdint.h>
    
    PROCESS(test_serial, "Serial line test process");
    AUTOSTART_PROCESSES(&test_serial);
    /*-------------------------------------------------------*/
    uint8_t singleSample = 0;
    /*-------------------------------------------------------*/
    PROCESS_THREAD(test_serial, ev, data){ 
    PROCESS_BEGIN();
     
     printf("Wait\n");
     leds_on(LEDS_YELLOW);
     
     while(1){
    	 PROCESS_WAIT_EVENT_UNTIL((ev==serial_line_event_message) && (data == &singleSample));
         printf("Insert the character! \n");
     if(singleSample == 0) {
       printf("Led off!\n");
       leds_off(LEDS_YELLOW);
       singleSample=1;
       } else if(singleSample == 1) {
    	   printf("Led on!\n");
    	   leds_toggle(LEDS_YELLOW);
    	   singleSample=0;
     }}
       PROCESS_END();
       }
     /*--------------------------------------------------------------------------*/
    
    Sorry friend! I have correct the my code.

    See you this code, is fuction but if I write 1 or 0 on the serial the LED not function

  • You are not listen carefully.The example code in Serial Communication section is like the following:

    #include "contiki.h"
    #include "dev/serial-line.h"
    #include <stdio.h>

    PROCESS(test_serial, "Serial line test process");
    AUTOSTART_PROCESSES(&test_serial);

    PROCESS_THREAD(test_serial, ev, data)
    {
    PROCESS_BEGIN();

    for(;;) {
    PROCESS_YIELD();
    if(ev == serial_line_event_message) {
    printf("received line: %s\n", (char *)data);
    }
    }
    PROCESS_END();
    }

    I won't say again. Please take care of that by yourself.
  • And how do I turn the LED on / off?
  • Please! Just this once!
  • Don’t you think you should make UART work first?
  • I generate the file.bin with the code that give you. I read on UART, but now I would like to on/off led
  • If you input something to UART, do you see it echo to the output.
  • If I write something, he writes on UART
  • Can you do a screenshot to show me your test?
  • I see this on Serial

  • You told me “If I write something, he writes on UART”. Where is it in your screenshot?
  • If I write on Uart, I not read nothing. I see only this screenshot that sent you
  • You told me “If I write something, he writes on UART”. But, you didn’t. I cannot verify what is try from your replies. I cannot help in this way anymore.