Skip navigation
Home > All Places > Software Forums > WICED Smart Bluetooth > WICED Smart Bluetooth Forums > Blog > 2015 > August

Hello Everyone,


See the attached file for an example of use of the PUART.


To use the sample code, load it onto two Tag boards, connect the boards via PUART, rx-to-tx, with a common ground (currently setup for P32, P33). Run HCI traces (default) on one board and click the button (P0) on the other board. An incrementing value, starting at 0, will be displayed on your terminal with every click of the button. This value was sent via PUART from the peripheral board (the value will increment twice on every click because the button registers an interrupt on each rising and falling edge).



Advertiser and Scanner

Posted by userc_19497 Aug 19, 2015

Hello. Here is an example app that is capable of swapping between advertising and scanning.



BLE advertisement packets consists of 31 bytes. Each field (i.e. appearance, name, service UUID or similar) has a header of 2 bytes (length and type), meaning that the maximum user payload is 29 bytes. That means the more fields that are packed into one advertisement packet, there are less bytes freed for user payload.


Here's an example of advertisement data(AD) from Bluetooth SIG documentation. (pdf attached)

You can view all the different data types and formats in the documentation attached.


Advertisement Field

In our SDK, each field is represented by BLE_ADV_FIELD data structure. Here's the definition:

typedef PACKED struct
    UINT8 len; //length of field
    UINT8 val; //value of field
    UINT8 data[ADV_LEN_MAX-2]; // This is the data and the biggest one is 31-2 = 29

Notice the length, value, and the actual data in the struct corresponds to how AD is formatted in the example above.


You can change the advertisement packet by defining the fields in an array and initializing them.

    BLE_ADV_FIELD adv[2];

     // Format advertisement data.  Data consists of 2 fields.  Standard Advertisement flags
     // and Broadcom Vendor specific data.  The vendor specific data consists of
     // 16 byte UUID and a message "Hello"

     // flags
     adv[0].len     = 1 + 1; // 1 (data length) + 1 (value)
     adv[0].val     = ADV_FLAGS;

     adv[1].len     = 23 + 1; // 23 (data length) + (value)
     adv[1].val     = ADV_MANUFACTURER_DATA; // (AD_TYPE == 0xff)
     adv[1].data[0] = 0x0f;  // Broadcom  (Company Identifier 2 bytes)
     adv[1].data[1] = 0x00;

     // Set UUID
     BT_MEMCPY(&adv[1].data[2], mybeacon_uuid, 16);

     // Set "Hello" message
     BT_MEMCPY(&adv[1].data[18], msg, 5);


Here are the field values:

// ADV flag values
enum ble_adv_flag_value
    ADV_FLAGS                           = 0x01,
    ADV_SERVICE_UUID16_MORE             = 0x02,
    ADV_SERVICE_UUID16_COMP             = 0x03,
    ADV_SERVICE_UUID32_MORE             = 0x04,
    ADV_SERVICE_UUID32_COMP             = 0x05,
    ADV_SERVICE_UUID128_MORE            = 0x06,
    ADV_SERVICE_UUID128_COMP            = 0x07,
    ADV_LOCAL_NAME_SHORT                = 0x08,
    ADV_LOCAL_NAME_COMP                 = 0x09,
    ADV_TX_POWER_LEVEL                  = 0x0A,
    ADV_CLASS_OF_DEVICE                 = 0x0D,
    ADV_SIMPLE_PAIRING_HASH_C           = 0x0E,
    ADV_TK_VALUE                        = 0x10,
    ADV_OOB_FLAGS                       = 0x11,
    ADV_SERVICE_DATA                    = 0x16,
    ADV_TARGET_PUBLIC_ADR               = 0x17,
    ADV_TARGET_RANDOM_ADR               = 0x18,
    ADV_APPEARANCE                      = 0x19,
    ADV_ADVERTISING_INTERVAL            = 0x1A,
    ADV_SERVICE_DATA_UUID32             = 0x20,
    ADV_SERVICE_DATA_UUID128            = 0x21,
    ADV_INDOOR_POSITION                 = 0x24,
    ADV_3D_INFORMATION_DATA             = 0x3D,
    ADV_MANUFACTURER_DATA               = 0xFF,


Then, you'll have to call bleprofile_GenerateADVData function to actually generate the AD.

     bleprofile_GenerateADVData(adv, 2);

where the first parameter is the array to BLE_ADV_FIELD and the second is the number of fields.


Starting Advertisement

You can start advertising in few different ways.

If you have the BLE_PROFILE_CFG defined for the app, then you can simply start by calling:

   bleprofile_Discoverable(HIGH_UNDIRECTED_DISCOVERABLE, NULL);


Or you can start advertising by setting up the advertisement parameters yourself.

        HCIULP_ADV_NONCONNECTABLE_EVENT,                // non-connectable undirected advertisement
        160,                                            // adv interval 100 msec
        HCIULP_ADV_CHANNEL_MAP_MASK,                    // all channels
        HCIULP_PUBLIC_ADDRESS,                          // int advAdrType,
        HCIULP_ADV_FILTER_POLICY_WHITE_LIST_NOT_USED,   // int advFilterPolicy,
        HCIULP_PUBLIC_ADDRESS,                          // int initiatorAdrType,


Advertisement packets have different types.

The first argument to this function, blecm_startAdv defines the type of the advertisement.


Value Passed
Advertisement Type

You can refer to the "auto-generated API" for more details on this function.




In order to start scanning, you simply need to call blecen_Scan function.



Or to turn it off: 



Advertisement Handler

You need to register a handler if you want to do anything with the advertisement packet in the app create function.

void advertisement_handler(HCIULP_ADV_PACKET_REPORT_WDATA *evt);
void basic_create(void)

    // register to process peripheral advertisements
    blecm_RegleAdvReportCb((BLECM_FUNC_WITH_PARAM) advertisement_handler);



Swapping between Advertiser and Scanner

I have made an example app that swaps its role between advertising and scanning. The files are attached as adv.h and adv.c

The app first starts scanning, but you can change its role by pushing the button on the board. It has a minimum RSSI value, so you'll need to have advertising device close to the scanner in order for the scanner to pick up the advertisement.


I was able to put the code into two Tag 3 boards and test their functions.

Here's the app in action.

Both apps started:


One of them starts advertising:


Roles switched:


AD in detail:

Notice how the advertisement data corresponds to how we set the BLE_ADV_FIELD array above.



LED with PWM

Posted by userc_19497 Aug 17, 2015

Hello, here is how you can turn on an LED using PWM.

Include Library

#include "pwm.h"
#include "gpiodriver.h"

Define Macros

#define LED_RED    26  /* PWM 0 */
#define LED_BLUE   27  /* PWM 1 */
#define LED_GREEN  28  /* PWM 2 */

#define GPIO_PORT(x)  (x/16)
#define GPIO_PIN(x)   (x%16)


#define LED_RED_CHANNEL      (PWM0)
#define LED_BLUE_CHANNEL     (PWM1)

     Note: depending on which chip you are using, the GPIO Pins might change

Enable LED

     // enable
     gpio_configurePin(GPIO_PORT(LED_RED), GPIO_PIN(LED_RED), ENABLE_LED_RED, 0); 
     pwm_start( LED_GREEN_CHANNEL, LHL_CLK, 0x000 , 0);

     // pwm_start( id, clk, toggleCount, initCount);
     // Output Voltage  | Toggle Count (Found these values by trial & error)
     // --------------------------------------------
     // ~ (4/4) V_MAX  |    0x000
     // ~ (3/4) V_MAX  |    0x100
     // ~ (2/4) V_MAX  |    0x210
     // ~ (1/4) V_MAX  |    0x315


     Note: depending on the hardware configuration, the V_MAX may change

Disable LED

     // disable
     pwm_disableChannel( 1 << LED_RED_CHANNEL );




BCM2073XS GPIO Basics

Hardware User Guide (SDK 2.x and TAG3 Board)

How to turn on LED

Different Frequencies for PWM



Once you have the WICED Smart IDE installed you can import other WICED Smart SDK .7z releases easily without reinstalling the IDE, or even changing the workspace. This method comes in handy when you have several releases you want to test and compare. You may keep several projects(SDKs) open in one workspace, but for simplicity we will start with closing the existing project.



<Importing a New WICED Smart SDK>


1. Right-click on your current project name in the IDE and select "Close Project". This will not modify or delete your files in anyway. It will, however, close the files you had open in the IDE, and you can choose to either save any changes that had been made. (This step is optional, you may have several projects open at once)


2. Extract the new WICED Smart SDK .7z file to your chosen destination.

3. Click on the arrow next to the leftmost folder icon and select "Makefile Project with Existing Code"


4. Click on "Browse" and navigate to and then select the WICED SDK folder you created. The "Project Name" will be automatically filled in from the name in the "Existing Code Location" you choose. You may modify the name for clarity.


5. The new SDK will now be showing in the leftmost "Project Explorer" view.


<Making New Targets>

Initially the new project directory will not show up in the right-most "Make Target" view. You will need to set up the directory first and then you will be able to add on new targets more easily.

1. In the leftmost tab of "Project Explorer", right-click on the new project you just imported. Select "Make Targets" and "Create".


2. Type in "clean" as the target name and press OK. (Any name will do but you will probably need a target "clean" anyway)



3. In this step you will have to close the IDE window and then restart it. When it reopens, you will see that the directory for targets will has been created.



4. From now on you can right-click on the project name in the "Make Target" tab or just click on the target+ icon.



Enjoy working with your new SDK!

WICED Smart User's Guide

Posted by kwang Aug 3, 2015
Table of Contents:
Product SelectionProduct EvaluationWICED SenseProduct DevelopmentManufacturing / Production
Product Selection
Here you will find a series of links/resources that will assist in the selection of a WICED Smart BLE product:
Data sheets:
Product Evaluation
Here you will find a series of links/resources that will assist during the purchase/use of a WICED Smart BLE development system:
To purchase one of our kits, please visit our partners page: Purchase a WICED Bluetooth Dev Kit
Downloading and Installing the SDK
For SDK downloads, please visit WICED Smart Documents & Downloads
If you are using one of Broadcom's TAG boards the Quick Start guide is extremely helpful in getting to know the TAG board and using the SDK.
Quick Start Guides:
SDK 2.x and TAG3 - The specified item was not found.
Hardware Guides:
Common Errors While Installing
If you are having problems with your installer, check that the download size of the installer is roughly 260MB, installer problems are typically caused by incomplete downloads.
The picture below shows a very common error message.  Our SDK utilizes a 32-bit version of an Eclipse based IDE which requires a 32-bit version of JRE to be installed.  If you already have the 64-bit JRE installed, you will also need to install the 32-bit version as well. The JRE is designed to allow both 32 and 64 bit variants to be installed on the system.
The WICED Sense kit uses a Silicon Labs USB to Serial Device.  The TAG3 board uses an FTDI USB to Serial Device. Both should be installed as part of the SDK 2.2.1 installation process. If not, the FTDI drivers for the TAG3 reinstall them using the file /WICED-Smart-SDK/Drivers/dpinst.exe (make sure you access from the command line).  The Silicon Labs USB Drivers can be found WICED Sense Table of Contents
Everything we have for the WICED Sense, such as schematics, drivers, and Android application source code, can be accessed through the WICED Sense Table of Contents. A great post for the WICED Sense is the WICED SENSE Kit BLOG which is like a WICED Sense quick start guide.
Some Android devices appear to have issues pairing to the WICED Sense Tag from inside the app, linked is a work-around that should allow you to connect to your Android device: WICED Sense Android Pairing Work-Around
Product Development
The most basic starting points to begin writing code are hello_client/sensor and mybeacon.  AS does a great overview of hello_sensor in his interview: WICED Smart Video BLOG: Experts Interview - Sleep Deep_Sleep and Advertising
Below are links to commonly visited posts that may help in your development process.
GATT Database:








Command Line Tools:

Filter Blog

By date:
By tag: