中级
20 分钟

使用WIRL-PRO2和ATmega1284P将Wirepas Mesh无线连接堆栈集成到您的应用中

Wirepas Click 立刻行动!

Wirepas Click with EasyAVR v7

已发布 6月 27, 2024

点击板

Wirepas Click

开发板

EasyAVR v7

编译器

NECTO Studio

微控制器单元

ATmega1284P

您的网关可以创建坚固的、自愈的和节能的网状网络,适用于智能照明、资产追踪等应用!

A

A

硬件概览

它是如何工作的?

Wirepas Click 基于 Würth Elektronik 的 WIRL-PRO2 Thetis-I,这是一款带有 Wirepas Mesh 协议的无线电模块。该模块旨在集成到基于 Wirepas 的路由网络中,用于设备或节点之间的无线通信。该模块在全球可用的免许可 2.4 GHz 频段内安全可靠地传输数据,具有认证和加密机制。WIRL-PRO2 Thetis-I 模块具有与 nano-SIM 卡相当的小尺寸(8 mm x 12 mm),包括板载 PCB 天线,使其非常适合小型设计。该模块工作在 2402 到 2480MHz 的频率范围内,数据速率高达 1Mbps。它基于 Nordic 

Semiconductor 的 32 位 ARM Cortex-M4 微控制器 nRF52840,配有 1MB 闪存和 256KB RAM。它具有印刷天线和智能天线配置(2 合 1 模块),允许高达 +6dBm 的发射功率和 -92dBm 的灵敏度。通过连接到板载 N.FL 连接器的外部天线,连接性能可以更好。由于其非常低的功耗,Wirepas Click 可以作为信标使用。为此,它配备了一个备用电池。此外,还有两个用户可配置的指示 LED,LED1 和 LED2(蓝色和绿色)。此外,Wirepas Click 还配备了一个未焊接的调试头,用于与 Wirepas 微控制器进行直接

通信。Wirepas Click 使用标准的 2 线 UART 接口与主 MCU 通信,支持 115200bps 的比特率。您可以通过 RST 引脚重置设备。DIN 引脚用于观察数据流,当处于低电平逻辑状态时,它是指向主 MCU 的数据指示。此 Click board™ 只能在 3.3V 逻辑电压水平下运行。使用具有不同逻辑电平的 MCU 之前,板必须进行适当的逻辑电压水平转换。此外,这款 Click board™ 配备了包含易于使用的功能和示例代码的库,可用于进一步开发。

Wirepas Click hardware overview image

功能概述

开发板

EasyAVR v7 是第七代AVR开发板,专为快速开发嵌入式应用的需求而设计。它支持广泛的16位AVR微控制器,来自Microchip,并具有一系列独特功能,如强大的板载mikroProg程序员和通过USB的在线电路调试器。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。EasyAVR v7 通过每个端口的四种不同连接器,比以往更高效地连接附件板、传感器和自定义电子产品。EasyAVR v7 开发板的每个部分

都包含了使同一板块运行最高效的必要组件。一个集成的mikroProg,一个快速的USB 2.0程序员,带有mikroICD硬件在线电路调试器,提供许多有价值的编 程/调试选项和与Mikroe软件环境的无缝集成。除此之外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括外部12V电源供应,7-12V交流或9-15V直流通过DC连接器/螺丝端子,以及通过USB Type-B(USB-B)连接器的电源。通信选项如USB-UART和RS-232也包括在内,与

广受好评的mikroBUS™标准、三种显示选项(7段、图形和基于字符的LCD)和几种不同的DIP插座一起,覆盖了广泛的16位AVR MCU。EasyAVR v7 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyAVR v7 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

AVR

MCU 内存 (KB)

128

硅供应商

Microchip

引脚数

40

RAM (字节)

16384

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PA6
RST
ID COMM
PA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Data Indication
PD2
INT
UART TX
PD1
TX
UART RX
PD0
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Wirepas Click Schematic schematic

一步一步来

项目组装

EasyAVR v7 front image hardware assembly

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

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
EasyAVR v7 Access DIP MB 1 - 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
EasyPIC PRO v7a Display Selection Necto Step 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”替换为要显示的参数。

软件支持

库描述

该库包含 Wirepas Click 驱动程序的 API。

关键功能:

  • wirepas_send_command - Wirepas 发送命令功能。

  • wirepas_write_csap_attribute - Wirepas 写入 CSAP 属性功能。

  • wirepas_send_data - Wirepas 发送数据功能。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Wirepas Click Example.
 *
 * # Description
 * This example demonstrates the use of Wirepas click board by processing
 * the incoming data and displaying them on the USB UART in sink mode, and sending data to 
 * the sinks in router mode.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration, setting device mode, node,
 * net and channel addresses, and starting stack.
 *
 * ## Application Task
 * Router mode - Sending data to the sinks at the same network.
 * Sink mode - Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - err_t wirepas_get_resp ( wirepas_t *ctx )
 *
 * @note
 * For the best experience use two clicks in sink mode and one in router.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "wirepas.h"

#define PROCESS_BUFFER_SIZE 200
#define TX_DATA             "Wirepas Click"

#define MULTI_SINK_MODE     // Comment out this macro to place device into single sink mode.

/**
* @brief Wirepas node addresses.
 * @details Specified setting for node addresses of Wirepas Click driver.
 */
#define ROUTER_NODE_ADDRESS         0x01
#define SINK_1_NODE_ADDRESS         0x02
#define SINK_2_NODE_ADDRESS         0x03
#define NET_ADDRESS                 0x01
#define CHANNEL_ADDRESS             0x01

#define NODE_ADDRESS                ROUTER_NODE_ADDRESS    /* Change the value of this macro to change 
                                                              node address, each node should have a unique address */

static wirepas_t wirepas;
static log_t logger;
uint8_t frame_id = 0;
wirepas_sink_data sink_1;
wirepas_sink_data sink_2;

/**
 * @brief Wirepas get response function.
 * @details This function is used to get response from the device. 
 * @param[in] ctx : Click context object.
 * See #wirepas_t object definition for detailed explanation.
 * @return @li @c  >=0 - Success,
 *         @li @c   <0 - Error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
err_t wirepas_get_resp ( wirepas_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    wirepas_cfg_t wirepas_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 " );

    // Click initialization.
    wirepas_cfg_setup( &wirepas_cfg );
    WIREPAS_MAP_MIKROBUS( wirepas_cfg, MIKROBUS_1 );
    if ( UART_ERROR == wirepas_init( &wirepas, &wirepas_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    wirepas_default_cfg ( &wirepas );
   
    uint8_t tmp_data[ 1 ] = { 0x00 };
    
    Delay_ms( 1000 );
    wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
    frame_id++;
   
    Delay_ms( 1000 );
    wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
    frame_id++;
    
    Delay_ms( 1000 );
    log_printf( &logger, " Wirepas stack stop request: \n" );
    wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_STOP_REQUEST, frame_id, 0x00, tmp_data );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    log_printf( &logger, " Wirepas factory reset request: \n" );
    wirepas_send_command( &wirepas, WIREPAS_CSAP_FACTORY_RESET_REQUEST, frame_id, strlen( WIREPAS_FACTORY_RESET_CODE ), WIREPAS_FACTORY_RESET_CODE );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
    frame_id++;
    
    Delay_ms( 1000 );
    wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
    frame_id++;
    
    Delay_ms( 1000 );
    log_printf( &logger, " Set node address: \n" );
    wirepas_set_node_address( &wirepas, frame_id, NODE_ADDRESS );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    log_printf( &logger, " Set net address: \n" );
    wirepas_set_net_address( &wirepas, frame_id, NET_ADDRESS );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    log_printf( &logger, " Set channel address: \n" );
    uint8_t channel_net = CHANNEL_ADDRESS;
    wirepas_write_csap_attribute( &wirepas, frame_id, WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL, 1, &channel_net );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    log_printf( &logger, " Set role: \n" );
    uint8_t role;
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )
    role = WIREPAS_ROUTER_NODE_MODE;
#else
    role = WIREPAS_SINK_NODE_MODE;
#endif
    wirepas_write_csap_attribute( &wirepas, frame_id, WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE, 1, &role );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    Delay_ms( 1000 );
    log_printf( &logger, " Wirepas Stack start request: \n" ); 
    tmp_data[ 0 ] = 0x01;
    wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_START_REQUEST, frame_id, 0x01, tmp_data );
    frame_id++;
    wirepas_get_resp( &wirepas );
    
    uint8_t data_buf[ WIREPAS_RX_DRV_BUFFER_SIZE ] = { 0 };
    
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )
    Delay_ms( 1000 );
    wirepas_poll_indication( &wirepas, frame_id, data_buf, NULL );
    frame_id++;
        
    sink_1.pduid = 0x00;
    sink_1.source_endpoint = 0x01;
    sink_1.destination_addr = SINK_1_NODE_ADDRESS;
    sink_1.destination_endpoint = 0x01;
    #if defined MULTI_SINK_MODE
        sink_2.pduid = 0x00;
        sink_2.source_endpoint = 0x01;
        sink_2.destination_addr = SINK_2_NODE_ADDRESS;
        sink_2.destination_endpoint = 0x01;
    #endif
#else
    uint8_t data_rd = 0;
    while ( 0 == data_rd )
    {
        wirepas_poll_indication( &wirepas, frame_id, data_buf, &data_rd );
        frame_id++;
        Delay_ms( 1000 );
    }
#endif
    Delay_ms( 100 );
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )
    log_printf( &logger, " Sending data to the first Sink node: \n" );
    wirepas_send_data ( &wirepas, frame_id, sink_1, 0x01, strlen( TX_DATA ), TX_DATA );
    frame_id++;
    wirepas_get_resp( &wirepas );
    Delay_ms( 5000 );
    
    #if defined MULTI_SINK_MODE
        log_printf( &logger, " Sending data to the second Sink node: \n" );
        wirepas_send_data ( &wirepas, frame_id, sink_2, 0x01, strlen( TX_DATA ), TX_DATA );
        frame_id++;
        wirepas_get_resp( &wirepas );
        Delay_ms( 5000 );
    #endif
#else
    uint8_t data_buf[ WIREPAS_RX_DRV_BUFFER_SIZE ] = { 0 };
    uint8_t data_rdy = 0;
    err_t error = wirepas_poll_indication( &wirepas, frame_id, data_buf, &data_rdy );
    frame_id++;
    if ( 1 == data_rdy )
    {
        log_printf( &logger, "%s \r\n", data_buf );
    }
    Delay_ms( 2000 );
#endif
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

err_t wirepas_get_resp ( wirepas_t *ctx )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    
    Delay_ms( 1000 );
    rx_size = wirepas_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 )
    {       
        if ( 0 == rx_buf[ 4 ] )
        {
            log_printf( &logger, " Response OK \n" );
            return WIREPAS_OK;
        }
        else 
        {
            log_printf( &logger, " Response ERROR %d\n", rx_buf[ 4 ] );
            return WIREPAS_ERROR;
        }
        
    }
    
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

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