享受高质量音频和数据传输,无限制。
A
A
硬件概览
它是如何工作的?
BLE 12 Click基于BM832A,这是一款高度灵活、超低功耗的蓝牙模块,为任何嵌入式应用提供BLE连接,由Fanstel提供。BM832A模块基于Nordic nRF52 SoC,集成了64MHz的32位ARM Cortex M4处理器,具有浮点单元(FPU)和2.4GHz多协议无线电(支持蓝牙5.0和集成PCB天线),具有-96dBm RX灵敏度(取决于数据速率),以及192kB的Flash内存和24kB的RAM。BLE 12 Click允许使用UART和SPI接口,常用的UART RX和TX引脚作为默认通信协议,用于以默认配置的115200 bps速度传输和交换AT命令,以便与主机MCU进行数据传输和交换。可以通过将标记为COMM SEL的SMD跳线置于适当位置来进行选择。注意,所有跳线的位置必须在同一侧,否则
Click board™可能会无响应。mikroBUS™的PWM引脚上的CMD引脚代表通信激活功能。CMD引脚的高逻辑状态允许模块与MCU通信,而低状态允许数据透明地发送到远端设备(例如智能手机)。在选择UART接口的情况下,可以通过发送命令"AT+STOP"来减少功耗。CS引脚必须设置为低逻辑状态200μs或更长时间,以唤醒UART接口。此外,它还有一个额外的数据就绪信号,标记为REQ,并连接到mikroBUS™插座的INT引脚,表示有新数据准备好供主机使用。此Click board™通过了全球范围内的监管认证,提供了增强的性能、安全性和可靠性,以支持在蓝牙网络上运行的物联网产品。此外,在BLE 12 Click的中心,还有一个额外的未填充的头部,提供了完全的
调试和编程支持。通过这个头部,用户可以使用串行线调试接口进行编程和调试,通过SWD接口引脚(SWDIO,SWCLK和SWO)提供。除了适当的接口外,此Click board™还具有一些额外的功能。一个连接到mikroBUS™插座RST引脚的复位按钮将模块置于复位状态,而两个额外的LED指示灯,标记为LED1和LED2的黄色和红色LED,可以用于可选的用户配置的视觉指示。此Click board™只能在3.3V逻辑电压水平下运行。因此,在使用不同逻辑电平的MCU之前,必须进行适当的逻辑电压电平转换。此外,此Click board™配备了包含函数和示例代码的库,可用作进一步开发的参考。
功能概述
开发板
EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。
EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和
基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。
微控制器概述
MCU卡片 / MCU
建筑
PIC
MCU 内存 (KB)
32
硅供应商
Microchip
引脚数
28
RAM (字节)
3648
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
原理图
一步一步来
项目组装
实时跟踪您的结果
应用输出通过UART模式
1. 一旦代码示例加载完成,按下 "FLASH" 按钮将启动构建过程,并将其编程到创建的设置上。
2. 编程完成后,点击右上角面板中的工具图标,选择 UART 终端
3. 打开 UART 终端标签后,首先在选项菜单中检查波特率设置(默认是 115200)。如果该参数正确,通过点击 "CONNECT" 按钮激活终端。
4. 现在,终端状态从 Disconnected 变为绿色的 Connected,数据将显示在 Received data 字段中。
软件支持
库描述
该库包含 BLE 12 Click 驱动程序的 API。
关键功能:
ble12_set_device_name
- BLE 12 设置设备名称功能ble12_set_op_mode
- BLE 12 设置操作模式功能ble12_send_cmd
- BLE 12 发送命令功能
开源
代码示例
这个示例可以在 NECTO Studio 中找到。欢迎下载代码,或者您也可以复制下面的代码。
/*!
* @file main.c
* @brief BLE 12 Click Example.
*
* # Description
* This example reads and processes data from BLE 12 Click board™.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes UART driver and logs UART.
* After driver initialization, the app performs a wake-up module,
* enters command mode, sets the device name and advertising time interval,
* and disconnects all connections.
* After that, the blinking of the yellow LED Indicates
* that the BLE 12 Click board™ is ready for connection.
* After establishing the connection, the yellow LED is turned on.
*
* ## Application Task
* This example demonstrates the use of the BLE 12 Click board™.
* Reads the received data and parses it.
* Results are being sent to the Usart Terminal, where you can track their changes.
*
* ## Additional Function
* - static void ble12_clear_app_buf ( void )
* - static err_t ble12_process ( void )
*
* @note
* We have used the Serial Bluetooth Terminal Android application for the test
* and you can find it at the link:
* https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal
*
* @author Nenad Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "ble12.h"
#define PROCESS_BUFFER_SIZE 200
#define RSP_TIMEOUT 100
static ble12_t ble12;
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;
/**
* @brief BLE 12 clearing application buffer.
* @details This function clears memory of application buffer and reset it's length and counter.
* @note None.
*/
static void ble12_clear_app_buf ( void );
/**
* @brief BLE 12 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.
* @li @c -2 - Application buffer overflow.
*
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t ble12_process ( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
ble12_cfg_t ble12_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.
ble12_cfg_setup( &ble12_cfg );
BLE12_MAP_MIKROBUS( ble12_cfg, MIKROBUS_1 );
if ( UART_ERROR == ble12_init( &ble12, &ble12_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( BLE12_ERROR == ble12_default_cfg ( &ble12 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
app_buf_len = 0;
app_buf_cnt = 0;
Delay_ms( 100 );
log_info( &logger, " Application Task " );
log_printf( &logger, "-------------------------------\r\n" );
log_printf( &logger, "\t BLE 12 Click\r\n" );
log_printf( &logger, "-------------------------------\r\n" );
log_printf( &logger, "\t Command mode\r\n" );
ble12_set_op_mode( &ble12, BLE12_OP_MODE_CMD );
Delay_ms( 100 );
ble12_event_startup( &ble12 );
Delay_ms( 100 );
ble12_set_led_state( &ble12, BLE12_LED_RED, BLE12_LED_OFF );
ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_OFF );
Delay_ms( 100 );
log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
log_printf( &logger, "> Set device name:" );
log_printf( &logger, " BLE 12 Click\r\n" );
ble12_set_device_name( &ble12, "BLE 12 Click" );
Delay_ms( 100 );
log_printf( &logger, "> Set Adv. Interval: 99 ms\r\n" );
ble12_set_adv_interval( &ble12, "0099" );
Delay_ms( 100 );
log_printf( &logger, "> Disconnect all connections\r\n" );
ble12_disconnect( &ble12 );
Delay_ms( 100 );
log_printf( &logger, "-------------------------------\r\n" );
log_printf( &logger, " Please connect your device\r\n" );
do
{
ble12_process();
ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_ON );
Delay_ms( 50 );
ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_OFF );
Delay_ms( 50 );
}
while ( !strstr( app_buf, BLE12_EVT_CONNECTED ) );
Delay_ms( 100 );
ble12_set_led_state( &ble12, BLE12_LED_RED, BLE12_LED_OFF );
ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_ON );
log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
log_printf( &logger, "\tDevice connected\r\n" );
Delay_ms( 100 );
ble12_set_op_mode( &ble12, BLE12_OP_MODE_DATA );
log_printf( &logger, "-------------------------------\r\n" );
log_printf( &logger, "\t Data mode\r\n" );
log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
Delay_ms( 100 );
ble12_process();
ble12_clear_app_buf( );
Delay_ms( 100 );
}
void application_task ( void )
{
ble12_process();
if ( app_buf_len > 0 )
{
log_printf( &logger, "%s", app_buf );
ble12_clear_app_buf( );
}
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
static void ble12_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t ble12_process ( void )
{
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = ble12_generic_read( &ble12, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
{
ble12_clear_app_buf( );
return BLE12_ERROR;
}
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 ) && ( rx_buff[ rx_cnt ] != 0x2B ) )
{
app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
}
else
{
app_buf_len--;
buf_cnt--;
}
}
return BLE12_OK;
}
return BLE12_ERROR;
}
// ------------------------------------------------------------------------ END