初学者
10 分钟

使用NORA-W36和PIC32MZ2048EFH100提供核心无线通信功能,支持WiFi 4 (802.11a/b/g/n)和v5.3 BLE

用于专业级应用的双频WiFi模块,带有蓝牙LE

WiFi NORA Click with Flip&Click PIC32MZ

已发布 9月 09, 2024

点击板

WiFi NORA Click

开发板

Flip&Click PIC32MZ

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFH100

通过双频WiFi和BLE连接增强您的项目,实现安全可靠的通信

A

A

硬件概览

它是如何工作的?

WiFi NORA Click基于u-blox的NORA-W366-00B6-00B双频WiFi和低功耗蓝牙(BLE)模块,采用Realtek RTL8720DF芯片,旨在增强专业级应用中的无线连接性。该模块支持WiFi 4(802.11a/b/g/n)协议,在2.4GHz和5GHz频段均可工作,能够作为WiFi站点或接入点运行。此外,它提供了蓝牙v5.3功能,能够作为外围设备、中央设备或两者兼具,并可以灵活充当GATT客户端或服务器。WiFi NORA Click适用于多种应用场景,如工业自动化、智能建筑与家居、智慧城市、计量和公用事业、医疗保健以及电动汽车充电等。该模块通过全球认证,配备了高性能的内部PCB天线,具有广泛的覆盖范围。模块预装了u-connectXpress软件,简化了终端产品的集成,加快了上市时间。它包括用于点对点和点对多点应用的

TCP/IP协议栈,并通过支持TLS加密和MQTT协议,确保与基于云的服务进行安全通信。此外,该模块还提供了强大的安全功能,包括WPA2/WPA3、WiFi企业安全和蓝牙LE安全连接。此Click板™通过UART接口在NORA-W366-00B6-00B模块与主MCU之间建立通信,使用标准的UART RX和TX引脚以及硬件流控制引脚(CTS/RTS)。默认通信速度设定为115200bps,以确保高效的数据交换。主MCU通过高级AT命令配置无线通信和其他功能,免去了深入了解WiFi和蓝牙协议栈的需求。除了接口引脚外,模块还使用了一些其他的mikroBUS™引脚,例如WKP引脚,作为主MCU唤醒功能的输出,WHS引脚用于将模块从深度睡眠模式唤醒。该板还具有一个RST引脚和一个RESET按钮,用于重置模块的功能。WiFi NORA

 Click配备了两个按钮,SW1和SW2,用于进入引导模式。当同时按下两个按钮时,模块将进入引导模式。如果在10秒内没有通过UART发送命令给引导程序,u-connectXpress应用将自动启动,模块设置将恢复为出厂默认值。仅按下SW1按钮会触发u-connectXpress应用程序的启动。此外,该Click板™包含一个用户可配置的RGB LED指示灯(LD2),用于指示各种模块状态。该Click板™只能在3.3V逻辑电平下运行。在使用具有不同逻辑电平的MCU之前,板上必须进行适当的逻辑电平转换。此外,它还配备了包含函数和示例代码的库,可作为进一步开发的参考。

WiFi NORA Click hardware overview image

功能概述

开发板

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 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Flip&Click PIC32MZ double image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

Host Wake-Up
RB11
AN
Reset / ID SEL
RE2
RST
UART CTS / ID COMM
RA0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Module Wake-Up
RC14
PWM
UART RTS
RD9
INT
UART TX
RE3
TX
UART RX
RG9
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

WiFi NORA Click Schematic schematic

一步一步来

项目组装

Flip&Click PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Flip&Click PIC32MZ作为您的开发板开始。

Flip&Click PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

软件支持

库描述

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

关键功能:

  • wifinora_hw_reset - 此函数用于执行硬件重置。

  • wifinora_send_cmd - 此函数用于发送所需的命令。

  • wifinora_send_cmd_with_par - 此函数用于发送带参数的所需命令。

开源

代码示例

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

/*!
 * @file main.c
 * @brief WiFi NORA Click Example.
 *
 * # Description
 * This example demonstrates the use of WiFi NORA 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, 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 wifinora_clear_app_buf ( void )
 * - static void wifinora_log_app_buf ( void )
 * - static err_t wifinora_process ( wifinora_t *ctx )
 * - static err_t wifinora_rsp_check ( uint8_t *rsp )
 * - static void wifinora_configure_for_example ( void )
 * - static void wifinora_configure_for_example ( void )
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "wifinora.h"

// Message content
#define MESSAGE_CONTENT                     "WiFi NORA 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                     200
#define PROCESS_BUFFER_SIZE                 200

static wifinora_t wifinora;
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 WiFi NORA clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void wifinora_clear_app_buf ( void );

/**
 * @brief WiFi NORA log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void wifinora_log_app_buf ( void );

/**
 * @brief WiFi NORA 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 wifinora_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 wifinora_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 wifinora_error_check ( err_t error_flag );

/**
 * @brief WiFi NORA configure for example function.
 * @details This function is used to configure device for example.
 */
static void wifinora_configure_for_example ( void );

/**
 * @brief WiFi NORA execute example function.
 * @details This function executes TCP/UDP Example.
 */
static void wifinora_example ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    wifinora_cfg_t wifinora_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.
    wifinora_cfg_setup( &wifinora_cfg );
    WIFINORA_MAP_MIKROBUS( wifinora_cfg, MIKROBUS_1 );
    if ( UART_ERROR == wifinora_init( &wifinora, &wifinora_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

    wifinora_process( );
    wifinora_clear_app_buf( );

    // Hardware reset
    wifinora_hw_reset( &wifinora );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_READY );
    wifinora_error_check( error_flag );

    // Communication check
    wifinora_send_cmd( &wifinora, WIFINORA_CMD_AT );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    // Factory reset
    wifinora_send_cmd( &wifinora, WIFINORA_CMD_AT_USYFR );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    // Software reset
    wifinora_send_cmd( &wifinora, WIFINORA_CMD_AT_SW_RESET );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_READY );
    wifinora_error_check( error_flag );

    wifinora_send_cmd( &wifinora, WIFINORA_CMD_AT_GMM );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    wifinora_configure_for_example( );

    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    wifinora_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 wifinora_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void wifinora_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 wifinora_process ( void ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = wifinora_generic_read( &wifinora, 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 WIFINORA_OK;
    }
    return WIFINORA_ERROR;
}

static err_t wifinora_rsp_check ( uint8_t *rsp )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    wifinora_clear_app_buf( );
    wifinora_process( );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, WIFINORA_RSP_ERROR ) ) )
    {
        wifinora_process( );
        if ( timeout_cnt++ > timeout )
        {
            wifinora_clear_app_buf( );
            return WIFINORA_ERROR_TIMEOUT;
        }
        Delay_ms ( 1 );
    }
    Delay_ms ( 100 );
    wifinora_process( );
    if ( strstr( app_buf, rsp ) )
    {
        return WIFINORA_OK;
    }
    else if ( strstr( app_buf, WIFINORA_RSP_ERROR ) )
    {
        return WIFINORA_ERROR_CMD;
    }
    else
    {
        return WIFINORA_ERROR_UNKNOWN;
    }
}

static void wifinora_error_check ( err_t error_flag )
{    
    switch ( error_flag )
    {
        case WIFINORA_OK:
        {
            wifinora_log_app_buf( );
            break;
        }
        case WIFINORA_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case WIFINORA_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case WIFINORA_ERROR_CMD:
        {
            log_error( &logger, " ERROR Response!" );
            break;
        }
        case WIFINORA_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    Delay_ms ( 500 );
}

static void wifinora_configure_for_example ( void )
{
    uint8_t command_data[ APP_BUFFER_SIZE ] = { 0 };

    #define WLAN_HANDLE         "0"
    strcpy( command_data, WLAN_HANDLE );
    strcat( command_data, ",\"" );
    strcat( command_data, WIFI_SSID );
    strcat( command_data, "\"" );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_UWSCP, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_UWSIPD, "0" );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    #define WPA_THRESHILD       "0"
    strcpy( command_data, WLAN_HANDLE );
    strcat( command_data, ",\"" );
    strcat( command_data, WIFI_PWD );
    strcat( command_data, "\"," );
    strcat( command_data, WPA_THRESHILD );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_UWSSW, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_UWSC, "0" );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    #define CONNECTED           "+UENEU"
    error_flag = wifinora_rsp_check( CONNECTED );
}

static void wifinora_example ( void )
{
    uint8_t command_data[ APP_BUFFER_SIZE ] = { 0 };
    #define TCP_CLIENT          "0"
    #define UDP_CLIENT          "1"
    #define READ_LEN            "255"

    log_printf( &logger, " TCP Example \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );

    #define TCP_PROTOCOL        "6"
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOCR, TCP_PROTOCOL );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    strcpy( command_data, TCP_CLIENT );
    strcat( command_data, "," );
    strcat( command_data, REMOTE_IP );
    strcat( command_data, "," );
    strcat( command_data, REMOTE_PORT );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOC, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    log_printf( &logger, " Send data \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    strcpy( command_data, TCP_CLIENT );
    strcat( command_data, ",\"" );
    strcat( command_data, MESSAGE_CONTENT );
    strcat( command_data, "\"" );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOWS, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    log_printf( &logger, " Read data \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    strcpy( command_data, TCP_CLIENT );
    strcat( command_data, "," );
    strcat( command_data, READ_LEN );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USORS, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    log_printf( &logger, " UDP Example \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );

    #define UDP_PROTOCOL        "17"
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOCR, UDP_PROTOCOL );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    strcpy( command_data, UDP_CLIENT );
    strcat( command_data, "," );
    strcat( command_data, REMOTE_IP );
    strcat( command_data, "," );
    strcat( command_data, REMOTE_PORT );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOC, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    log_printf( &logger, " Send data \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    strcpy( command_data, UDP_CLIENT );
    strcat( command_data, ",\"" );
    strcat( command_data, MESSAGE_CONTENT );
    strcat( command_data, "\"" );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOWS, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    log_printf( &logger, " Read data \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    strcpy( command_data, UDP_CLIENT );
    strcat( command_data, "," );
    strcat( command_data, READ_LEN );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USORS, command_data );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    log_printf( &logger, " Close sockets \r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOCL, UDP_CLIENT );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    wifinora_send_cmd_with_par( &wifinora, WIFINORA_CMD_AT_USOCL, TCP_CLIENT );
    error_flag = wifinora_rsp_check( WIFINORA_RSP_OK );
    wifinora_error_check( error_flag );

    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

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

额外支持

资源

喜欢这个项目吗?

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