探索我们 ZigBee 无线电模块的潜力,该模块精心设计以节省电能,同时提供强大的无线连接,非常适合需要高效和可靠性的物联网应用。
A
A
硬件概览
它是如何工作的?
ZigBee Click 基于 ETRX357,这是一款低功耗 Zigbee 无线电模块,集成了许多先进外设的 2.4 GHz 收发器,由 Silicon Labs 提供。ZigBee 协议是一套用于短到中距离设备间无线连接的标准。它使用 IEEE 802.15.4 无线电规范在 2.4GHz 频段运行,并加上三个额外的网络、安全和应用层。该模块的独特之处在于它使用了网状网络架构,以桶链式将数据从一个节点传递到下一个节点,直到到达目的地。ETRX357 模块预装了一个独立的引导加载程序,支持通过 ZigBee Click 上的 FW 引脚进行空中引导加载和串行引导加载新固件。模块使用由简单 AT 命令组成的默认固件进行控制。定义模块功能并允许独立功能的参数保存在非易失性存储器中,组织在所谓的 S 寄存器中。
命令和响应通过 ETRX357 的串行端口作为 ASCII 文本传递,因此通常只需一个简单的终端应用程序即可。行业标准的串行线、JTAG 编程和调试接口以及标准的 ARM 系统调试组件有助于简化任何自定义软件开发。此外,几个 MAC 功能也在硬件中实现,以帮助保持 ZigBee 和 IEEE802.15.4 标准所施加的严格时间要求。该模块还能够通过外部主机控制充当协调器和信任中心。AT 风格命令行提供了设置和管理 Zigbee 网络所需的所有工具,允许轻松访问堆栈的低级功能。ZigBee Click 使用 UART 接口与 MCU 通信作为其默认通信协议,但也为用户提供了使用其他接口(如 SPI 和 I2C)的选项,如果用户希望配置模块并自行编写库。可以通过将标记为 COMM SEL 的
SMD 跳线定位到适当位置来选择 UART 和 I2C 之间的通信。请注意,所有跳线必须放置在同一侧,否则 Click board™ 可能会无响应。其他功能如复位和中断通过 mikroBUS™ 的 RST 和 INT 引脚提供和路由,串行 UART 连接 CTS 和 RTS 则通过 mikroBUS™ 的 CS 和 PWM 引脚路由。为了简化部署,Click board™ 配备了由 ZigBee 模块控制的 CMT-8540S-SMT 磁性蜂鸣器,用于声音信号和通知。您可以使用我们编译器支持的声音库创建不同的声音模式。信号频率决定声音的音调,占空比决定振幅(音量)。此 Click board™ 设计为仅在 3.3V 逻辑电平下运行。在使用具有不同逻辑电平的 MCU 之前,应进行适当的逻辑电压电平转换。
功能概述
开发板
Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE
mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口
来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。
微控制器概述
MCU卡片 / MCU

建筑
PIC32
MCU 内存 (KB)
2048
硅供应商
Microchip
引脚数
100
RAM (字节)
524288
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程。

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持
库描述
该库包含 ZigBee Click 驱动程序的 API。
关键功能:
zigbee_send_at
- 合并两个字符串并将其发送到设备的功能zigbee_resp
- 检查驱动程序缓冲区字符串的功能zigbee_set_pin_rst
- 设置 RST 引脚状态的功能
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief ZigBee Click Example.
*
* # Description
* This is an example that demonstrates the use of the ZigBee Click board.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initialization of driver, UART ISR and then configures device.
* Depending on previous selected device mode it creates new PAN network or joins to one.
*
* ## Application Task
* Host mode: Broadcasts message 'MikroE' every 3 seconds.
* User mode: Checks if something is received.
*
* ## Additional Function
* - void zigbee_clear_app_buf ( void ) - Clearing application buffer function.
* - void resp_wait ( zigbee_t *ctx ) - Function for waiting for complete response.
*
* @author Stefan Ilic
*
*/
#include "board.h"
#include "log.h"
#include "zigbee.h"
static zigbee_t zigbee;
static log_t logger;
uint8_t dev_mode;
uint8_t app_mode;
static char app_buf[ ZIGBEE_DEV_BUFFER_MAX ] = { 0 };
char AT_BCAST_MSG[ 15 ] = ":00,MikroE";
char AT_HOST_CFG1[ 10 ] = "00=6314";
char AT_HOST_CFG2[ 20 ] = "0A=0914;password";
char AT_HOST_CFG3[ 50 ] = "09=5A6967426565416C6C69616E63653039;password";
/**
* @brief ZigBee clearing application buffer.
* @details This function clears memory of application buffer and reset it's length and counter.
*/
void zigbee_clear_app_buf ( void );
/**
* @brief ZigBee wait response.
* @details This function is used for waiting for complete response.
*/
void resp_wait ( zigbee_t *ctx );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
zigbee_cfg_t zigbee_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
app_mode = ZIGBEE_APP_INIT;
dev_mode = ZIGBEE_DEV_USER;
// Click initialization.
zigbee_cfg_setup( &zigbee_cfg );
ZIGBEE_MAP_MIKROBUS( zigbee_cfg, MIKROBUS_1 );
if ( UART_ERROR == zigbee_init( &zigbee, &zigbee_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Restarting Device \r\n" );
zigbee_restart( &zigbee );
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT );
resp_wait( &zigbee );
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + DASSL \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_DASSL );
resp_wait( &zigbee );
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : ATZ \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_ATZ );
resp_wait( &zigbee );
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : ATI \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_ATI );
resp_wait( &zigbee );
log_printf( &logger, "------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + N \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_N );
resp_wait( &zigbee );
if ( ZIGBEE_DEV_HOST == dev_mode )
{
// Setting the device into host mode and creating a network for other devices to connect.
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + HOST CFG 1 \r\n", app_buf );
zigbee_send_at( &zigbee, ZIGBEE_CMD_ATS, &AT_HOST_CFG1[ 0 ] );
resp_wait( &zigbee );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + HOST CFG 2 \r\n", app_buf );
zigbee_send_at( &zigbee, ZIGBEE_CMD_ATS, &AT_HOST_CFG2[ 0 ] );
resp_wait( &zigbee );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + HOST CFG 3 \r\n", app_buf );
zigbee_send_at( &zigbee, ZIGBEE_CMD_ATS, &AT_HOST_CFG3[ 0 ] );
resp_wait( &zigbee );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + EN \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_EN );
resp_wait( &zigbee );
}
else if ( ZIGBEE_DEV_USER == dev_mode )
{
// Setting the device into user mode and joining the existing network.
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + JN \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_JN );
resp_wait( &zigbee );
}
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + IDREQ \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_IDREQ );
resp_wait( &zigbee );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
log_printf( &logger, " Sending command : AT + N \r\n", app_buf );
zigbee_send_cmd( &zigbee, ZIGBEE_CMD_AT_N );
resp_wait( &zigbee );
Delay_ms( 1000 );
app_mode = ZIGBEE_APP_TASK;
log_info( &logger, " Application Task " );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
}
void application_task ( void )
{
if ( ZIGBEE_DEV_HOST == dev_mode )
{
log_printf( &logger, "-----------------------------------\r\n", app_buf );
zigbee_send_at( &zigbee, ZIGBEE_CMD_AT_BCAST, &AT_BCAST_MSG[ 0 ] );
resp_wait( &zigbee );
Delay_ms( 3000 );
}
else if ( ZIGBEE_DEV_USER == dev_mode )
{
resp_wait( &zigbee );
log_printf( &logger, "-----------------------------------\r\n", app_buf );
}
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
void zigbee_clear_app_buf ( void )
{
memset( app_buf, 0, ZIGBEE_DEV_BUFFER_MAX );
}
void resp_wait ( zigbee_t *ctx )
{
uint8_t resp_flag;
for ( ; ; )
{
zigbee_generic_read( &zigbee, app_buf, ZIGBEE_DEV_BUFFER_MAX );
Delay_ms( 50 );
resp_flag = zigbee_resp( ctx, app_buf );
if ( ( ZIGBEE_APP_TASK == app_mode ) && ( ZIGBEE_DEV_USER == dev_mode ) )
{
if ( ( ZIGBEE_OP_WAIT != resp_flag ) )
{
log_printf( &logger, " %s ", app_buf );
zigbee_clear_app_buf( );
}
}
else
{
if ( ( ZIGBEE_OP_OK == resp_flag ) || ( ZIGBEE_OP_ERROR == resp_flag ) )
{
log_printf( &logger, "%s", app_buf );
log_printf( &logger, "\r\n" );
zigbee_clear_app_buf( );
break;
}
}
}
}
// ------------------------------------------------------------------------ END