非常适合需要长期低功耗电池运行的云连接系统
A
A
硬件概览
它是如何工作的?
Calypso Click基于Würth Elektronik的WIRL-WIFS Calypso(2610011025000)WLAN模块,专为嵌入式应用中的无线连接设计。该模块符合IEEE 802.11 b/g/n标准,配备完整集成的TCP/IP协议栈,是WiFi通信的多功能解决方案。Calypso模块通过WiFi认证(ID: WFA81685),确保符合行业标准,提供可靠的应用性能。它采用边缘电镀连接和智能天线配置,易于集成到任何系统中,并具有直观的AT风格命令界面,简化了配置和控制。Calypso模块支持IPv4和IPv6协议,并预装了多种网络协议,如SNTP、DHCPv4、DHCPv6、mDNS、HTTP(S)和MQTT,确保高效、安全的数据交换。其先进的安全功能包括同时处理多达六个安全套接字、支持安全启动、存储和空中(OTA)更新,使其成为需要安全、可靠云连接的物联网应用的理想选择。Calypso模块具备低功耗无线连接,适用于串行电缆替代方案或中等数据吞吐量需求的低功耗物联网设备。该Click板™采用
UART接口与主MCU通信,使用标准的RX和TX引脚,并通过CTS和RTS引脚进行硬件流控制。默认通信速率为921600bps,确保平稳、高效的数据传输。整个模块通过UART接口的AT命令进行配置和控制,配置完成后独立管理WLAN连接,释放主控制器的资源。此外,通过定制固件开发,可实现无需主机的独立应用。Click板™配备USB Type-C连接器,通过PC进行供电和配置。这得益于集成的CP2102N USB到UART桥接芯片和NCP1117 LDO稳压器,它将USB供电转换为模块所需的3.3V。除了这种供电方式,板载还支持背面的纽扣电池备用电源,允许实现前面提到的独立运行。除了UART接口外,该Click板™还使用I2C接口控制I/O扩展器PCA9536,由于mikroBUS™引脚数量有限,该扩展器管理特定模块功能。通过扩展器,可以控制以下功能:AP0和AP1,用于设置应用模式(如AT命令正常模式、OTA、Provisioning或透明模式);BOOT引脚在启动时拉低以启用标准应
用引导;RM2引脚可配置为远程GPIO功能,允许配置和控制GPIO,包括输入、输出和PWM。此外,这些信号可以通过SW1开关手动控制,RM1则通过开关管理,RM0可以通过mikroBUS™插座进行控制。该板还配备了多个额外功能来增强其性能。它包括一个复位引脚(RST)和一个RESET按钮用于模块复位,以及一个唤醒引脚(WUP)用于将模块从睡眠模式中唤醒。板上有两个LED指示灯用于提供视觉反馈:一个绿色(LD2)和一个蓝色(LD3),用于指示模块的操作状态。此外,用户可以选择板载PCB天线(适用于紧凑设计)或通过板载ANT u.Fl连接器连接外部天线,适用于远程应用。此Click板™只能在3.3V逻辑电平下运行。在使用具有不同逻辑电平的MCU之前,必须进行适当的逻辑电平转换。此外,该Click板™还配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。
功能概述
开发板
Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE
mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口
来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。
微控制器概述
MCU卡片 / MCU

建筑
PIC32
MCU 内存 (KB)
2048
硅供应商
Microchip
引脚数
100
RAM (字节)
524288
使用的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”替换为要显示的参数。

软件支持
库描述
该库包含 Calypso Click 驱动程序的 API。
关键功能:
calypso_set_app_mode
- 此函数用于设置Calypso Click板的选定应用模式。calypso_hw_reset
- 此函数用于执行硬件重置。calypso_send_cmd
- 此函数用于发送所需的命令。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief Calypso Click Example.
*
* # Description
* This example demonstrates the use of Calypso Click board by processing
* the incoming data and displaying them on the USB UART.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and places AT command mode, tests the communication,
* and after that restarts the device, and performs example configuration.
*
* ## Application Task
* It creates a connection to the TCP-UDP echo server, sends a message to it reads it back,
* displaces it on the UART terminal, and then closes the connection.
*
* ## Additional Function
* - static void calypso_clear_app_buf ( void )
* - static void calypso_log_app_buf ( void )
* - static err_t calypso_process ( void )
* - static err_t calypso_rsp_check ( uint8_t *rsp )
* - static void calypso_error_check ( err_t error_flag )
* - static void calypso_configure_for_example ( void )
* - static void calypso_example ( void )
*
* @author MikroE Team
*
*/
#include "board.h"
#include "log.h"
#include "calypso.h"
#include "conversions.h"
// Message content
#define MESSAGE_CONTENT "Calypso Click board - demo example."
// TCP/UDP example parameters
#define REMOTE_IP "77.46.162.162" // TCP/UDP echo server IP address
#define REMOTE_PORT "51111" // TCP/UDP echo server port
// WiFi parameters
#define WIFI_SSID "MikroE Public"
#define WIFI_PWD "mikroe.guest"
// Application buffer size
#define APP_BUFFER_SIZE 256
#define PROCESS_BUFFER_SIZE 256
static calypso_t calypso;
static log_t logger;
static err_t error_flag;
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
/**
* @brief Calypso clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void calypso_clear_app_buf ( void );
/**
* @brief Calypso log application buffer.
* @details This function logs data from application buffer to USB UART.
* @note None.
*/
static void calypso_log_app_buf ( void );
/**
* @brief Calypso 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 calypso_process ( 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 - Error response.
* @li @c -2 - Timeout error.
* @li @c -3 - Unknown error.
* See #err_t definition for detailed explanation.
*/
static err_t calypso_rsp_check ( uint8_t *rsp );
/**
* @brief Check for errors.
* @details This function checks for different types of
* errors and logs them on UART or logs the response if no errors occured.
* @param[in] error_flag : Error flag to check.
*/
static void calypso_error_check ( err_t error_flag );
/**
* @brief Calypso configure for example function.
* @details This function is used to configure device for example.
*/
static void calypso_configure_for_example ( void );
/**
* @brief Calypso execute example function.
* @details This function executes TCP/UDP Example.
*/
static void calypso_example ( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
calypso_cfg_t calypso_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.
calypso_cfg_setup( &calypso_cfg );
CALYPSO_MAP_MIKROBUS( calypso_cfg, MIKROBUS_1 );
if ( UART_ERROR == calypso_init( &calypso, &calypso_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( CALYPSO_ERROR == calypso_default_cfg ( &calypso ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
calypso_configure_for_example( );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
calypso_example( );
}
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 calypso_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static void calypso_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 calypso_process ( void )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t overflow_bytes = 0;
int32_t rx_cnt = 0;
int32_t rx_size = calypso_generic_read( &calypso, rx_buf, PROCESS_BUFFER_SIZE );
if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) )
{
if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE )
{
overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
app_buf_len = APP_BUFFER_SIZE - rx_size;
memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
}
for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
{
if ( rx_buf[ rx_cnt ] )
{
app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
}
}
return CALYPSO_OK;
}
return CALYPSO_ERROR;
}
static err_t calypso_rsp_check ( uint8_t *rsp )
{
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
calypso_clear_app_buf( );
calypso_process( );
while ( ( 0 == strstr( app_buf, rsp ) ) &&
( 0 == strstr( app_buf, CALYPSO_RSP_ERROR ) ) )
{
calypso_process( );
if ( timeout_cnt++ > timeout )
{
calypso_clear_app_buf( );
return CALYPSO_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
Delay_ms ( 100 );
calypso_process( );
if ( strstr( app_buf, rsp ) )
{
return CALYPSO_OK;
}
else if ( strstr( app_buf, CALYPSO_RSP_ERROR ) )
{
return CALYPSO_ERROR_CMD;
}
else
{
return CALYPSO_ERROR_UNKNOWN;
}
}
static void calypso_error_check ( err_t error_flag )
{
switch ( error_flag )
{
case CALYPSO_OK:
{
calypso_log_app_buf( );
break;
}
case CALYPSO_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case CALYPSO_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case CALYPSO_ERROR_CMD:
{
log_error( &logger, " ERROR Response!" );
break;
}
case CALYPSO_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
Delay_ms ( 500 );
}
static void calypso_configure_for_example ( void )
{
uint8_t command_data[ APP_BUFFER_SIZE ] = { 0 };
log_printf( &logger, " Hardware reset. \r\n" );
calypso_hw_reset( &calypso );
error_flag = calypso_rsp_check( CALYPSO_RSP_READY );
calypso_error_check( error_flag );
log_printf( &logger, " Performing Test. \r\n" );
calypso_send_cmd( &calypso, CALYPSO_CMD_AT_TEST );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Setting WLAN Mode. \r\n" );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_WLAN_SET_MODE, "STA" );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
#define SECURITY_TYPE "WPA_WPA2"
strcpy( command_data, WIFI_SSID );
strcat( command_data, ",," );
strcat( command_data, SECURITY_TYPE );
strcat( command_data, "," );
strcat( command_data, WIFI_PWD );
strcat( command_data, ",,," );
log_printf( &logger, " WLAN Connect. \r\n" );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_WLAN_CONNECT, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
error_flag = calypso_rsp_check( CALYPSO_RSP_CONNECTED );
calypso_error_check( error_flag );
}
static void calypso_example ( void )
{
uint8_t command_data[ APP_BUFFER_SIZE ] = { 0 };
uint8_t socket_num[ 4 ] = { 0 };
uint8_t * __generic_ptr socket_num_buf = 0;
#define SOCKET_OPEN "+socket:"
#define SOCKET_CONNECTED "+connect:"
#define SOCKET_FAMILY "INET"
#define SOCKET_TYPE "STREAM"
#define SOCKET_PROTOCOL_TCP "TCP"
#define SOCKET_PROTOCOL_UDP "UDP"
#define SOCKET_FORMAT_BINATY "0"
log_printf( &logger, " Create TCP socket. \r\n" );
strcpy( command_data, SOCKET_FAMILY );
strcat( command_data, "," );
strcat( command_data, SOCKET_TYPE );
strcat( command_data, "," );
strcat( command_data, SOCKET_PROTOCOL_TCP );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_SOCKET, command_data );
error_flag = calypso_rsp_check( SOCKET_OPEN );
calypso_error_check( error_flag );
socket_num_buf = strstr( app_buf, SOCKET_OPEN ) + strlen ( SOCKET_OPEN );
if ( socket_num_buf )
{
memcpy ( socket_num, socket_num_buf, 2 );
if ( socket_num[ 1 ] < '0' || socket_num[ 1 ] > '9' )
{
socket_num[ 1 ] = 0;
}
}
log_printf( &logger, " Connect to the TCP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FAMILY );
strcat( command_data, "," );
strcat( command_data, REMOTE_PORT );
strcat( command_data, "," );
strcat( command_data, REMOTE_IP );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_CONNECT, command_data );
error_flag = calypso_rsp_check( SOCKET_CONNECTED );
calypso_error_check( error_flag );
uint8_t message_len_buf[ 10 ] = { 0 };
uint16_t message_len = strlen( MESSAGE_CONTENT );
uint16_to_str( message_len, message_len_buf );
l_trim( message_len_buf );
r_trim( message_len_buf );
log_printf( &logger, " Send data to the TCP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FORMAT_BINATY );
strcat( command_data, "," );
strcat( command_data, message_len_buf );
strcat( command_data, "," );
strcat( command_data, MESSAGE_CONTENT );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_SEND, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Read data from the TCP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FORMAT_BINATY );
strcat( command_data, "," );
strcat( command_data, message_len_buf );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_RECV, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Closing the TCP connection. \r\n" );
strcpy( command_data, socket_num );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_CLOSE, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Create UDP socket. \r\n" );
strcpy( command_data, SOCKET_FAMILY );
strcat( command_data, "," );
strcat( command_data, SOCKET_TYPE );
strcat( command_data, "," );
strcat( command_data, SOCKET_PROTOCOL_UDP );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_SOCKET, command_data );
error_flag = calypso_rsp_check( SOCKET_OPEN );
calypso_error_check( error_flag );
socket_num_buf = strstr( app_buf, SOCKET_OPEN ) + strlen ( SOCKET_OPEN );
if ( socket_num_buf )
{
memcpy ( socket_num, socket_num_buf, 2 );
if ( socket_num[ 1 ] < '0' || socket_num[ 1 ] > '9' )
{
socket_num[ 1 ] = 0;
}
}
log_printf( &logger, " Connect to the UDP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FAMILY );
strcat( command_data, "," );
strcat( command_data, REMOTE_PORT );
strcat( command_data, "," );
strcat( command_data, REMOTE_IP );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_CONNECT, command_data );
error_flag = calypso_rsp_check( SOCKET_CONNECTED );
calypso_error_check( error_flag );
log_printf( &logger, " Send data to the UDP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FORMAT_BINATY );
strcat( command_data, "," );
strcat( command_data, message_len_buf );
strcat( command_data, "," );
strcat( command_data, MESSAGE_CONTENT );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_SEND, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Read data from the UDP server. \r\n" );
strcpy( command_data, socket_num );
strcat( command_data, "," );
strcat( command_data, SOCKET_FORMAT_BINATY );
strcat( command_data, "," );
strcat( command_data, message_len_buf );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_RECV, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
log_printf( &logger, " Closing the UDP connection. \r\n" );
strcpy( command_data, socket_num );
calypso_send_cmd_with_par( &calypso, CALYPSO_CMD_AT_CLOSE, command_data );
error_flag = calypso_rsp_check( CALYPSO_RSP_OK );
calypso_error_check( error_flag );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
// ------------------------------------------------------------------------ END