background image

In this assignment, the following steps are added to the Host MCU application to set up and handle a
device information service within the ATBTLC1000 module. The following steps are added to the startup
project:

Adding device info service component from ASF

Configuring and loading the service

Figure 4-2. Device Information Service

4.1 

Adding Device Info Service Component from ASF Wizard to Project

To use the “officially adopted GATT-based profiles” from SIG, ASF provides Bluetooth Low Energy service
components including init functions that pre-define services in Host memory.

Note: 

 Before starting this assignment, be sure to follow the steps mentioned in 

Creating the Project and

Initializing 

and 

Establishing Connection with Central Device

.

1.

Click 

ASF > ASF Wizard

.

2.

Search for “BLE-Device Information Services” and then click 

Add

.

 ATBTLC1000

Setting/Handling of Pre-Defined Service

©

 2017 Microchip Technology Inc.

 Training Manual

DS00002599A-page 31

Summary of Contents for ATBTLC1000 Xplained Pro

Page 1: ...hitecture to software design Description of the required process for developing the Bluetooth Low Energy peripheral application with the ATBTLC1000 Handling of Bluetooth Low Energy custom services and characteristics Note The custom service implementation procedure uses the ATBTLC1000ZR XSTK kit This procedure is also applicable for other supported platforms as mentioned in BluSDK Release Notes Fi...

Page 2: ...andling of Pre Defined Service 30 4 1 Adding Device Info Service Component from ASF Wizard to Project 31 4 2 Configuring and Loading Device Information Service 33 5 Setting up and Handling Custom Service 37 5 1 Configuring and Loading the Custom Environment Service 38 5 2 Updating the Temperature Characteristic 43 6 Appendix A Software Solution Pre Defined Svc 47 7 Appendix B Software Solution Cus...

Page 3: ...Worldwide Sales and Service 57 ATBTLC1000 2017 Microchip Technology Inc Training Manual DS00002599A page 3 ...

Page 4: ...e previous releases refer to the Atmel Studio Release Notes available on the Microchip web page 1 2 Software Setup 1 2 1 Installation of Microchip SmartConnect application on a Mobile device 1 Open the Apple Store iPhone iOS or Google Play Store Android on the mobile device 2 Search for Microchip SmartConnect 3 Click Install to install application on the device The Microchip SmartConnect applicati...

Page 5: ... Manager SM The Security Manager defines the procedure for pairing authentication and encryption between BLE devices This layer is mainly used if security is requested on that particular connection Logical Link Control and Adaptation Protocol L2CAP L2CAP supports high level protocol multiplexing packet segmentation reassembly and conveying the quality of service information L2CAP permits applicati...

Page 6: ...event messages are then returned by the ATBTLC1000 on request processing or on specific Bluetooth Low Energy events These event messages are to be handled by the host device according to the user application requirements The following figure illustrates a typical Bluetooth Low Energy peripheral application flowchart ATBTLC1000 Getting Started 2017 Microchip Technology Inc Training Manual DS0000259...

Page 7: ...5 1 SMART SAM L21 Xplained Pro The SMART SAM L21 Xplained Pro evaluation kit is used to evaluate the ATSAML21J18B microcontroller This kit includes an on board embedded debugger to program and debug ATSAML21J18B The kit also contains an on board current measurement circuitry which enables the user to measure current profile over time without any external tools The connection with any Xplained Pro ...

Page 8: ...ny of the supported host MCU Xplained Pro evaluation boards to quickly add Bluetooth Low Energy connectivity to the platform This kit provides easy access to the features of the ATBTLC1000 ZR110CA Bluetooth Low Energy module and illustrates how to integrate the device in a custom design which is supported by the Atmel Studio integrated development platform ATBTLC1000 Getting Started 2017 Microchip...

Page 9: ...d serial EEPROM Compatible with two wire I2C and SMBus serial interfaces Current Measurement Header Allows measurement of the current consumption of the board It must be closed to enable power to the ATBTLC1000 ZR110CA module 1 6 Hardware Setup 1 Ensure that ATBTLC1000ZR XPRO power consumption header is closed and that jumpers are placed on pins 2 to 3 of headers J105 J106 J107 and J108 as shown i...

Page 10: ... XPRO as illustrated in the following figure Figure 1 8 ATBTLC1000ZR XPRO Extension connected with SAM L21 XPRO 3 Connect the board to PC using the Debug USB Connector Figure 1 9 SAM L21 XPRO Connection to PC ATBTLC1000 Getting Started 2017 Microchip Technology Inc Training Manual DS00002599A page 10 ...

Page 11: ...4 Now the Hardware is ready for development ATBTLC1000 Getting Started 2017 Microchip Technology Inc Training Manual DS00002599A page 11 ...

Page 12: ...L21 Note For more details refer to module datasheet and XPRO board design documentation 2 1 Creating Project from ASF Advanced Software Framework has a pre configured Bluetooth Low Energy Startup template project that includes Bluetooth Low Energy software API for Host and ATBTLC1000 and their peripheral driver dependencies This is used as starting project for any Bluetooth Low Energy project deve...

Page 13: ...Xplained Pro board and then press OK button to import the BLE startup template project Select BLE Startup Template SAM L21 Xplained Pro SAML21J18B for this hands on Note Rev B XPRO boards can be identified by SAML21J18B silk screen marking below SAML21 MCU 3 The BLE startup project is now created and loaded in Atmel Studio Figure 2 3 Startup_Template Project ATBTLC1000 Creating the Project and Ini...

Page 14: ...ty by using a Timer Counter TC or Timer Counter for Control TCC peripheral Console UART Universal Asynchronous Receiver Transmitter UART communication in synchronous blocking mode Generic Board Support Host MCU Board specific initialization System Drivers Select MCU s System peripheral drivers These drivers are included by default in ASF projects and manage the clocks and oscillator of the system ...

Page 15: ... C Compiler Symbols 3 The ATBTLC1000ZR XSTK kit uses the ATBTLC1000 ZR110CA module Change symbol BLE_MODULE to BTLC1000_ZR and enable UART_FLOWCONTROL_4WIRE_MODE for ATBTLC1000 ZR module as shown in the figure below Figure 2 6 Startup Template Project Window Note This configuration change is not required for ATBTLC1000 MR module ATBTLC1000 Creating the Project and Initializing 2017 Microchip Techn...

Page 16: ...XPLAINED_PRO_B1 Properties Figure 2 8 Compiling the Project 5 In project properties click the Tool tab and select the EDBG of SAM L21 Xplained Pro board as debugger programmer Figure 2 9 Selection of Debugger Programmer 6 Open any Terminal application for example TeraTerm Select the COM port enumerated on the PC and set the following parameters EDBG associated COM Port Check Windows Device Manager...

Page 17: ...module must return the Bluetooth Device Address and Address type Figure 2 10 Console Log Window Note 1 If initialization fails make sure to verify the hardware configuration is aligned with the description refer to Hardware Setup 2 The initialization of ATBTLC1000 takes few seconds due to patch download process ATBTLC1000 Creating the Project and Initializing 2017 Microchip Technology Inc Training...

Page 18: ...teraction between Host MCU ATBTLC1000 and Bluetooth Low Energy central during connection establishment is as follows Figure 3 1 Establishing Connection with Central Device On host MCU side the management of the Bluetooth connection is performed through three main steps 1 GAP callback registration 2 Advertisement configuration 3 ATBTLC1000 event handling In the existing project main routine the int...

Page 19: ...fication To avoid any collision with other wireless network such as Wi Fi a channel change is performed for each advertisement packet sent data frequency hopping as illustrated in the following figure Figure 3 3 Advertisement Process During advertisement the payload structure to be sent differs from application to application and is set by using encapsulated packet data unit type information PDU_T...

Page 20: ...pheral the connectable undirected event ADV_IND advertising type is used See the following description about the ADV_IND advertisement packet Figure 3 5 ADV_IND Advertisement Packet The ADV_IND payload contains different Advertisement Data types AD0 ADn which provide specific information to the central device such as device short name Tx power level and list of available services UUIDs The number ...

Page 21: ... assigned as 0x1809 so its equivalent UUID is 00001809 0000 1000 8000 00805F9B34FB 3 1 3 Device Name AD Types 0x08 to 0x09 This AD type field is used to advertise the Local name of device in the network The Local name data type value indicates if the name is complete or shortened If the name is shortened the complete name can be read after the connection is established 0x08 Shortened Local Name 0x...

Page 22: ...equires a parameter raw adv_data to be sent to central Following is an example of its definition static uint8_t adv_data 0x11 AD1 length 17 0x03 AD1 Type Complete list of 128 bit UUIDs 0x1b 0xc5 0xd5 0xa5 0x02 0x00 0xa6 0x87 AD1 UUID MSBs 0xe5 0x11 0x36 0x39 0xc0 0xba 0x5a 0xf0 0x0A AD2 Length 10 0x09 AD2 Type Complete local Name M y _ D E V AD2 My_DEV 3 1 3 2 Starting the Advertisement Process at...

Page 23: ...ss In this assignment the advertisement process is performed in the following configuration Undirected Type AT_BLE_ADV_TYPE_UNDIRECTED Discoverable Mode AT_BLE_ADV_GEN_DISCOVERABLE No peer Address peer_addr NULL No filtering filtered AT_BLE_ADV_FP_ANY Advertisement interval 1s interval 1600 Maximum timeout timeout 655 Randomness enabled disable_randomness FALSE 3 1 4 1 Starting the Advertisement P...

Page 24: ... advertisement process by adding the following highlighted code to the application main routine int main void if SAMG55 SAM4S Initialize the SAM system sysclk_init board_init elif SAM0 system_init endif Initialize serial console serial_console_init Hardware timer hw_timer_init button initialization button_init hw_timer_register_callback timer_callback_fn DBG_LOG Initializing BLE Application initia...

Page 25: ...play the following Log output Figure 3 9 Log Output Window 3 2 Managing GAP events The management of the Bluetooth connection at the host MCU level is done through reception and handling of events reported by the ATBTLC1000 These events are generated by ATBTLC1000 GAP GATT and L2CAP layers to notify the host about the ongoing Bluetooth interaction with other devices in its vicinity ATBTLC1000 Esta...

Page 26: ...vents typedef struct ble_gap_event_cb BLE Undefined events received from ATBTLC1000 which is not handled in Library ble_event_callback_t undefined BLE scan information contains the peer device scan information Refer ref at_ble_scan_info_t ble_event_callback_t scan_info Once the BLE scan timeout or scan stop triggers the scan report event Refer ref at_ble_scan_report_t ble_event_callback_t scan_rep...

Page 27: ...d_t ble_event_callback_t peer_att_info_ind Peer device channel map received indication ref at_ble_channel_map_t ble_event_callback_t con_channel_map_ind ble_gap_event_cb_t Note Callback definition is application specific If the application layer requires a specific event callback then the specific member of the structure is to be assigned with the address of the callback function In this assignmen...

Page 28: ...nt main void if SAMG55 SAM4S Initialize the SAM system sysclk_init board_init elif SAM0 system_init endif Initialize serial console serial_console_init Hardware timer hw_timer_init button initialization button_init hw_timer_register_callback timer_callback_fn DBG_LOG Initializing BLE Application initialize the BLE chip and Set the Device Address ble_device_init NULL Register ATBTLC1000 Gap Callbac...

Page 29: ...e list pass key 123456 Note 1 Pairing event handling is carried out by ble_manager c Refer to ble_pair_key_request_handler for code implementation The default pass key of 123456 is also fixed inside this function This can be changed here Figure 3 11 Console Log Window Note After peripheral pairing no services information are displayed in Microchip SmartConnect application as no service is currentl...

Page 30: ...e may reference other primary or secondary services and or a set of characteristics that make up the service Each service distinguishes itself from other services by means of a unique numeric ID called as UUID which can be either 16 bit for officially adopted Bluetooth Low Energy Services or 128 bit for custom services Note A full list of officially adopted services and their UUID are seen on the ...

Page 31: ...from ASF Wizard to Project To use the officially adopted GATT based profiles from SIG ASF provides Bluetooth Low Energy service components including init functions that pre define services in Host memory Note Before starting this assignment be sure to follow the steps mentioned in Creating the Project and Initializing and Establishing Connection with Central Device 1 Click ASF ASF Wizard 2 Search ...

Page 32: ...k Apply to add the component to the project Figure 4 5 Adding the Modules to Project 5 The Device Information Service component is added to the project and is confirmed by device_information folder added in Solution Explorer ATBTLC1000 Setting Handling of Pre Defined Service 2017 Microchip Technology Inc Training Manual DS00002599A page 32 ...

Page 33: ...uded service references included_service_count In number of elements in included_service_list charactristic_list In Out an array of characteristics included in the service this array is updated with respective characteristics handles charactristic_count In number of elements in charactristic_list Return Execution Status This function requires an argument as GATT description structure of the servic...

Page 34: ...UTHR permissions endif device_info_serv serv_chars 0 user_desc NULL user defined name device_info_serv serv_chars 0 user_desc_len 0 device_info_serv serv_chars 0 user_desc_max_len 0 device_info_serv serv_chars 0 user_desc_permissions AT_BLE_ATTR_NO_PERMISSIONS user description permissions device_info_serv serv_chars 0 client_config_permissions AT_BLE_ATTR_NO_PERMISSIONS client config permissions d...

Page 35: ...artConnect application on Android or iOS device 8 Press Start Scan button and connect to peripheral Note The device name is a characteristic and contains the name of the device This device name can be read by the central device to know the name of the device in order to differentiate the devices This is being set using at_ble_device_name_set API The device name is set by default when ble_device_in...

Page 36: ...ile settings The reason for this is that the mobile app stores the previous pairing information but the ATBTLC1000 device lost the previous pairing information due to RESET since it was stored on temporary storage RAM 10 The serial terminal must display the following log output window Figure 4 9 Console Log Window ATBTLC1000 Setting Handling of Pre Defined Service 2017 Microchip Technology Inc Tra...

Page 37: ...Ds are generated randomly Custom services characteristics are free to use any 128 bit UUID less than the base UUID There is no reserved space for vendors to use 16 bit or 32 bit UUIDs With this definition any temperature change is notified to the central The notify mechanism allows the central to know when the data changes When notify property of the Client Characteristic Configuration Descriptor ...

Page 38: ...e_list uint16_t included_service_count at_ble_characteristic_t charactristic_list uint16_t charactristic_count Description Defines a new primary service along with its included services and characteristics in ATBTLC1000 module Parameters Uuid In primary service UUID service_handle Out service handle is returned here included_service_list In array of included service references included_service_cou...

Page 39: ... define TEMPERATURE_CHAR_UUID 0x1b 0xc5 0xd5 0xa5 0x02 0x00 0xa6 0x87 0xe5 0x11 0x36 0x39 0xd8 0xba 0x5a 0xf0 2 Define the following environment service handler and characteristics variable as global in startup_template c file Services handlers at_ble_handle_t environment_service_handler at_ble_characteristic_t environment_service_characs 1 3 Add the following service initialization function custo...

Page 40: ...ccessfully sent over the air else printf n Assignment 4 1 Sending Notification over the air failed return AT_BLE_SUCCESS 6 Declare the following GATT server callback structure in startup_template c file This assignment uses two GATT callbacks static const ble_gatt_server_event_cb_t app_gatt_server_handle notification_confirmed custom_notification_confirmation_handler characteristic_changed custom_...

Page 41: ...s start_advertisement while true ble_event_task 9 Click to save the project Ctrl S 10 Compile the project by pressing button F7 11 Verify that no build error appears in the Atmel Studio output window Figure 5 3 Atmel Studio Output Window 12 Click to program the project binary on the SAM L21 Xplained Pro Ctrl Alt F5 13 Open the Microchip SmartConnect application on Android or iOS device 14 Connect ...

Page 42: ... as unknown service in the above figure as this service is not a SIG defined service Figure 5 5 General Information 16 Serial terminal client must display the following Log output ATBTLC1000 Setting up and Handling Custom Service 2017 Microchip Technology Inc Training Manual DS00002599A page 42 ...

Page 43: ...notify characteristic value is based on following interaction between the Host MCU and the ATBTLC1000 Figure 5 7 Characteristic Notification 5 2 1 Setting a Characteristic Value at_ble_characteristic_value_set Prototype at_ble_status_t at_ble_characteristic_value_set at_ble_handle_t handle uint8_t value uint16_t len Description Sets a characteristic value in ATBTLC1000 memory Parameters ATBTLC1000...

Page 44: ...ic 10 second timer for sending the notification Add the following code in previously defined custom_char_changed_app_event function Callback registered for char changed event static at_ble_status_t custom_char_changed_app_event void param at_ble_characteristic_changed_t char_changed_param_handle at_ble_characteristic_changed_t param if environment_service_characs 0 client_config_handle char_change...

Page 45: ...ag true timer_flag true timer_flag false send_temperature_notification 7 Click to save the project Ctrl S 8 Compile the project by pressing the button F7 9 Verify that no build error appears in Atmel Studio output window Figure 5 8 Atmel Studio Output Window 10 Click to program the project binary on the L21 Xplained XSTK 11 Open Microchip SmartConnect Application on Android or iOS device 12 Connec...

Page 46: ...ication Window 15 Serial terminal must display the following log output Figure 5 10 Log Output Window ATBTLC1000 Setting up and Handling Custom Service 2017 Microchip Technology Inc Training Manual DS00002599A page 46 ...

Page 47: ...ULL 0 Start Advertisement ble_status at_ble_adv_start AT_BLE_ADV_TYPE_UNDIRECTED AT_BLE_ADV_GEN_DISCOVERABLE NULL AT_BLE_ADV_FP_ANY 1600 655 0 if ble_status AT_BLE_SUCCESS printf n Failed to start advertisement Callback registered for AT_BLE_CONNECTED event static at_ble_status_t ble_connected_cb void param printf n Assignment 2 2 Application connected connected_flag true ALL_UNUSED param return A...

Page 48: ...zation button_init hw_timer_register_callback timer_callback_fn DBG_LOG Initializing BLE Application initialize the BLE chip and Set the Device Address ble_device_init NULL Register ATBTLC1000 Callbacks register_btlc1000_callbacks Initialize Device Info service in GATT printf n Assignment 3 2 Start Device Info Service dis_init_service dis_service_handler Define the primary service in the GATT serv...

Page 49: ...pe AT_BLE_UUID_128 memcpy environment_service_uuid uuid serv_uuid 16 Define temperature characteristic environment_service_characs 0 user_desc uint8_t Temperature environment_service_characs 0 user_desc_len 10 environment_service_characs 0 user_desc_max_len 10 environment_service_characs 0 uuid type AT_BLE_UUID_128 memcpy environment_service_characs 0 uuid uuid charac0_uuid 16 environment_service_...

Page 50: ...r when Registering ATBTLC1000 callbacks void start_advertisement void printf n Assignment 2 1 Start Advertisement Set advertisement data ble_status at_ble_adv_data_set adv_data sizeof adv_data NULL 0 Start Advertisement ble_status at_ble_adv_start AT_BLE_ADV_TYPE_UNDIRECTED AT_BLE_ADV_GEN_DISCOVERABLE NULL AT_BLE_ADV_FP_ANY 1600 655 0 if ble_status AT_BLE_SUCCESS printf n Failed to start advertise...

Page 51: ...bute data base ble_status at_ble_characteristic_value_set environment_service_characs 0 char_val_handle uint8_t Temperature_value sizeof Temperature_value ble_status at_ble_notification_send 0 environment_service_characs 0 char_val_handle if ble_status AT_BLE_SUCCESS printf fail to send temperature update notification int main void if SAMG55 SAM4S Initialize the SAM system sysclk_init board_init e...

Page 52: ...dvertising process start_advertisement while true ble_event_task if connected_flag true timer_flag true timer_flag false send_temperature_notification ATBTLC1000 Appendix B Software Solution Custom Service 2017 Microchip Technology Inc Training Manual DS00002599A page 52 ...

Page 53: ...8 Document Revision History Rev A 12 2017 Section Changes Document Initial release ATBTLC1000 Document Revision History 2017 Microchip Technology Inc Training Manual DS00002599A page 53 ...

Page 54: ...nd follow the registration instructions Customer Support Users of Microchip products can receive assistance through several channels Distributor or Representative Local Sales Office Field Application Engineer FAE Technical Support Customers should contact their distributor representative or Field Application Engineer FAE for support Local sales offices are also available to help customers A listin...

Page 55: ...ryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logo Kleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLAB OptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM BA SpyNIC SST SST Logo SuperFlash tinyAVR UNI O and XMEGA are registered trademarks of Microchip Technology Incorporated in the U S A and other countries ClockWorks The Emb...

Page 56: ...ties in Chandler and Tempe Arizona Gresham Oregon and design centers in California and India The Company s quality system processes and procedures are for its PIC MCUs and dsPIC DSCs KEELOQ code hopping devices Serial EEPROMs microperipherals nonvolatile memory and analog products In addition Microchip s quality system for the design and manufacture of development systems is ISO 9001 2000 certifie...

Page 57: ... China Xiamen Tel 86 592 2388138 China Zhuhai Tel 86 756 3210040 India Bangalore Tel 91 80 3090 4444 India New Delhi Tel 91 11 4160 8631 India Pune Tel 91 20 4121 0141 Japan Osaka Tel 81 6 6152 7160 Japan Tokyo Tel 81 3 6880 3770 Korea Daegu Tel 82 53 744 4301 Korea Seoul Tel 82 2 554 7200 Malaysia Kuala Lumpur Tel 60 3 7651 7906 Malaysia Penang Tel 60 4 227 8870 Philippines Manila Tel 63 2 634 90...

Reviews: