中级
20 分钟

使用ETRX357和PIC18F25K80创建您自己的节能物联网网络网关

用ZigBee的魔力点燃您的物联网梦想!

ZigBee Click with EasyPIC v8

已发布 6月 25, 2024

点击板

ZigBee Click

开发板

EasyPIC v8

编译器

NECTO Studio

微控制器单元

PIC18F25K80

探索我们 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 之前,应进行适当的逻辑电压电平转换。

ZigBee Click hardware overview image

功能概述

开发板

EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。

EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和

基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyPIC v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

32

硅供应商

Microchip

引脚数

28

RAM (字节)

3648

使用的MCU引脚

mikroBUS™映射器

FW Update
RA3
AN
Reset
RA0
RST
UART RTS
RA5
CS
SPI Clock
RC3
SCK
SPI Data OUT
RC4
MISO
SPI Data IN
RC5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART CTS / SPI Chip Select
RC1
PWM
Interrupt
RB1
INT
UART TX
RC6
TX
UART RX
RC7
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
NC
NC
5V
Ground
GND
GND
2

“仔细看看!”

Click board™ 原理图

ZigBee Click Schematic schematic

一步一步来

项目组装

EasyPIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyPIC v8作为您的开发板开始。

EasyPIC v8 front image hardware assembly
Rotary B 2 Click front image hardware assembly
MCU DIP 28 hardware assembly
EasyPIC v8 28pin-DIP - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

实时跟踪您的结果

应用程序输出

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

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。