确保智能电网设备之间的无缝连接。
A
A
硬件概览
它是如何工作的?
Wireless SUN Click基于Rohm Semiconductor的BP35C5,这是一款超紧凑的Wi-SUN FAN兼容无线通信模块。BP35C5已通过ARIB和FCC的无线电法律认证,因此可以在920MHz频率下使用,采用二进制GFSK调制方法,在日本和美国使用。它还包括一个Wi-SUN软件堆栈,可以在不同的传输模式(20、10或1mW)下进行高效操作。此外,由于它具有内置的安全功能,并支持模块端的通信加密和安全密钥更新,因此可以在不需要复杂控制的情况下有效地进行安全通信。正如之前提到的,该模块使用Wi-SUN FAN(Field Area Network)网状网络协议,由一个称为边界路由器的父中继器、一个称
为路由器的中继器和一个称为叶子的终端组成。由于其中继功能(跳频功能),它可以覆盖广泛的范围。因此,可以建立最多1000个单位的网状网络-支持信道跳频的多跳网状网络,具有通过自动路由(能够自动切换路由)避免无线干扰的能力。这个特点使它非常适合社会基础设施应用,如交通和路灯,建立覆盖整个城市的远程管理系统。该Click board™使用UART接口与MCU通信,具有常用的UART RX、TX和硬件流控制引脚UART CTS和RTS(发送和接收)。默认情况下,它以115200 bps的速度与主机MCU进行数据传输和交换。此外,额外的板载测试点TP1和TP2通过串行线调试接口为用户提供了完整的
调试和编程功能,可通过SWD接口引脚(SWCK和SWD)进行编程和调试。除了适当的接口,该Click board™还具有一些其他特性。一个连接到mikroBUS™插座的RST引脚的复位按钮将模块置于复位状态,而标有STATUS的蓝色LED指示灯表示广播传输状态的LED指示灯。该Click board™只能在3.3V逻辑电压电平下操作。在使用不同逻辑电平的MCU之前,必须通过适当的逻辑电压电平转换进行。然而,该Click board™配备了一个包含函数和示例代码的库,可供进一步开发时参考。
功能概述
开发板
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板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
AVR
MCU 内存 (KB)
128
硅供应商
Microchip
引脚数
40
RAM (字节)
16384
你完善了我!
配件
使用的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”替换为要显示的参数。

软件支持
库描述
该库包含 Wireless SUN Click 驱动程序的 API。
关键功能:
wirelesssun_send_cmd
- 该函数向点击模块发送指定的命令。wirelesssun_send_cmd_with_parameter
- 该函数向点击模块发送指定的命令,并附加所需的参数。wirelesssun_generic_read
- 该函数通过UART串行接口读取所需数量的数据字节。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief Wireless SUN Click Example.
*
* # Description
* This example demonstrates the use of Wireless SUN click board by showing
* the communication between the two click boards configured as BORDER and ROUTER.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and configures the click board by performing a hardware reset
* and a clear parameters feature, and setting the device network name, device role to
* BORDER or ROUTER depending on the application mode. In the end, it saves settings and
* reboots device.
*
* ## Application Task
* Depending on the selected application mode, it reads all the received data and parses
* the received TCP/UDP messages (BORDER mode) or waits for the connection, reads the parent
* global address, and then starts sending a desired TCP/UDP messages to the parent every
* 3 seconds (ROUTER mode).
*
* ## Additional Function
* - static void wirelesssun_clear_app_buf ( void )
* - static err_t wirelesssun_process ( void )
* - static err_t wirelesssun_rsp_check ( void )
* - static void wirelesssun_wait_for_connection ( void )
* - static void wirelesssun_get_parent_gbl_address ( uint8_t *gbl_addr )
*
* @note
* By default, the BORDER application mode is selected. comment out the DEMO_APP_BORDER macro
* definition in order to switch the application mode to ROUTER.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "wirelesssun.h"
#include "conversions.h"
// Comment out the line below in order to switch the application mode to ROUTER
#define DEMO_APP_BORDER
// Device network name.
#define DEVICE_NETWORK_NAME "\"Wireless SUN click\""
// Text message to send in the transmitter application mode
#define DEMO_TEXT_MESSAGE "MikroE - Wireless SUN click board"
#define PROCESS_BUFFER_SIZE 600
static wirelesssun_t wirelesssun;
static log_t logger;
static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;
/**
* @brief Wireless SUN clearing application buffer.
* @details This function clears memory of application buffer and reset its length and counter.
* @return None.
* @note None.
*/
static void wirelesssun_clear_app_buf ( void );
/**
* @brief Wireless SUN data reading function.
* @details This function reads data from device and concatenates data to application buffer.
* @return @li @c 0 - Read some data.
* @li @c -1 - Nothing is read.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t wirelesssun_process ( void );
/**
* @brief Response check.
* @details This function checks for response and
* returns the status of response.
* @return @li @c 0 - OK response.
* @li @c -1 - Nothing is read.
* @li @c -2 - Timeout error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t wirelesssun_rsp_check ( void );
/**
* @brief Wireless SUN wait for connection function.
* @details This function waits for the ROUTER connection - FAN join state 5(OPERATIONAL).
* @return None.
* @note None.
*/
static void wirelesssun_wait_for_connection ( void );
/**
* @brief Wireless SUN get parent gbl address function.
* @details This function reads the parent global address after the ROUTER connects to the BORDER.
* @return None.
* @note None.
*/
static void wirelesssun_get_parent_gbl_address ( uint8_t *gbl_addr );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
wirelesssun_cfg_t wirelesssun_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.
wirelesssun_cfg_setup( &wirelesssun_cfg );
WIRELESSSUN_MAP_MIKROBUS( wirelesssun_cfg, MIKROBUS_1 );
if ( UART_ERROR == wirelesssun_init( &wirelesssun, &wirelesssun_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
app_buf_len = 0;
app_buf_cnt = 0;
log_printf( &logger, "\r\n - Reset device -\r\n" );
wirelesssun_reset_device ( &wirelesssun );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Clear parameters and reboot device -\r\n" );
wirelesssun_send_cmd ( &wirelesssun, WIRELESSSUN_CMD_CLRST );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Set device name -\r\n" );
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_NETNAME, DEVICE_NETWORK_NAME );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Set device starting role -\r\n" );
#ifdef DEMO_APP_BORDER
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_ATSTART, WIRELESSSUN_DEVICE_ROLE_BORDER );
#else
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_ATSTART, WIRELESSSUN_DEVICE_ROLE_ROUTER );
#endif
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Save settings and reboot device -\r\n" );
wirelesssun_send_cmd ( &wirelesssun, WIRELESSSUN_CMD_SVRST );
wirelesssun_rsp_check ( );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
#ifdef DEMO_APP_BORDER
wirelesssun_process( );
if ( strstr( app_buf, WIRELESSSUN_CMD_PROMPT_SIGN ) )
{
uint8_t demo_hex_msg[ 100 ] = { 0 };
uint8_t demo_text_msg[ 50 ] = { 0 };
char * __generic_ptr start_msg_ptr = NULL;
char * __generic_ptr end_msg_ptr = NULL;
uint8_t msg_len = 0;
uint8_t msg_cnt = 0;
if ( ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) ) || ( strstr( app_buf, WIRELESSSUN_RSP_UDPR ) ) )
{
if ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) )
{
start_msg_ptr = strstr( app_buf, WIRELESSSUN_RSP_TCPR );
}
else
{
start_msg_ptr = strstr( app_buf, WIRELESSSUN_RSP_UDPR );
}
start_msg_ptr = strstr ( start_msg_ptr, ">" ) + 2;
end_msg_ptr = strstr( start_msg_ptr, WIRELESSSUN_CMD_PROMPT_SIGN );
msg_len = ( end_msg_ptr - start_msg_ptr );
memcpy ( demo_hex_msg, start_msg_ptr, msg_len );
for ( msg_cnt = 0; msg_cnt < msg_len; msg_cnt += 2 )
{
demo_text_msg[ msg_cnt / 2 ] = hex_to_uint8 ( &demo_hex_msg [ msg_cnt ] );
}
if ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) )
{
log_printf( &logger, "\r\n - Received TCP message: \"%s\" -\r\n", demo_text_msg );
}
else
{
log_printf( &logger, "\r\n - Received UDP message: \"%s\" -\r\n", demo_text_msg );
}
}
wirelesssun_clear_app_buf( );
}
#else
wirelesssun_wait_for_connection ( );
uint8_t gbl_address[ 20 ] = { 0 };
wirelesssun_get_parent_gbl_address ( gbl_address );
for ( ; ; )
{
uint8_t tcp_udp_params[ 120 ] = { 0 };
uint8_t demo_hex_msg[ 100 ] = { 0 };
uint8_t demo_text_msg[ 50 ] = { 0 };
uint8_t msg_cnt = 0;
strcpy ( demo_text_msg, DEMO_TEXT_MESSAGE );
strcpy ( tcp_udp_params, gbl_address );
strcat ( tcp_udp_params, WIRELESSSUN_CMD_DELIMITER );
strcat ( tcp_udp_params, WIRELESSSUN_DEFAULT_PORT );
strcat ( tcp_udp_params, WIRELESSSUN_CMD_DELIMITER );
for ( msg_cnt = 0; msg_cnt < strlen ( demo_text_msg ); msg_cnt++ )
{
uint8_to_hex ( demo_text_msg[ msg_cnt ], &demo_hex_msg[ msg_cnt * 2 ] );
}
strcat ( tcp_udp_params, demo_hex_msg );
log_printf( &logger, "\r\n - Sending \"%s\" message via TCP -\r\n", demo_text_msg );
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_TCPS, tcp_udp_params );
wirelesssun_rsp_check ( );
Delay_ms ( 3000 );
log_printf( &logger, "\r\n - Sending \"%s\" message via UDP -\r\n", demo_text_msg );
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_UDPS, tcp_udp_params );
wirelesssun_rsp_check ( );
Delay_ms ( 3000 );
}
#endif
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
static void wirelesssun_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t wirelesssun_process ( void )
{
int32_t rx_size;
char rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = wirelesssun_generic_read( &wirelesssun, rx_buf, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE )
{
wirelesssun_clear_app_buf( );
log_error( &logger, " Overflow!" );
return WIRELESSSUN_ERROR;
}
else
{
buf_cnt = app_buf_len;
app_buf_len += rx_size;
}
for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
{
if ( rx_buf[ rx_cnt ] )
{
app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buf[ rx_cnt ];
log_printf( &logger, "%c", rx_buf[ rx_cnt ] );
}
else
{
app_buf_len--;
buf_cnt--;
}
}
return WIRELESSSUN_OK;
}
return WIRELESSSUN_ERROR;
}
static err_t wirelesssun_rsp_check ( void )
{
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
wirelesssun_clear_app_buf( );
wirelesssun_process( );
while ( 0 == strstr( app_buf, WIRELESSSUN_CMD_PROMPT_SIGN ) )
{
wirelesssun_process( );
if ( timeout_cnt++ >= timeout )
{
wirelesssun_clear_app_buf( );
log_error( &logger, " Timeout!" );
return WIRELESSSUN_ERROR_TIMEOUT;
}
Delay_ms( 1 );
}
log_printf( &logger, "\r\n" );
return WIRELESSSUN_OK;
}
static void wirelesssun_wait_for_connection ( void )
{
#define FSTAT_OPERATIONAL "fstat 5(OPERATIONAL)"
#define FMNG_JOIN_STATE_5 "FMng: changed fan join state (4 -> 5)"
uint32_t timeout_cnt = 0;
uint32_t timeout = 60000;
for ( ; ; )
{
wirelesssun_process( );
if ( timeout_cnt++ >= timeout )
{
wirelesssun_send_cmd ( &wirelesssun, WIRELESSSUN_CMD_FSTAT );
wirelesssun_rsp_check ( );
timeout_cnt = 0;
}
Delay_ms( 1 );
if ( ( strstr( app_buf, FMNG_JOIN_STATE_5 ) ) ||
( strstr( app_buf, FSTAT_OPERATIONAL ) ) )
{
wirelesssun_clear_app_buf( );
return;
}
if ( strstr( app_buf, WIRELESSSUN_CMD_PROMPT_SIGN ) )
{
wirelesssun_clear_app_buf( );
}
}
}
static void wirelesssun_get_parent_gbl_address ( uint8_t *gbl_addr )
{
#define GBL_ADDRESS_START "GBL<"
#define GBL_ADDRESS_END ">"
for ( ; ; )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 10000;
wirelesssun_send_cmd ( &wirelesssun, WIRELESSSUN_CMD_RPLINF );
wirelesssun_rsp_check ( );
for ( ; ; )
{
wirelesssun_process( );
if ( strstr( app_buf, WIRELESSSUN_CMD_PROMPT_SIGN ) )
{
char * __generic_ptr start_gbl_ptr = strstr( app_buf, GBL_ADDRESS_START );
if ( start_gbl_ptr )
{
start_gbl_ptr += 4;
Delay_ms( 100 );
wirelesssun_process( );
char * __generic_ptr end_gbl_ptr = strstr( start_gbl_ptr, GBL_ADDRESS_END );
memcpy ( gbl_addr, start_gbl_ptr, end_gbl_ptr - start_gbl_ptr );
wirelesssun_clear_app_buf( );
return;
}
wirelesssun_clear_app_buf( );
}
if ( timeout_cnt++ > timeout )
{
break;
}
Delay_ms( 1 );
}
}
}
// ------------------------------------------------------------------------ END