Showing posts with label LAUNCHXL-CC2650. Show all posts
Showing posts with label LAUNCHXL-CC2650. Show all posts

Wednesday, December 18, 2019

How to change CC26xx/CC13xx UART baudrate dynamically in your application.

The following steps show you how to change CC26xx/CC13xx UART baudrate dynamically in your application.

1. In port pininterrupt example into your CCS.

2. Add the following header files for UART and task related stuffs.

    #include <ti/sysbios/knl/Task.h>
    #include <ti/drivers/UART.h>
    #include <stdint.h>

3. Add the following defines and global variables for UART and task related stuffs.

    #define TASKSTACKSIZE     768
    uint32_t baudrate=115200;
    bool baudrate_change=false;
    UART_Handle uart;
    UART_Params uartParams;

    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];

4. Add the following red codes into buttonCallbackFxn to change baudrate when BTN1 is pressed.

            case Board_BUTTON1:
                currVal =  PIN_getOutputValue(Board_LED1);
                PIN_setOutputValue(ledPinHandle, Board_LED1, !currVal);
                if(baudrate==115200){
                    const char echoBaudrateChange[] = "\fChange Baudrate to 9600:\r\n";
                    UART_write(uart, echoBaudrateChange, sizeof(echoBaudrateChange));
                    baudrate=9600;
                }else{
                    const char echoBaudrateChange[] = "\fChange Baudrate to 115200:\r\n";
                    UART_write(uart, echoBaudrateChange, sizeof(echoBaudrateChange));
                    baudrate=115200;
                }
                baudrate_change=true;
                break;


5. Add the following function echoFxn()

Void echoFxn(UArg arg0, UArg arg1)
{
    char input;
    const char echoPrompt[] = "\fEchoing characters:\r\n";

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);

RESTART_UART:
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = baudrate;
    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) {
        if(baudrate_change){
            UART_close(uart);
            uart=NULL;
            baudrate_change=false;
            goto RESTART_UART;
        }
        UART_read(uart, &input, 1);
        UART_write(uart, &input, 1);
    }
}


6. Add the following red codes in main function to start UART task.

int main(void)
{
    Task_Params taskParams;
    /* Call board init functions */
    Board_initGeneral();
    Board_initUART();

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


7. Build and download firmware into LaunchPad to test it.

Tuesday, December 17, 2019

How to create a periodic event to toggle BLE Advertising in CC26xx simple_peripheral example

The following steps show you how to create a periodic event to toggle BLE Advertising every 10 seconds in CC26xx simple_peripheral example.

In simple_peripheral.c, add the following codes:

1. Add "#define ADV_PERIODIC_EVT Event_Id_01" for new periodic event.

2. Add "#define ADV_PERIODIC_EVT_PERIOD 10000" to define the period as 10 seconds.

3. Add ADV_PERIODIC_EVT to Bitwise OR of all events to pend on.

    #define SBP_ALL_EVENTS       (SBP_ICALL_EVT        | \
                                                         SBP_QUEUE_EVT        | \
                                                         ADV_PERIODIC_EVT     | \
                                                         SBP_PERIODIC_EVT)

4. Add "advertEnabledPeriod = TRUE;" as a global variable for toggling BLE advertising.

5. Add "static Clock_Struct periodicClockAdv;" for periodic clock.

6. In SimplePeripheral_init(), add the following lines to start periodic event for toggling BLE advertising.

    Util_constructClock(&periodicClockAdv, SimplePeripheral_clockHandler,
                      ADV_PERIODIC_EVT_PERIOD, 0, false, ADV_PERIODIC_EVT);
    Util_startClock(&periodicClockAdv);



7.  Add the following codes in SimplePeripheral_taskFxn() to toggle BLE advertising in ADV_PERIODIC_EVT event which is triggered every 10 seconds.

      if (events & ADV_PERIODIC_EVT)
      {
        Util_startClock(&periodicClockAdv);
        if(advertEnabledPeriod==TRUE){
            advertEnabledPeriod=FALSE;
        } else {
            advertEnabledPeriod=TRUE;
        }
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                                 &advertEnabledPeriod);

      }


8. After building and download hex into your CC26xx device, you can use SimpleLink Starter APP to scan and check if BLE advertising is toggled every 10 seconds.

Thursday, January 17, 2019

How to output 32K crystal signal to specific pin on LAUNCHXL-CC2640R2

The following steps show you how to output 32K crystal signal to specific pin on LAUNCHXL-CC2640R2 using simple_peripheral example.

1. Add " #include  < driverlib/aon_ioc.h > " in simple_peripheral.c.

2. Add the following two lines in the end of SimplePeripheral_init() to output 32K crystal signal to DIO_10.

    IOCPortConfigureSet(IOID_10, IOC_PORT_AON_CLK32K, IOC_STD_OUTPUT);
    AONIOC32kHzOutputEnable();

3. Use scope to check wave form and frequency on DIO_10.

Thursday, October 11, 2018

How to use serial bootloader mode to download binary to LAUNCHXL-CC1310/LAUNCHXL-CC2650 using Flash Programmer 2

The following steps show you how to use serial bootloader mode to download binary to LAUNCHXL-CC1310/LAUNCHXL-CC2650 using Flash Programmer 2.

1. Select XDS110 CC1310 connection to do mass erase.


2. Select CC1310 and connect it to XDS110 Class Application/User Uart.




3. Select binary to download and you should see "Sucess!" after download.


Monday, April 23, 2018

How to connect Contiki-NG cc26xx-web-demo to IBM Watson IoT Platform.

The following steps show you how to connect Contiki-NG cc26xx-web-demo (running on LAUNCHXL-1310 or LAUNCHXL-CC2650) to IBM Watson IoT Platform.

1. Setup IBM Watson IoT Platform.
  • 1.1 Login to IBM Watson IoT Platform and go to SECURITY tab of Device page to use "TLS Optional". This step is critical. If you don't do this, you need to use TLS for connection and default cc26xx-web-demo won't work.

  • 1.2 Go to Device Types tab of Device page to click "Add Device Type".
  • 1.3 Input device type name. I use cc26xx-web-demo in this demo.
  • 1.4 Follow all the steps to finish add device type.
  • 1.5 Switch to Browse tab of Device page to click "Add Device".
  • 1.6 Select "Select Existing Device Type" to cc26xx-web-demo and input Device ID which I use device MAC address.
  • 1.7 Input authentication token.
  • 1.8 Keep your device credentials carefully.
  • 1.9 Finish adding device and you would see it on Browse tab of device page.

2. Running 6lbr and wrapsix on Raspberry Pi first and connect your cc26xx-web-demo running on LAUNCHXL-CC1310 or LAUNCHXL-CC2650 to your 6lbr and configure cc26xx-web-demo.
  • 2.1 Open "MQTT/IBM Cloud Config" page.
  • 2.2 Configure cc26xx-web-demo for IBM Watson IoT platform according to device credentials in step 1.7.
  • 2.3 Run "ping uc6bmi.messaging.internetofthings.ibmcloud.com" to get its IPv4 address 169.45.2.20.
  • 2.4 Change broker IP to "0064:ff9b:0000:0000:0000:0000:a92d:0214" which is IPv6 address of "169.45.2.20".
  • 2.5 Click "Submit" on "MQTT/IBM Cloud Config" page to connect to IBM Watson IoT platform.

Thursday, April 19, 2018

How to build and run Contiki-NG cc26xx-web-demo running on LAUNCHXL-CC1310 and rpl-border-router on Raspberry Pi with slip radio running on LAUNCHXL-CC1310

The following steps show how to build and run Contiki-NG cc26xx-web-demo running on LAUNCHXL-CC1310 (or LAUNCHXL-CC2650) and rpl-border-router on Raspberry Pi with slip radio running on LAUNCHXL-CC1310 (or LAUNCHXL-CC2650) .

1. Do "git clone --recursive https://github.com/contiki-ng/contiki-ng" on your InstantContiki or Cygwin (you can build Cygwin develop environment according to here)

2. Build slip radio for LAUNCHXL-CC1310

  • 2.1 Change directory to contiki-ng/examples/slip-radio
  • 2.2 Add "#define IEEE802154_CONF_DEFAULT_CHANNEL 25" to project-conf.h
  • 2.3 Build slip-radio.bin by "make TARGET=srf06-cc26xx BOARD=launchpad/cc1310 slip-radio.bin"
  • 2.4 Download slip-radio.bin to one of LAUNCHXL-CC1310 to act as slip radio for usage of rpl-border-router.
3. Build cc26x0-web-demo for LAUNCHXL-CC1310

  • 3.1 Change directory to contiki-ng/examples/platform-specific/cc26xx/cc26x0-web-demo
  • 3.2 Make sure "#define IEEE802154_CONF_DEFAULT_CHANNEL 25" is defined in project-conf.h
  • 3.3 Build cc26xx-web-demo.bin by "make TARGET=srf06-cc26xx BOARD=launchpad/cc1310 cc26xx-web-demo.bin"
  • 3.4 Download cc26xx-web-demo.bin to another of LAUNCHXL-CC1310 to connect with rpl-border-router later.
4. Build and run rpl-border-router on Raspberry Pi
  • 4.1 Do "git clone --recursive https://github.com/contiki-ng/contiki-ng" on your Raspberry Pi.
  • 4.2 Change directory to contiki-ng/examples/rpl-border-router
  • 4.3 Build border-router.native by "make TARGET=native all"
  • 4.4 Connect LAUNCHXL-CC1310 (running slip radio) to Raspberry Pi and make sure it emulates ttyACM0.
  • 4.5 Run rpl-border-router by "sudo ./border-router -native fd00::1/64 -s /dev/ttyACM0"

5. You can type "help" on rpl-border-router console to know more available commands.



6. You can login to Raspberry Pi using another terminal and do "ping6 fd00::212:4b00:e00:cc00" to see reply from rpl-border-router.


6. Power on cc26xx-web-demo on another LAUNCHXL-CC1310. The green led on LAUNCHXL-CC1310 should blink fast in the beginning. When you see green led blinking slows down, it means cc26xx-web-demo joins rpl-border-router.

7. You can type "ip-nbr" on rpl-border-router console to know reachable nodes.



8. Now, you can do "ping6 fd00::212:4b00:a27:f319" (fd00::212:4b00:a27:f319 is the IPv6 address of cc26xx-web-demo) and see reply from cc26xx-web-demo.




Build and run 6lbr/Contiki-NG cc26xx-web-demo on Rasperry Pi with LAUNCHXL-CC1310/LAUNCHXL-CC2650

The following steps show how to build and run 6lbr/Contiki-NG cc26xx-web-demo on Rasperry Pi with LAUNCHXL-CC1310/LAUNCHXL-CC2650:

1. Build Contiki-NG slip radio for LAUNCHXL-CC1310 on InstantContiki 3.0 or Cygwin (you can refer here to setup Cygwin build environment)
  • 1.1 Do "git clone --recursive https://github.com/contiki-ng/contiki-ng"
  • 1.2 Switch to directory contiki-ng/
  • 1.3 Do "git submodule sync" and "git submodule update --init"
  • 1.4 Switch to directory contiki-ng/examples/slip-radio
  • 1.5 Since 6lbr/Contiki-NG only supports RPL-CLASSIC now, we use "make TARGET=cc26x0-cc13x0 srf06-cc26xx BOARD=launchpad/cc1310 MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC  slip-radio.bin" to build slip radio for LAUNCHXL-CC1310.
  • 1.6 Download slip-radio.bin to one LAUNCHXL-CC1310 to act as slip radio for Raspberry Pi later.

2. Build Contiki-NG cc26x0-web-demo for LAUNCHXL-CC1310 on InstantContiki 3.0 or Cygwin
  • 2.1 Apply Fixing cc26xx 6lbr client example patch first.
  • 2.2 Switch to directory contiki-ng/examples/platform-specific/cc26xx/cc26x0-web-demo
  • 2.3 Since 6lbr/Contiki-NG only supports RPL-CLASSIC now, we use "make TARGET=srf06-cc26xx BOARD=launchpad/cc1310 MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC  cc26xx-web-demo.bin" to build cc26xx-web-demo for LAUNCHXL-CC1310.
  • 2.4 Download cc26xx-web-demo.bin to another LAUNCHXL-CC1310 to join Raspberry Pi 6lbr later.

3. Build 6lbr/Contiki-NG on Rasperry Pi
  • 3.1 SSH login to Raspberry Pi.
  • 3.2 Change directory to home folder and git clone --recursive https://github.com/cetic/6lbr.git
  • 3.3 Change directory to 6lbr folder and do "git submodule update --init" git checkout contiki-ng
  • 3.4 Change directory to home folder and git clone --recursive https://github.com/cetic/contiki-ng.git
  • 3.5 Change directory to contiki-ng folder and do "git submodule update --init" git checkout sixlbr
  • 3.6 Change directory to 6lbr/examples/6lbr folder and run the following build command
    "make WITH_CONTIKI=0 CONTIKI=~/contiki-ng WERROR=0 all"
  • 3.7  After build successfully, do "sudo make install". You will see "install: cannot stat ‘tools/nvm_tool’: No such file or directory" issue since nvm_tool doens't make properly for current version. It might be fixed later but you can use nvm_tool built by previous 6lbr to do the following steps.
  • 3.8 Run "sudo /usr/lib/6lbr/bin/nvm_tool --update --channel 25 /etc/6lbr/nvm.dat" to change 6lbr/Contiki-NG to use channel 25.
  • 3.9 Run "/usr/lib/6lbr/bin/nvm_tool --print /etc/6lbr/nvm.dat" to make sure it switches to channel 25.
  • 3.10 Connect LAUNCHXL-CC1310 running slip radio to Raspberry Pi.
  • 3.11 Run "sudo service 6lbr start" to start 6lbr/Contiki-NG and you can use Firefox to access to [bbbb::100]


 4. Power on LAUNCHXL-CC1310 running cc26xx-web-demo and you will see it pops on sensors tab of 6lbr web page. You can test http or coap function on cc26xx-web-demo now.






Tuesday, April 17, 2018

How to use 6lbr node config to enable IPv4 port mapping to allow accessing to cc26xx-web-demo from IPv4 address with mapped port on Raspberry Pi.

The following steps show you how to use 6lbr node config to enable IPv4 port mapping to allow accessing to cc26xx-web-demo from IPv4 address with mapped port on Raspberry Pi.

1. Go to 6lbr web page and switch to Configuration tab.



2. Go to IP64 section in Configuration tab.
  • 2.1 Fill IPv4 address of internet router that your 6lbr GW connects to. Mine is 10.15.8.1
  • 2.2 Fill IPv4 address that you want your 6lbr GW to be. Mine is 10.15.8.150
  • 3.3 Set Static port mapping to "on".

3. Login to Raspberry Pi and do "sudo vi /etc/6lbr/node_config.conf" to add a node into it. You can refer to node_config.conf format here. My test uses LAUNXCHXL-CC1310 (MAC address 00:12:4B:00:0A:27:F3:19) to run cc26xx-web-demo


4.  Do "sudo vi /etc/6lbr/6lbr.conf" and add "NODE_CONFIG=/etc/6lbr/node_config.conf".


5. Do "sudo service 6lbr restart" to restart 6lbr and power on cc26xx-web-demo (running on LAUNCHXL-CC1310 with MAC address 00:12:4B:00:0A:27:F3:19). You should see it pops on sensors configuration


6. Now, you can access to the node using IPv4 address 10.15.8.150 and port 25000 by http://10.15.8.150:25000



Tuesday, April 10, 2018

Connect IBM quickstart of Contik cc26xx-web-demo to node-red for data processing.

The following steps show you how to connect IBM quickstart of Contik cc26xx-web-demo to node-red for data processing.

1.Login to IBM Bluemix and switch to Dashboard. Click "Create resource" button to create node-red.

2. Add node-red to filter. Find "Node-RED starter" and click it to create node-red application,


3.Give an App name and click "Create" button.


4. Wait the service to be started. It will take a while.

5. After service starts, click "Visit App URL" to access to node-red flow editor.

6. You will need to follow the steps in the wizard to setup node-red editor account when you create it first time.
7.Then, click on "Go to your Node-RED flow editor" to access to node-red URL.


8. This is Node-RED flow editor.

9. Switch to IBM quickstart and click on "IMPORT FLOW"

10. Copy the data.

11. Click hamburger icon -> import -> Clipboard to import data from IBM quickstart.

12. Paste the data and click "import"

13. IBM quickstart of mapped device status are imported. Click "Deploy" button to deploy it.

14. You can see data starts streaming on debug window.

15. You can construct your data flow to storage like mangoDB or process them.

Wednesday, January 3, 2018

How to create a new task in TI RTOS to use ICall service like osal_snv_write and osal_snv_read.

The following steps show you how to create a new task in TI RTOS to use ICall service like osal_snv_write and osal_snv_read. I will use ProjectZero in TI BLE Stack 2.2.1 as an example running on LAUNCHXL-CC2650 to do it.

1. Increase OSAL_MAX_NUM_PROXY_TASKS in BLE Stack project osal.c and rebuild Stack project to download it to your LAUNCHXL-CC2650.

2. Increase ICALL_MAX_NUM_TASKS and ICALL_MAX_NUM_ENTITIES in ProjectZero application Predefined Symbols.

3. Add the following Test_createTask function in ProjectZero.c and claim function prototype "extern void Test_createTask(void);" in ProjectZero.h

// Task configuration
#define TEST_TASK_STACK_SIZE                   800
Task_Struct testTask;
Char testTaskStack[TEST_TASK_STACK_SIZE ];

void Test_createTask(void)
{
  Task_Params taskParams;

  // Configure task
  Task_Params_init(&taskParams);
  taskParams.stack = testTaskStack;
  taskParams.stackSize = TEST_TASK_STACK_SIZE ;
  taskParams.priority = 2;

  Task_construct(&testTask, TestFunction, &taskParams, NULL);
}

4. Add the following TestFunction function in ProjectZero.c

// Entity ID globally used to check for source and/or destination of messages
static ICall_EntityID testEntity;
// Semaphore globally used to post events to the application thread
static ICall_Semaphore testsem;

uint8 status_snv;
uint8 write_buffer[10];
uint8 read_buffer[10];

static void TestFunction(UArg a0, UArg a1)
{

  ICall_registerApp(&testEntity, &testsem);
  while(1)
  {
      write_buffer[0] = 0x12;
      write_buffer[1] = 0x12;
      write_buffer[2] = 0x12;
      write_buffer[3] = 0x12;

      status_snv = osal_snv_write(0x80,10, (uint8_t *)write_buffer );

      //Do ADC Polling and Data processing
      read_buffer[0] = 0x0;
      read_buffer[1] = 0x0;
      read_buffer[2] = 0x0;
      read_buffer[3] = 0x0;

      status_snv = osal_snv_read(0x80,10, (uint8_t *)read_buffer );
  }


5. Call "Test_createTask();" right after "ProjectZero_createTask();" to create TestFunction task to use ICall service for osal_snv_write/osal_snv_read.

Thursday, December 7, 2017

How to use LAUNCHXL-CC2650 to work with Wireshark as Zigbee sniffer.

The following steps show you how to use LAUNCHXL-CC2650 to work with Wireshark as Zigbee sniffer.

1. Download and install PACKET-SNIFFER-2 from http://www.ti.com/tool/PACKET-SNIFFER
 
2. Connect the LaunchPad board to the PC with a USB cable and program sniffer_fw_15_4.hex under C:\Program Files (x86)\Texas Instruments\SmartRF Tools\SmartRF Packet Sniffer 2\sniffer_fw\bin\cc26x0lp\15.4 to your LAUNCHXL-CC2650 using Flash Programmer 2.



3. Start SmartRF Sniffer Agent and select Data -> Data Out to check "Use Pipe".



4. Press the Device Configuration button and select a sniffer device, frequency band and channel to use.



5. Press "Start All" button. The incoming data indicator becomes green and the outgoing data indicator becomes blue.



6. Install Wireshark and create a new desktop shortcut. Then, modify the Target setting of the new Wireshark shortcut to add "-i\\.\pipe\tiwspc_data -k" to the end.



7. Start Wireshark and go to Edit->Preferences...->Protocol->Zigbee to add Zigbee TC Link Key "5a6967426565416c6c69616e63653039".



8. Start the new Wireshark shortcut and you will see Wireshark starts to do Zigbee sniff.