确保智能电网设备之间的无缝连接。
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™配备了一个包含函数和示例代码的库,可供进一步开发时参考。
功能概述
开发板
Nucleo-64 搭载 STM32F410RB MCU 提供了一种经济高效且灵活的平台,供开发者探索新想法并原型设计他们的项目。该板利用 STM32 微控制器的多功能性,使用户能够为他们的项目选择最佳的性能与功耗平衡。它配备了 LQFP64 封装的 STM32 微控制器,并包含了如用户 LED(同时作为 ARDUINO® 信号)、用户和复位按钮,以及 32.768kHz 晶体振荡器用于精确的计时操作等基本组件。Nucleo-64 板设计考虑到扩展性和灵活性,它特有的 ARDUINO® Uno
V3 扩展连接器和 ST morpho 扩展引脚头,提供了对 STM32 I/O 的完全访问,以实现全面的项目整合。电源供应选项灵活,支持 ST-LINK USB VBUS 或外部电源,确保在各种开发环境中的适应性。该板还配备了一个具有 USB 重枚举功能的板载 ST-LINK 调试器/编程器,简化了编程和调试过程。此外,该板设计旨在简化高级开发,它的外部 SMPS 为 Vcore 逻辑供电提供高效支持,支持 USB 设备全速或 USB SNK/UFP 全速,并内置加密功能,提升了项目的功效
和安全性。通过外部 SMPS 实验的专用连接器、 用于 ST-LINK 的 USB 连接器以及 MIPI® 调试连接器,提供了更多的硬件接口和实验可能性。开发者将通过 STM32Cube MCU Package 提供的全面免费软件库和示例得到广泛支持。这些,加上与多种集成开发环境(IDE)的兼容性,包括 IAR Embedded Workbench®、MDK-ARM 和 STM32CubeIDE,确保了流畅且高效的开发体验,使用户能够充分利用 Nucleo-64 板在他们的项目中的能力。
微控制器概述
MCU卡片 / MCU
建筑
ARM Cortex-M4
MCU 内存 (KB)
128
硅供应商
STMicroelectronics
引脚数
64
RAM (字节)
32768
你完善了我!
配件
Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图
一步一步来
项目组装
实时跟踪您的结果
应用程序输出
此款Click板可通过两种方式进行接口连接和监控:
Application Output
- 在调试模式下,使用“Application Output”窗口进行实时数据监控。按照本教程正确设置它。
UART Terminal
- 通过UART终端使用USB to UART converter监控数据有关详细说明,请查看本教程。
软件支持
库描述
该库包含 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
额外支持
资源
类别:1GHz以下收发器