重新定义连接性,无缝连接设备,在您的物联网项目中实现新的控制和效率水平。
A
A
硬件概览
它是如何工作的?
NB IoT Click 基于 Quectel Wireless Solutions 的 BC95-G 模块,支持专为物联网应用开发的 LTE NB1 技术。它支持多个 NB 频段:B1、B3、B5、B8、B20 和 B28。该模块支持点对点的 MO 和 MT 消息,广泛用于 M2M 通信。其包含的协议集允许使用 NB1 技术进行数据和短信传输,并且具有超低功耗,使其成为构建物联网应用的理想选择。正如前面提到的,BC95-G 模块是 Click 板的主要组件,由多个内部块或部分组成,如 RF 收发器部分、Flash SRAM 部分、电源管理部分以及具有外围接口的蜂窝基带处理器。BC95 模块支持多个外围接口,包括两个 UART 接口(包括主 UART 和调试 UART 接口)、USIM 卡接口和 GPIO 接口。主 UART 接口可用于 AT 命令通信和数据传输,支持 9600 bps 的波特率。在固件升级时使用 115200 bps 的波特率。Quectel BC95 模块必须由干净稳定的电源供电。模块正常工作所需的电压为 4V,通过 MCP1826 从 5V mikroBUS™ 电源轨导出,MCP1826 是 Microchip 的 1A 低压降输出 (LDO) 稳压器。
尽管 Quectel BC95 模块是超低功耗设备,但其功耗有时会短暂峰值,因此需要使用 1A LDO。BC95 模块没有专用的 USB 接口,因此在 NB IoT Click 上添加了 USB 到 UART 电路,以提供 USB 到 UART 转换。使用了 FTDI 的 FT230X,这是一种高度集成的 USB-UART 桥接解决方案,具有紧凑的尺寸和所需的外部组件少的优点。两颗 LED 用于指示通过该 IC 的数据流量:标记为 TX 的红色 LED 表示 UART 传输,而标记为 RX 的黄色 LED 表示 UART 接收。该 Click 板配备了 micro USB 连接器,允许模块通过个人电脑供电和配置。Quectel Wireless Solutions 公司提供了一个软件套件,可以用于配置 BC95 模块。然而,FT230X IC 需要驱动程序才能工作。FTDI 提供了所有主要操作系统的驱动程序,具体可在其官方网站的驱动程序下载页面找到。Windows 操作系统的驱动程序也包含在下载部分。Click 板背面的 micro SIM 卡座用于安装 SIM 卡。没有有效的 SIM 卡,设备无法连接到蜂窝网络。BC95 模块的数字部分由集成的 LDO 稳压器供电,因此有必要
转换微控制器 (MCU) 通信线的逻辑电压电平。通过利用 LDO 输出(通过 MOSFET 开关电路路由),为 TXB0106 的一侧提供所需的参考电压,这是一种 6 位双向逻辑电压电平转换器。TXB0106 另一侧的参考电压取自 mikroBUS™ 的 3.3V 电源轨。一些信号级 MOSFET 组成的小型开关电路用于在 Click 板插入 mikroBUS™ 插座时关闭 FT230X,从而允许与主 MCU 的不间断通信。STAT 引脚用于指示设备状态。该引脚通过 TXB0106 电平转换器连接到 mikroBUS™ AN 引脚,并连接到标记为 STAT 的黄色 LED,用于直观地指示设备状态。通过将 mikroBUS™ 引脚的 RST 引脚拉到低电平,可以重置模块。该引脚通过内部上拉电阻上拉到高电平。除了硬件复位外,还可以使用 AT 命令复位模块。有关可用 AT 命令的更多信息,请参阅下载部分。然而,Click 板由 mikroSDK 库支持。该库包含简化软件开发的函数,将多个 AT 命令集成到单个函数调用中。使用 mikroSDK 使代码更加可读,但更重要的是,易于移植。
功能概述
开发板
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
你完善了我!
配件
LTE 平板旋转天线是提高 3G/4G LTE 设备性能的多功能选择。其宽频率范围为 700-2700MHz,确保在全球主要蜂窝频段上的最佳连接性。这款平板天线配有 SMA 公头连接器,可轻松直接连接到您的设备或 SMA 模块连接器。其突出特点之一是可调角度,可以以 45⁰ 为增量进行设置(0⁰/45⁰/90⁰),允许您微调天线的方向以实现最佳信号接收。该天线具有 50Ω 的阻抗和 <2.0:1 的电压驻波比 (VSW 比),确保可靠且高效的连接。其 5dB 增益、垂直极化和全向辐射图形增强了信号强度,适用于各种应用。天线长度为 196mm,宽度为 38mm,提供紧凑而有效的解决方案,以改善您的连接性。其最大输入功率为 50W,能够满足各种设备的需求。
使用的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”替换为要显示的参数。

软件支持
库描述
该库包含 NB IoT Click 驱动程序的 API。
关键功能:
nbiot_send_cmd
- 发送命令函数nbiot_power_on
- NB IoT 模块上电nbiot_generic_write
- NB IoT 数据写入函数
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* \file
* \brief NbIot Click example
*
* # Description
* This example reads and processes data from NB IoT clicks.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver, wake-up module and sets default configuration
* for connecting device to network.
*
* ## Application Task
* Waits for device to connect to network and then checks the signal quality
* every 5 seconds. All data is being logged on USB UART where you can track their changes.
*
* ## Additional Function
* - static void nbiot_clear_app_buf ( void )
* - static void nbiot_error_check( err_t error_flag )
* - static void nbiot_log_app_buf ( void )
* - static void nbiot_check_connection( void )
* - static err_t nbiot_rsp_check ( void )
* - static err_t nbiot_process ( void )
*
* @note
* In order for the example to work, a valid SIM card needs to be entered.
*
* @author MikroE Team
*
*/
// ------------------------------------------------------------------- INCLUDES
#include "board.h"
#include "log.h"
#include "nbiot.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 PROCESS_BUFFER_SIZE 500
#define WAIT_FOR_CONNECTION 0
#define CONNECTED_TO_NETWORK 1
static nbiot_t nbiot;
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 NB IoT clearing application buffer.
* @details This function clears memory of application buffer and reset its length and counter.
* @note None.
*/
static void nbiot_clear_app_buf ( void );
/**
* @brief NB 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 nbiot_process ( void );
/**
* @brief NB IoT check for errors.
* @details This function checks for different types of errors and logs them on UART.
* @note None.
*/
static void nbiot_error_check( err_t error_flag );
/**
* @brief NB IoT logs application buffer.
* @details This function logs data from application buffer.
* @note None.
*/
static void nbiot_log_app_buf ( void );
/**
* @brief NB 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 nbiot_rsp_check ( void );
/**
* @brief NB IoT chek connection.
* @details This function checks connection to the network and
* logs that status to UART.
*
* @note None.
*/
static void nbiot_check_connection( void );
// ------------------------------------------------------ APPLICATION FUNCTIONS
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
nbiot_cfg_t nbiot_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.
nbiot_cfg_setup( &nbiot_cfg );
NBIOT_MAP_MIKROBUS( nbiot_cfg, MIKROBUS_1 );
err_t init_flag = nbiot_init( &nbiot, &nbiot_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... " );
nbiot_power_on( &nbiot );
// dummy read
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
// AT
nbiot_send_cmd( &nbiot, NBIOT_CMD_AT );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// ATI - product information
nbiot_send_cmd( &nbiot, NBIOT_CMD_ATI );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// CGMR - firmware version
nbiot_send_cmd( &nbiot, NBIOT_CMD_CGMR );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 1000 );
// COPS - deregister from network
nbiot_send_cmd_with_parameter( &nbiot, NBIOT_CMD_COPS, "2" );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 1000 );
// CFUN - full funtionality
nbiot_send_cmd_with_parameter( &nbiot, NBIOT_CMD_CFUN, "1" );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// COPS - automatic mode
nbiot_send_cmd_with_parameter( &nbiot, NBIOT_CMD_COPS, "0" );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 2000 );
// CEREG - network registration status
nbiot_send_cmd_with_parameter( &nbiot, NBIOT_CMD_CEREG, "2" );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// CIMI - request IMSI
nbiot_send_cmd( &nbiot, NBIOT_CMD_CIMI );
app_error_flag = nbiot_rsp_check( );
nbiot_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
nbiot_send_cmd_check( &nbiot, NBIOT_CMD_CGATT );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// CEREG - network registration status
nbiot_send_cmd_check( &nbiot, NBIOT_CMD_CEREG );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 500 );
// CSQ - signal quality
nbiot_send_cmd( &nbiot, NBIOT_CMD_CSQ );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 5000 );
}
else
{
log_info( &logger, "CONNECTED TO NETWORK" );
log_info( &logger, "CHECKING SIGNAL QUALITY" );
nbiot_send_cmd( &nbiot, NBIOT_CMD_CSQ );
app_error_flag = nbiot_rsp_check( );
nbiot_error_check( app_error_flag );
Delay_ms( 5000 );
}
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
static void nbiot_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t nbiot_process ( void )
{
err_t return_flag = APP_ERROR_DRIVER;
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = nbiot_generic_read( &nbiot, 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 )
{
nbiot_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 nbiot_rsp_check ( void )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 20000;
err_t error_flag = nbiot_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 = nbiot_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 ) )
{
nbiot_send_cmd( &nbiot, NBIOT_CMD_AT );
nbiot_process( );
Delay_ms( 100 );
}
nbiot_clear_app_buf( );
return APP_ERROR_TIMEOUT;
}
Delay_ms( 1 );
}
nbiot_check_connection();
nbiot_log_app_buf();
log_printf( &logger, "-----------------------------------\r\n" );
return APP_OK;
}
static void nbiot_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 nbiot_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" );
nbiot_clear_app_buf( );
}
static void nbiot_check_connection( void )
{
#define CONNECTED "+CGATT:1"
if ( strstr( app_buf, CONNECTED ) != 0 )
{
app_connection_status = CONNECTED_TO_NETWORK;
}
}
// ------------------------------------------------------------------------ END