中级
30 分钟

体验SARA-R410M-02B和STM32F031K6在物联网连接方面的巨大进步

物联网连接的未来

LTE IoT Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

LTE IoT Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

通过 LTE IoT 赋能您的物联网项目,无缝集成 CAT M1 和 NB1 技术,开启无限连接的可能性。

A

A

硬件概览

它是如何工作的?

LTE IoT Click 基于 u-Blox 的 SARA-R410M-02B,这是一个可配置的 LTE Cat M1/NB1 多模模块,具有全球物联网和 M2M 应用支持。该模块由多个内部块或部分组成,例如 RF 和内存部分、电源管理部分以及具有外围接口的蜂窝基带处理器。它支持 UART 和 USB 接口,以及外部 SIM 卡/芯片接口,具有超低功耗和成本优化的解决方案,非常适合开发 LPWA 物联网应用。它还提供扩展的不连续接收(e-DRX),将电池寿命延长至 10 年。SARA-R410M-02B 的另一个优点是硬件已准备好在未来支持通过 Cat M1 的 VoLTE 实现语音功能,可用于需要一定人机交互的应用,例如安全应用中的报警面板。SARA-R410M-02B 模块的电源由 Microchip 的 1A 低压差输出(LDO)稳压器 MCP1826 调节至 3.8V。模块的数字接口供电输出引脚为 Texas Instruments 的 6 位双向电平转换和电压转换器 TXB0106 的一侧提供所需的参考电压。模块的主 UART 总线连接到 TXB0106 电平转换器的一侧,而另一侧连接到相应的 mikroBUS™ UART 引脚。电

平转换器另一侧的参考电压取自板载 SMD 跳线,标记为 PWR SEL,用于在 3.3V 和 5V 之间选择 mikroBUS™,取决于所用 MCU 类型及其逻辑电压水平要求。SARA-R410M-02B 模块使用 UART 接口与 MCU 通信,常用的 UART RX 和 TX 引脚,包括硬件流控制引脚 UART CTS、RTS、RI(清除发送、准备发送和响铃指示器)。它支持自动波特率检测,默认配置为 115200 bps,用于数据传输和与主 MCU 交换 AT 通信命令。除了默认波特率外,UART 接口还支持 9600、19200、38400 和 57600 波特率。该接口还可以作为设备连接到 USB 主机,例如个人计算机(PC),允许使用 u-Blox 提供的专有应用程序 m-center,提供干净且全面的接口,用于访问模块的主要功能、设置配置参数、管理 SMS 消息、跟踪模块活动等。LTE IoT Click 具有 50Ω 阻抗的 SMA 天线连接器,可以用于连接 MikroE 提供的合适天线,例如橡胶天线 GSM/GPRS 直角。这款天线非常适合所有 GSM/GPRS 应用,支持一系列频率和频段。Click board™ 背面有一个 Micro

 SIM 卡插槽,用于安装 micro SIM 卡,允许连接到蜂窝网络,支持 1.8V 和 3V SIM 卡类型。板载低电平有效的按钮标记为 PWR,连接到 mikroBUS™ 的 AN 引脚,代表点火(开机)按钮,其成功操作将由 STAT LED 指示。如果设备已启动,该引脚上持续 1.5 秒的低脉冲将关闭模块。也可以通过发出 AT+CPWROFF 命令或使用连接到 mikroBUS™ RST 引脚的复位功能关闭模块,这将通过在该引脚上发送持续 10 秒的有效低输入导致突然断电(强制断电)。此 Click board™ 具有两个 LED 指示灯:黄色 LED 标记为 STAT,用于直观指示设备的操作状态,红色 LED 标记为 TX,用于指示网络状态。此 Click Board™ 设计用于使用 3.3V 和 5V 逻辑电压水平,可通过 PWR SEL 跳线选择。适当的电压电平转换器执行正确的逻辑电压电平转换,而 LDO 确保模块由推荐值供电。这样,3.3V 和 5V 兼容的 MCU 都可以正确使用通信线路。此外,此 Click board™ 配备了一个库,包含易于使用的函数和示例代码,可用于进一步开发。

LTE IoT 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

LTE 平面旋转天线是一种多功能选择,可提升 3G/4G LTE 设备的性能。其宽频率范围为 700-2700MHz,确保在全球主要蜂窝频段上的最佳连接。此平板天线配有 SMA 公连接器,可轻松直接连接到您的设备或 SMA 模块连接器。其一大亮点是可调节角度,可按 45⁰ 的增量(0⁰/45⁰/90⁰)设置,使您能够微调天线方向以实现最大信号接收。具有 50Ω 的阻抗和 <2.0:1 的电压驻波比(VSWR),这款天线可确保可靠高效的连接。其 5dB 的增益、垂直极化和全向辐射模式增强了信号强度,适用于各种应用。天线尺寸为 196mm 长和 38mm 宽,提供紧凑而有效的解决方案以改善连接。其最大输入功率为 50W,能够满足各种设备的需求。

LTE IoT Click accessories image

使用的MCU引脚

mikroBUS™映射器

Power ON
PA0
AN
HW Reset / Power OFF
PA11
RST
UART CTS
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART RI
PA8
PWM
UART RTS
PA12
INT
UART TX
PA10
TX
UART RX
PA9
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LTE IoT 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
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU Access MB 1 - upright/background 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

实时跟踪您的结果

应用程序输出

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”替换为要显示的参数。

软件支持

库描述

此库包含 LTE IoT Click 驱动程序的 API。

关键功能:

  • lteiot_power_on - LTE IoT 模块电源开启

  • lteiot_send_cmd - 发送命令功能

开源

代码示例

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

/*!
 * \file 
 * \brief LteIot Click example
 * 
 * # Description
 * This example reads and processes data from LTE IoT click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and wake-up module and sets default configuration for connecting device to network.
 * 
 * ## Application Task  
 * Waits for device to connect to network and then sends SMS to selected phone number.
 * 
 * ## Additional Function
 * - static void lteiot_clear_app_buf ( void )
 * - static void lteiot_error_check( err_t error_flag )
 * - static void lteiot_log_app_buf ( void )
 * - static void lteiot_check_connection( void )
 * - static err_t lteiot_rsp_check ( void )
 * - static err_t lteiot_process ( void )
 * 
 * @note 
 * In order for the example to work, 
 * user needs to set the phone number and sim apn to which he wants to send an SMS
 * Enter valid data for the following macros: SIM_APN and PHONE_NUMBER_TO_MESSAGE.
 * E.g. 
    SIM_APN "vipmobile"
    PHONE_NUMBER_TO_MESSAGE "999999999"
 * 
 * @author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "lteiot.h"

#define APP_OK                              0
#define APP_ERROR_DRIVER                    -1
#define APP_ERROR_OVERFLOW                  -2
#define APP_ERROR_TIMEOUT                   -3

#define RSP_OK                              "OK"
#define RSP_ERROR                           "ERROR"

#define SIM_APN                             ""  // Set valid SIM APN
#define PHONE_NUMBER_TO_MESSAGE             ""  // Set Phone number to message
#define MESSAGE_CONTENT                     "LTE IoT Click"   // Messege content 

#define PROCESS_BUFFER_SIZE                 500

#define WAIT_FOR_CONNECTION                 0
#define CONNECTED_TO_NETWORK                1

static lteiot_t lteiot;
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;

static uint8_t app_connection_status        = WAIT_FOR_CONNECTION;

static err_t app_error_flag;

/**
 * @brief LTE IoT clearing application buffer.
 * @details This function clears memory of application buffer and reset its length and counter.
 * @note None.
 */
static void lteiot_clear_app_buf ( void );

/**
 * @brief LTE IoT data reading function.
 * @details This function reads data from device and concats data to application buffer.
 * 
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot_process ( void );

/**
 * @brief LTE IoT check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 * @note None.
 */
static void lteiot_error_check( err_t error_flag );

/**
 * @brief LTE IoT logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void lteiot_log_app_buf ( void );

/**
 * @brief LTE IoT response check.
 * @details This function checks for response and returns the status of response.
 * 
 * @return application status.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot_rsp_check ( void );

/**
 * @brief LTE IoT chek connection.
 * @details This function checks connection to the network and 
 *          logs that status to UART.
 * 
 * @note None.
 */
static void lteiot_check_connection( void );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot_cfg_t lteiot_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 " );
    Delay_ms( 1000 );
    
    // Click initialization.
    lteiot_cfg_setup( &lteiot_cfg );
    LTEIOT_MAP_MIKROBUS( lteiot_cfg, MIKROBUS_1 );
    err_t init_flag  = lteiot_init( &lteiot, &lteiot_cfg );
    if ( init_flag == UART_ERROR )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    log_info( &logger, " Power on device... " );
    lteiot_power_on( &lteiot );
    
    // dummy read
    lteiot_process( );
    lteiot_clear_app_buf( );
    
    // AT
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_AT );
    app_error_flag = lteiot_rsp_check( );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // ATI - product information
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_ATI );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGMR - firmware version
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_CGMR );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - deregister from network
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_COPS, "2" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGDCONT - set sim apn
    lteiot_set_sim_apn( &lteiot, SIM_APN );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
     
    // CFUN - full funtionality
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_CFUN, "1" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - automatic mode
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_COPS, "0" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 2000 );
    
    // CEREG - network registration status
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_CEREG, "2" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CIMI - request IMSI
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_CIMI );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    app_buf_len = 0;
    app_buf_cnt = 0;
    app_connection_status = WAIT_FOR_CONNECTION;
    log_info( &logger, " Application Task " );
    Delay_ms( 5000 );
}

void application_task ( void )
{  
    if ( app_connection_status == WAIT_FOR_CONNECTION )
    {
        // CGATT - request IMSI
        lteiot_send_cmd_check( &lteiot, LTEIOT_CMD_CGATT );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CEREG - network registration status
        lteiot_send_cmd_check( &lteiot, LTEIOT_CMD_CEREG );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CSQ - signal quality
        lteiot_send_cmd( &lteiot, LTEIOT_CMD_CSQ );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 5000 );
    }
    else
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
        
        // SMS message format - text mode
        lteiot_send_cmd_with_parameter( &lteiot, "AT+CMGF", "1" );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 3000 );
        
        for( ; ; )
        {   
            log_printf( &logger, "> Sending message to phone number...\r\n" );
            lteiot_send_text_message( &lteiot, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
            app_error_flag = lteiot_rsp_check(  );
            lteiot_error_check( app_error_flag );
            Delay_ms( 10000 );
            Delay_ms( 10000 );
            Delay_ms( 10000 );
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

static void lteiot_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
    app_buf_cnt = 0;
}

static err_t lteiot_process ( void )
{
    err_t return_flag = APP_ERROR_DRIVER;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = lteiot_generic_read( &lteiot, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 )
    { 
        int32_t buf_cnt = 0;
        return_flag = APP_OK;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lteiot_clear_app_buf(  );
            return_flag = APP_ERROR_OVERFLOW;
        }
        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_buff[ rx_cnt ] != 0 ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
                buf_cnt--;
            }
        }
    } 

    return return_flag;
}

static err_t lteiot_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;
    
    err_t error_flag = lteiot_process(  );
    
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }
    
    while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
    {
        error_flag = lteiot_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }
        
        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
            {
                lteiot_send_cmd( &lteiot, LTEIOT_CMD_AT );
                lteiot_process(  );
                Delay_ms( 100 );
            }
            lteiot_clear_app_buf(  );
            return APP_ERROR_TIMEOUT;
        }
        
        Delay_ms( 1 );
    }
    
    lteiot_check_connection();
    
    lteiot_log_app_buf();
    
    log_printf( &logger, "-----------------------------------\r\n" );
    
    return APP_OK;
}

static void lteiot_error_check( err_t error_flag )
{
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        switch ( error_flag )
        {
            case -2:
                log_error( &logger, " Overflow!" );
                break;
            case -3:
                log_error( &logger, " Timeout!" );
                break;
            default:
                break;
        }
    }
}

static void lteiot_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 ] );
    }
    log_printf( &logger, "\r\n" );
    lteiot_clear_app_buf(  );
}

static void lteiot_check_connection( void )
{
    #define CONNECTED "+CGATT: 1"
    
    if ( strstr( app_buf, CONNECTED ) != 0 )
    {
        app_connection_status = CONNECTED_TO_NETWORK;
    }
}

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

额外支持

资源

喜欢这个项目吗?

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