This information applies to the following SoCs: nRF52833 and nRF52840.
Applications demonstrating the Bluetooth peripheral functionality can be extended by adding Zigbee protocol support to them, to achieve dynamic multiprotocol functionality. See the sections on this page for the list of required changes.
For reference, see <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus
, which is a modified version of the ble_app_uart
example.
For more information on multiprotocol operation, refer to the Multiprotocol support with BLE/Bluetooth support section.
Restrictions
Zigbee hardware requirements must be met in transformed examples. Refer to the Zigbee memory layout and requirements page.
Modifying sdk_config.h
Modify the sdk_config.h file by implementing the following edits:
- Add the following settings to
sdk_config.h
to configure the Zigbee stack:
#ifndef ZB_ERROR_TO_STRING_ENABLED
#define ZB_ERROR_TO_STRING_ENABLED 0
#endif
#ifndef ZB_ERROR_PRINT_TO_LOG
#define ZB_ERROR_PRINT_TO_LOG 0
#endif
#ifndef ZIGBEE_CHANNEL
#define ZIGBEE_CHANNEL 16
#endif
#ifndef ZIGBEE_TRACE_LEVEL
#define ZIGBEE_TRACE_LEVEL 0
#endif
#ifndef ZIGBEE_TRACE_MASK
#define ZIGBEE_TRACE_MASK 0x0000
#endif
#ifndef ZIGBEE_TIMER_INSTANCE
#define ZIGBEE_TIMER_INSTANCE NRF_DRV_TIMER_INSTANCE(3)
#endif
- Modify the following settings, if they appear in
sdk_config.h:
#define TIMER3_ENABLED 1
#define FDS_VIRTUAL_PAGES_RESERVED 0x30
- Add the following define to the compiler options:
Libraries
The nRF5 SDK for Thread and Zigbee provides precompiled Zigbee libraries that must be added to the project.
For a Zigbee router or coordinator devicem, use the following set of libraries:
/external/zboss/lib/<TOOLCHAIN>/libzboss.a
/external/zboss/lib/<TOOLCHAIN>/nrf_radio_driver_softdevice.a
For the Zigbee end device, use the following set of libraries:
/external/zboss/lib/<TOOLCHAIN>/libzboss.ed.a
/external/zboss/lib/<TOOLCHAIN>/nrf_radio_driver_softdevice.a
Additionally, add one of the following defines to the compiler options, to indicate the device type:
- ZB_ROUTER_ROLE
- ZB_ED_ROLE
There is no need to add the additional define for Zigbee coordinator device.
Modifying GCC Makefile
Complete the following edits in the GCC Makefile:
- Add the following snippet to the makefile of a BLE application; it replaces libzboss library with the selected variant:
# Zigbee stack libraries
LIB_FILES += \
$(SDK_ROOT)/external/zboss/lib/gcc/libzboss.a \
$(SDK_ROOT)/external/zboss/lib/gcc/nrf_radio_driver_softdevice.a \
- Add the following snippet inside of the SRC_FILES section to compile all platform-dependent source files required by Zigbee stack (edit the SoC number if you use nRF52833):
$(SDK_ROOT)/external/zboss/zb_error/zb_error_to_string.c \
$(SDK_ROOT)/external/zboss/osif/zb_nrf52840_common.c \
$(SDK_ROOT)/external/zboss/osif/zb_nrf52840_nrf_logger.c \
$(SDK_ROOT)/external/zboss/osif/zb_nrf52840_nvram.c \
$(SDK_ROOT)/external/zboss/osif/zb_nrf52840_sdk_config_deps.c \
$(SDK_ROOT)/external/zboss/osif/zb_nrf52840_timer.c \
- To use the Zigbee API, add header include paths inside of the INC_FOLDERS section:
$(SDK_ROOT)/external/zboss/osif \
$(SDK_ROOT)/external/zboss/zb_error \
$(SDK_ROOT)/external/zboss/include \
$(SDK_ROOT)/external/zboss/include/ha \
$(SDK_ROOT)/external/zboss/include/osif \
$(SDK_ROOT)/external/zboss/include/zcl \
$(SDK_ROOT)/external/zboss/include/zll \
For reference, see the makefile that already supports dynamic Zigbee/BLE: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus\pca10056\s140\armgcc\Makefile
.
Modifying IAR project
Complete the following edits in the IAR project:
- Add libraries under the IAR compiler:
- Click Project -> Add Files.
- Choose the file type of Library/Object Files.
- Navigate to
\external\zboss\lib\iar
.
- Select all needed libraries according to the section above.
- Add all platform-dependent source files, required by Zigbee stack.
- Add source files under the IAR compiler:
- Click Project -> Add Files.
- Choose the file type of Source Files.
- Navigate to
\external\zboss\osif
.
- Select the following files (edit the SoC number if you use nRF52833):
zb_nrf52840_common.c
zb_nrf52840_nrf_logger.c
zb_nrf52840_nvram.c
zb_nrf52840_sdk_config_deps.c
zb_nrf52840_timer.c
- Add the Zigbee stack error parsing module, located under
\external\zboss\zb_error
:
- To use the Zigbee API, add header include paths:
- Click Project -> Options.
- Choose the C/C++ Compiler section.
- In the Preprocessor tab, navigate to the Additional include directory section.
- Add the path to the
\external\zboss\osif
and the \external\zboss\include
folder, with all subdirectories inside it.
After the folder path is added, depending on your project location, the following records are visible.
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\zb_error
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\osif
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\include
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\include\ha
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\include\osif
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\include\zcl
$PROJ_DIR$\..\..\..\..\..\..\..\..\external\zboss\include\zll
For reference, see the IAR project that already supports dynamic Zigbee/BLE: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus\ble_zigbee_dynamic_light_switch_nus.eww
Modifying main.c
Complete the following steps in the main.c
file:
- At the top of the
main.c
file, add all necessary includes, depending on the Zigbee use case. #include "zboss_api.h"
#include "zb_error_handler.h"
- After the section which contains defines and static variables, add the following lines:
#define IEEE_CHANNEL_MASK (1l << ZIGBEE_CHANNEL)
#define ERASE_PERSISTENT_CONFIG ZB_FALSE
- Define all clusters and endpoints that should be present on your Zigbee device:
#define LIGHT_SWITCH_ENDPOINT 1
ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(identify_attr_list, &m_attr_identify_time);
basic_attr_list,
identify_attr_list);
LIGHT_SWITCH_ENDPOINT,
dimmer_switch_clusters);
- Add the function for initializing the Zigbee protocol. Note that it depends on your use case.
static void zigbee_init(void)
{
uint64_t factoryAddress;
factoryAddress = (uint64_t)NRF_FICR->DEVICEID[0] << 32;
factoryAddress |= NRF_FICR->DEVICEID[1];
memcpy(m_ieee_addr, &factoryAddress, sizeof(factoryAddress));
UNUSED_RETURN_VALUE(ZB_MEMSET(&m_device_ctx, 0, sizeof(light_switch_ctx_t)));
ZB_ERROR_CHECK(zb_err_code);
}
For reference on how to add the dimmable switch functionality (for example) see: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus\main.c
- Add the function for handling Zigbee events:
{
switch(sig)
{
if (status == RET_OK)
{
NRF_LOG_INFO("Joined network successfully");
}
else
{
NRF_LOG_ERROR("Failed to join network. Status: %d", status);
}
break;
if (status != RET_OK)
{
NRF_LOG_WARNING("Production config is not present or invalid");
}
break;
default:
NRF_LOG_INFO("Unhandled signal %d. Status: %d", sig, status);
}
if (param)
{
ZB_FREE_BUF_BY_REF(param);
}
}
- Call the
zigbee_init
function inside of the application main function. - Note
- This function must be called after the SoftDevice has been initialized.
- Add the following snippet inside the main loop of your application:
For more information about defining and implementing Zigbee device, see Programming principles.
Parameters of Timeslot API
Timeslot API has been tested with a set of default parameters on the nRF52840 Development Kit. These parameters are preset when the 802.15.4 radio driver is initialized.
However, in case your application needs to use a different set of parameters for the Timeslot API, the 802.15.4 radio driver exposes the nrf_raal_softdevice_config()
function to change the default Timeslot API parameters.
One of the parameters is the crystal accuracy in PPM units, which by default is set to 25 PPM. The application may use the nrf_raal_softdevice_config()
function to change the PPM value of the currently used crystal.
Instructions on how to select other parameters for specific applications will be available in future releases of the nRF5 SDK for Thread and Zigbee.