使用我们的2.4GHz WiFi解决方案,提升您的家庭网络,速度、覆盖范围和可靠性都令人满意,确保您轻松保持连接。
A
A
硬件概览
它是如何工作的?
WiFi 9 Click基于Panasonic的PAN9420,这是一个完全嵌入式的Wi-Fi模块。该模块结合了高性能的CPU、高灵敏度的无线电收发器、基带处理器、介质访问控制器、加密单元、具有修补能力的引导ROM、内部静态RAM和系统可编程闪存存储器。模块集成的QSPI闪存存储器可供应用程序存储网页内容,如HTML页面或图像数据。对接入点和基础结构模式的并行支持,可以方便地设置模块到智能设备和家庭网络路由器的同时Wi-Fi连接。预编程的Wi-Fi
SoC固件支持客户端(STA)、微型接入点(µAP)和自组织网络模式(Wi-Fi Direct)应用程序。通过透明模式,原始数据可以从UART发送到空中接口,传输到智能设备、Web服务器或PC应用程序。为了在mikroBUS™插座上通过一个UART实现模块和主机MCU之间的同时通信,我们添加了Nexperia的74HC4052多路复用器。在WiFi 9 Click板上,实现了几个状态LED,以便最轻松地可视化监视模块的状态,如MCU心跳、IP连
接、错误、Wi-Fi连接和引导。PAN9420支持通过空中进行固件更新。为了利用这一功能,客户需要确保满足适当的先决条件,并提供适当的环境。这个Click board™只能在3.3V逻辑电压电平下操作。在使用不同逻辑电平的MCU之前,板上必须执行适当的逻辑电压电平转换。此外,它还配备了一个包含功能和示例代码的库,可作为进一步开发的参考。
功能概述
开发板
Flip&Click PIC32MZ 是一款紧凑型开发板,设计为一套完整的解决方案,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 PIC32MZ 微控制器,Microchip 的 PIC32MZ2048EFH100,四个 mikroBUS™ 插槽用于 Click 板™连接,两个 USB 连接器,LED 指示灯,按钮,调试器/程序员连接器,以及两个与 Arduino-UNO 引脚兼容的头部。得益于创
新的制造技术,它允许您快速构建具有独特功能和特性的小工具。Flip&Click PIC32MZ 开发套件的每个部分都包含了使同一板块运行最高效的必要组件。此外,还可以选择 Flip&Click PIC32MZ 的编程方式,使用 chipKIT 引导程序(Arduino 风格的开发环境)或我们的 USB HID 引导程序,使用 mikroC、mikroBasic 和 mikroPascal for PIC32。该套件包括一个通过 USB 类型-C(USB-C)连接器的干净且调
节过的电源供应模块。所有 mikroBUS™ 本身支持的 通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、用户可配置的按钮和 LED 指示灯。Flip&Click PIC32MZ 开发套件允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。
微控制器概述
MCU卡片 / MCU
建筑
PIC32
MCU 内存 (KB)
2048
硅供应商
Microchip
引脚数
100
RAM (字节)
524288
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
原理图
一步一步来
项目组装
实时跟踪您的结果
通过调试模式的应用程序输出
1. 一旦代码示例加载完成,按下 "DEBUG" 按钮将启动构建过程,并将其编程到创建的设置上,然后进入调试模式。
2. 编程完成后,IDE 中将出现一个带有各种操作按钮的标题。点击绿色的 "PLAY" 按钮开始读取通过 Click board™ 获得的结果。获得的结果将在 "Application Output" 标签中显示。
软件支持
库描述
该库包含 WiFi 9 Click 驱动程序的 API。
关键功能:
wifi9_select_uart
- 切换到命令或二进制UARTwifi9_reset_device
- 模块重置。wifi9_send_command
- 发送命令函数。
开源
代码示例
这个示例可以在 NECTO Studio 中找到。欢迎下载代码,或者您也可以复制下面的代码。
/*!
* \file
* \brief WiFi 9 Click example
*
* # Description
* This application showcases capability of the WiFi 9 Click board.
* It initializes device, connects to local WiFi. Creates TCP server, waits for connection,
* and logs every message it receives from clients and returns back those messages as an echo response.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver and wifi communication, then connects to the desired WiFi network
* and creates TCP server on the IP address assigned to the click board.
*
* ## Application Task
* All data received from the TCP clients will be logger to USB UART and echoed back to the clients.
*
* ## Additional Function
* - static void wifi9_clear_app_buf ( void )
* - static err_t wifi9_process ( void )
* - static void wifi9_log_app_buf ( void )
* - static err_t wifi9_rsp_check ( uint8_t *rsp )
*
* \author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "wifi9.h"
#include "string.h"
// Example parameters
#define EXAMPLE_SSID "MikroE Public"
#define EXAMPLE_PASSWORD "mikroe.guest"
#define EXAMPLE_SERVER_PORT "1234"
// Application buffer size
#define APP_BUFFER_SIZE 256
#define PROCESS_BUFFER_SIZE 256
// ------------------------------------------------------------------ VARIABLES
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static wifi9_t wifi9;
static log_t logger;
// ------------------------------------------------------- ADDITIONAL FUNCTIONS
/**
* @brief Clearing application buffer.
* @details This function clears memory of application
* buffer and reset its length.
*/
static void wifi9_clear_app_buf ( void );
/**
* @brief Data reading function.
* @details This function reads data from device and
* appends it to the application buffer.
* @return @li @c 0 - Some data is read.
* @li @c -1 - Nothing is read.
* See #err_t definition for detailed explanation.
*/
static err_t wifi9_process ( void );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void wifi9_log_app_buf ( void );
/**
* @brief Response check.
* @details This function checks for response and
* returns the status of response.
* @param[in] rsp Expected response.
* @return @li @c 0 - OK response.
* @li @c -1 - Unknown error.
* @li @c -2 - Timeout error.
* See #err_t definition for detailed explanation.
*/
static err_t wifi9_rsp_check ( uint8_t *rsp );
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg;
wifi9_cfg_t cfg;
/**
* 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.
wifi9_cfg_setup( &cfg );
WIFI9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
wifi9_init( &wifi9, &cfg );
wifi9_reset_device( &wifi9 );
wifi9_select_uart( &wifi9, WIFI9_SELECT_CMD_UART );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
wifi9_process( );
wifi9_clear_app_buf( );
log_printf( &logger, "---------------------\r\n" );
log_printf( &logger, "---- System Info ----\r\n" );
log_printf( &logger, "---------------------\r\n" );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_FIRMWARE );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_FIRMWARE );
wifi9_log_app_buf( );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_MAC_ADDR );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_MAC_ADDR );
wifi9_log_app_buf( );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_SERIAL_NUM );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_SERIAL_NUM );
wifi9_log_app_buf( );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_RADIO_VER );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_RADIO_VER );
wifi9_log_app_buf( );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_BOOTL_VER );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_BOOTL_VER );
wifi9_log_app_buf( );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_SYSTEM_HW_REV );
wifi9_rsp_check( WIFI9_CMD_GET_SYSTEM_HW_REV );
wifi9_log_app_buf( );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, "--------------------------\r\n" );
log_printf( &logger, "---- Start NETCAT app ----\r\n" );
log_printf( &logger, "--------------------------\r\n" );
log_printf( &logger, "\r\nSet Station to ON status: " );
wifi9_send_command( &wifi9, WIFI9_CMD_SET_WLAN_STATE_STA_ON );
wifi9_rsp_check( WIFI9_CMD_SET_WLAN_STATE );
wifi9_log_app_buf( );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, "\r\nSet Station SSID and PASSWORD: " );
strcpy( app_buf, WIFI9_CMD_SET_WLAN_CFG_STA );
strcat( app_buf, " \"" );
strcat( app_buf, EXAMPLE_SSID );
strcat( app_buf, "\" \"" );
strcat( app_buf, EXAMPLE_PASSWORD );
strcat( app_buf, "\" 4" );
wifi9_send_command( &wifi9, app_buf );
wifi9_rsp_check( WIFI9_CMD_SET_WLAN_CFG );
wifi9_log_app_buf( );
Delay_ms ( 500 );
log_printf( &logger, "\r\nTurn ON - Netcat module: " );
wifi9_send_command( &wifi9, WIFI9_CMD_SET_NETCAT_STATE_ON );
wifi9_rsp_check( WIFI9_CMD_SET_NETCAT_STATE );
wifi9_log_app_buf( );
Delay_ms ( 500 );
log_printf( &logger, "\r\nExclude Netcat authentication: " );
wifi9_send_command( &wifi9, WIFI9_CMD_SET_NETCAT_AUTH_OFF );
wifi9_rsp_check( WIFI9_CMD_SET_NETCAT_AUTH );
wifi9_log_app_buf( );
Delay_ms ( 500 );
log_printf( &logger, "\r\nSet the Netcat module server port: " );
strcpy( app_buf, WIFI9_CMD_SET_NETCAT_CFG_SERVER );
strcat( app_buf, " " );
strcat( app_buf, EXAMPLE_SERVER_PORT );
wifi9_send_command( &wifi9, app_buf );
wifi9_rsp_check( WIFI9_CMD_SET_NETCAT_CFG );
wifi9_log_app_buf( );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, "\r\nWaiting for an IP address assignment from DHCP server...\r\n" );
for ( ; ; )
{
log_printf( &logger, "\r\nGet IP address: " );
wifi9_send_command( &wifi9, WIFI9_CMD_GET_NET_CFG_STA );
wifi9_rsp_check( WIFI9_CMD_GET_NET_CFG );
wifi9_log_app_buf( );
if ( !strstr ( app_buf, "0.0.0.0" ) )
{
break;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
wifi9_clear_app_buf( );
Delay_ms ( 1000 );
log_printf( &logger, "\r\nNow you can connect to the TCP server listed above via a TCP client app\r\n" );
log_printf( &logger, "The module is transferred to BIN-UART - for data collection\r\n" );
wifi9_select_uart( &wifi9, WIFI9_SELECT_BIN_UART );
log_info( &logger, " Application Task " );
Delay_ms ( 1000 );
}
void application_task ( void )
{
wifi9_process( );
if ( app_buf_len )
{
wifi9_log_app_buf( );
wifi9_generic_write( &wifi9, app_buf, app_buf_len );
wifi9_clear_app_buf( );
Delay_ms ( 100 );
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
static void wifi9_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static err_t wifi9_process ( void )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t rx_size = 0;
rx_size = wifi9_generic_read( &wifi9, rx_buf, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = app_buf_len;
if ( ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) && ( app_buf_len > 0 ) )
{
buf_cnt = APP_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - APP_BUFFER_SIZE );
memmove ( app_buf, &app_buf[ APP_BUFFER_SIZE - buf_cnt ], buf_cnt );
}
for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
{
if ( rx_buf[ rx_cnt ] )
{
app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
if ( app_buf_len < APP_BUFFER_SIZE )
{
app_buf_len++;
}
}
}
return WIFI9_OK;
}
return WIFI9_ERROR;
}
static void wifi9_log_app_buf ( void )
{
for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
{
log_printf( &logger, "%c", app_buf[ buf_cnt ] );
}
}
static err_t wifi9_rsp_check ( uint8_t *rsp )
{
uint32_t timeout_cnt = 0;
uint32_t timeout = 60000;
wifi9_clear_app_buf( );
wifi9_process( );
while ( 0 == strstr( app_buf, rsp ) )
{
wifi9_process( );
if ( timeout_cnt++ > timeout )
{
wifi9_clear_app_buf( );
return WIFI9_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
Delay_ms ( 100 );
wifi9_process( );
if ( strstr( app_buf, rsp ) )
{
return WIFI9_OK;
}
return WIFI9_ERROR;
}
// ------------------------------------------------------------------------ END