初学者
10 分钟

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

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

WiFi NORA Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

WiFi NORA Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

通过双频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

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

Host Wake-Up
PA0
AN
Reset / ID SEL
PA11
RST
UART CTS / ID COMM
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Module Wake-Up
PA8
PWM
UART RTS
PA12
INT
UART TX
PA10
TX
UART RX
PA9
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

WiFi NORA Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 32 with STM32F031K6 MCU作为您的开发板开始。

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
STM32 M4 Clicker HA MCU/Select 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

额外支持

资源

喜欢这个项目吗?

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