3.18 Bluetooth® Low Energy ANPC Application
This section helps users to enable the BLE Alert Notification Profile Client (ANPC) on the Curiosity board using the MCC. In this application example, BLE ANPC functions is in the Peripheral role and is paired with the BLE ANPS application which functions in the Central role.
Users can either choose to run the precompiled application example .hex
file on the Curiosity Board and experience the demo or go through the steps involved in
developing this application from scratch.
These examples are incrementally structured upon one another. Recommendation is to follow the examples in order,by learning the basic concepts first and then progressing to the more advanced topics.
Recommended Reading
- BLE Software Specification
- Getting Started with WME Bluetooth Low Energy Applications
Hardware Requirement
Tool | Quantity |
---|---|
Curiosity Board | 3 |
Micro USB cable | 2 |
Software Requirement
- MPLAB X IPE: For programming the precompiled hex file.
- MPLAB X IDE: For programming the application example.
- Teraterm: Terminal Emulator for displaying UART output.
Programming the Precompiled Hex File or Application Example
Programming the .hex
File using MPLAB X IPE
- Import and program the
precompiled
.hex
file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anpc_app\hex\
” - Import and program the
precompiled
.hex
file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anps_app\hex\
” - For more information on the
programming steps, refer to the Programming a Device in MPLAB IPE.Note: Users must choose the correct device and tool information.
Programming the Application using MPLAB X IDE
- Follow the steps mentioned in Running a Precompiled Example
- Open and program the application
example “
ble_anpc_app_xxxx.X
where xxxx refer to device (for example: WBZ451, project file:ble_anpc_app_wbz451.X
) located in “<Harmony Content Path>\wireless_apps_ble\apps\ble_anpc_app\firmware
” using MPLAB X IDE . - Open and program the application
example “
ble_anps_app_xxxx.X
where xxxx refer to device (for example: WBZ451, project file:ble_anps_app_wbz451.X
) located in “<Harmony Content Path>\wireless_apps_ble\apps\ble_anps_app\firmware
” using MPLAB X IDE .
For more details on finding the Harmony content path, refer to Installing the MCC Plugin.
Demo Description
- Refer BLE ANPC Demo Description.Note: The BLE connection status will be indicated by the green color of the RGB LED.
Developing this Application from Scratch using MCC
This section explains the steps required by a user to develop this application example from scratch using MCC
- Create a new MCC Harmony Project by selecting the device. For more details, refer to Creating a New MCC Harmony Project.
- Launch the MPLAB Code
Configurator from the toolbar as illustrated below. The project graph will open
with the default components.
Figure 3-235. MCC - In the Device Resources window, expand Libraries > Harmony >
Wireless > Application Services. Then, click the Plus
Symbol to add the Alert Notification App Service Component to the
project graph.
Figure 3-236. Alert Notification App Service - All BLE ANPC related components will be added into the project graph. Accept dependencies or satisfiers by selecting Yes
- To enable digital and communication interfaces, refer to Enabling Digital Input/Output and Communication Interfaces Through System Hardware Definition (SHD) component in Getting Started with WME Bluetooth Low Energy Applications from Related Links.
- Change the CONSOLE
Component settings as illustrated in the following figure.
Figure 3-237. Console Configuration - Change the SERCOM0
Component settings as illustrated in the following figure.
Figure 3-238. SERCOM0 Configuration - Change FreeRTOS component
settings as illustrated in the following figure. For more details, refer to the
link Configuring FreeRTOS from Getting Started with WME Bluetooth Low
Energy Applications from Related Links.
Figure 3-239. FreeRTOS Configuration - For WBZ451
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
Figure 3-240. Project Graph - Verify the
WBZ451-CURIOSITY Configuration for LED initialization as
illustrated in the following figure.
Figure 3-241. WBZ451-CURIOSITY Configuration
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
- For WBZ351
- Verify if the project
graph window has all the expected components. as illustrated in the
following figure
Figure 3-242. Project Graph - Verify the
WBZ351-CURIOSITY Configuration for LED initialization as
illustrated in the following figure.
Figure 3-243. WBZ351-CURIOSITY Configuration
- Verify if the project
graph window has all the expected components. as illustrated in the
following figure
-
Select the Apple Notification App Service component. In the Configuration Options, the Enable Client Role option will be enabled by default. If it is not enabled, ensure to enable the option. Additionally, ensure that the Enable App Code Generation” option is also enabled.
Figure 3-244. Apple Notification App Service Component Figure 3-245. Apple Notification App Service Configuration - Enabling the client role option
in Alert Notification App Service component will configure BLE
Stack component . Additionally, selecting the Enable App Code
Generation option will generate the necessary application files related
to the service during the code generation process. Verify the BLE Stack
configuration.
Figure 3-246. BLE Stack Configuration Figure 3-247. BLE Stack Configuration
Generating a Code
For more details on code generation, refer to the MPLAB Code Configurator (MCC) Code Generation.
Files Containing User Application Code
Source Files | Usage |
---|---|
app.c | Application State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations |
app_ble_callbacks.c | All the event functions related to GAP, GATT, SMP and L2CAP events that user can use or modify . |
app_anpc_callbacks.c | All the event functions related to ANPC event handles that user can use or modify. |
app_utility.c | Contains generic utility functions that serve the purpose of providing reusable, common functionalities that can be applied across various parts of a program. |
app.c
is auto generated and has
a state machine based application code sample. Users can use this template to
develop their application. Main application logic is implemented in void
APP_Tasks()
function.app.c
app.c
Firmware FSM (Finite State Machine)
This application firmware implements an ANPC on the Curiosity board.
APP_ANPC_STATE_IDLE
: application remains in the Idle modeAPP_ANPC_STATE_ADV
: application is waiting for a new connection withintimeout_adv
seconds.APP_ANPC_STATE_WITH_BOND_ADV
: application is waiting for a reconnection withintimeout_with_bond_adv
seconds.APP_ANPC_STATE_CONN
: application is prepared to send commands/receive notifications.Figure 3-251. Finite State Machine
Variable |
Value |
Description |
---|---|---|
|
60 seconds |
The timeout of advertising without bond |
|
30 seconds |
The timeout of advertising with bond |
Firmware State |
LED behavior |
---|---|
APP_ANPC_STATE_IDLE |
All LEDs are OFF |
APP_ANPC_STATE_ADV |
Blue LED flashes once every 3 seconds. (ON: 50 ms, OFF: 2950 ms) |
APP_ANPC_STATE_WITH_BOND_ADV |
Blue LED flashes twice every 3 seconds. (ON: 50 ms, OFF: 50 ms) |
APP_ANPC_STATE_CONN |
Blue LED flashes twice every 1.5 seconds (ON: 50 ms, OFF: 150 ms) |