蓝牙LE通信,具有双角色连接和EMI保护,非常适合智能家居、远程监控以及物联网系统中的室内定位应用
A
A
硬件概览
它是如何工作的?
RYB080I Click 基于 RYB080I,这是来自 REYAX 的 2.4GHz 蓝牙 4.2/5.0 低功耗 (LE) 模块,集成天线,专为与智能手机及各种蓝牙设备的无缝连接而设计。该模块基于 TI CC2640R2F ARM® Cortex®-M3 微控制器,这是一款以高效性能和可靠性著称的行业标准芯片,支持双连接功能,可同时与两个蓝牙设备保持通信。它同时支持主机和客户端角色,具有极高的无线通信场景适应性。凭借其强大的功能,此 Click 板™ 非常适合远程监控和控制应用、智能家居系统以及室内定位解决方案。模块的一个重要优势是集成金属屏蔽罩,可防止电磁干扰 (EMI),即使在信号噪声较大的环境中,也能确保稳定可靠的运行。它基于广泛采用的通用属性配置文件 (GATT),能够与蓝牙低功耗
设备顺畅交互。通过 REYAX 开发的 AT 指令,控制和配置变得简单,便于集成到各种项目中。RYB080I 通过了 FCC CFR47 Part 15(美国)、NCC(台湾)和 MIC(日本)的认证,符合严格的国际标准,为全球应用提供合规性和可靠性。此 Click 板™ 采用支持 MIKROE 新推出的 “Click Snap” 功能的独特格式设计。与标准化的 Click 板不同,该功能允许通过折断 PCB 将主传感器区域变为可移动,开辟了许多新的实施可能性。得益于 Snap 功能,RYB080I 可通过直接访问标记为 1-8 的引脚实现自主运行。此外,Snap 部分包括一个指定的固定螺孔位置,用户可以将 Snap 板固定在所需位置。关于板载连接功能,此 Click 板™ 使用 UART 接口与主 MCU 通信,通过标
准的 UART RX 和 TX 引脚交换 AT 指令。默认情况下,它以 115200bps 的波特率通信。此外,还提供未焊接的 JTAG 接口引脚,以完全支持调试和编程。该接口允许用户使用 JTAG(联合测试行动组)行业标准,通过这些 JTAG 引脚进行编程和调试。除了通信和控制引脚外,此 Click 板™ 还包括一个复位引脚 (RST) 和一个 RESET 按钮,便于模块复位,以及六个测试点连接到模块的通用 I/O 引脚,支持进一步定制。此 Click 板™ 只能在 3.3V 逻辑电压水平下运行。在使用不同逻辑电平的 MCU 之前,必须进行适当的逻辑电压电平转换。此外,它还配备了包含易于使用的功能和示例代码的库,可作为进一步开发的参考。
功能概述
开发板
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)
128
硅供应商
Microchip
引脚数
40
RAM (字节)
3728
使用的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”替换为要显示的参数。

软件支持
库描述
该库包含 RYB080I Click 驱动程序的 API。
关键功能:
ryb080i_cmd_run
- 此功能向点击模块发送指定命令。ryb080i_cmd_set
- 此功能为点击模块的指定命令设置一个值。ryb080i_cmd_get
- 此功能用于从点击模块获取给定命令的值。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief RYB080I Click Example.
*
* # Description
* This example demonstrates the use of RYB080I click board by processing data
* from a connected BT device.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and logger.
*
* ## Application Task
* Application task is split in few stages:
* - RYB080I_POWER_UP:
* Powers up the device and reads the system information.
* - RYB080I_CONFIG_EXAMPLE:
* Sets the BT device name and enables the full power mode.
* - RYB080I_EXAMPLE:
* Performs a BT terminal example by processing all data from connected BT devices
* and sending back an adequate response messages.
*
* ## Additional Function
* - static void ryb080i_clear_app_buf ( void )
* - static void ryb080i_log_app_buf ( void )
* - static err_t ryb080i_process ( ryb080i_t *ctx )
* - static err_t ryb080i_read_response ( ryb080i_t *ctx, uint8_t *rsp )
* - static err_t ryb080i_power_up ( ryb080i_t *ctx )
* - static err_t ryb080i_config_example ( ryb080i_t *ctx )
* - static err_t ryb080i_example ( ryb080i_t *ctx )
*
* @note
* We have used the Serial Bluetooth Terminal smartphone application for the test.
* A smartphone and the click board must be paired to exchange messages.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "ryb080i.h"
// Message content
#define MESSAGE_CONTENT "RYB080I click board - demo example."
// Local device name.
#define DEVICE_NAME "RYB080I click"
static ryb080i_t ryb080i;
static log_t logger;
// Application buffer size
#define APP_BUFFER_SIZE 600
#define PROCESS_BUFFER_SIZE 200
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
RYB080I_POWER_UP = 1,
RYB080I_CONFIG_EXAMPLE,
RYB080I_EXAMPLE
} ryb080i_app_state_t;
static ryb080i_app_state_t app_state = RYB080I_POWER_UP;
/**
* @brief RYB080I clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void ryb080i_clear_app_buf ( void );
/**
* @brief RYB080I log application buffer.
* @details This function logs data from application buffer to USB UART.
* @note None.
*/
static void ryb080i_log_app_buf ( void );
/**
* @brief RYB080I data reading function.
* @details This function reads data from device and concatenates data to application buffer.
* @param[in] ctx : Click context object.
* See #ryb080i_t object definition for detailed explanation.
* @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 ryb080i_process ( ryb080i_t *ctx );
/**
* @brief RYB080I read response function.
* @details This function waits for a response message, reads and displays it on the USB UART.
* @param[in] ctx : Click context object.
* See #ryb080i_t object definition for detailed explanation.
* @param[in] rsp Expected response.
* @return @li @c 0 - OK response.
* @li @c -2 - Timeout error.
* @li @c -3 - Command error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t ryb080i_read_response ( ryb080i_t *ctx, uint8_t *rsp );
/**
* @brief RYB080I power up function.
* @details This function powers up the device, and reads the system information.
* @param[in] ctx : Click context object.
* See #ryb080i_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t ryb080i_power_up ( ryb080i_t *ctx );
/**
* @brief RYB080I config example function.
* @details This function sets the BT device name and enables the full power mode.
* @param[in] ctx : Click context object.
* See #ryb080i_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t ryb080i_config_example ( ryb080i_t *ctx );
/**
* @brief RYB080I example function.
* @details This function performs a BT terminal example by processing all data from
* a connected BT device and sending back an adequate response messages.
* @param[in] ctx : Click context object.
* See #ryb080i_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t ryb080i_example ( ryb080i_t *ctx );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
ryb080i_cfg_t ryb080i_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.
ryb080i_cfg_setup( &ryb080i_cfg );
RYB080I_MAP_MIKROBUS( ryb080i_cfg, MIKROBUS_1 );
if ( UART_ERROR == ryb080i_init( &ryb080i, &ryb080i_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
app_state = RYB080I_POWER_UP;
log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}
void application_task ( void )
{
switch ( app_state )
{
case RYB080I_POWER_UP:
{
if ( RYB080I_OK == ryb080i_power_up( &ryb080i ) )
{
app_state = RYB080I_CONFIG_EXAMPLE;
log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
}
break;
}
case RYB080I_CONFIG_EXAMPLE:
{
if ( RYB080I_OK == ryb080i_config_example( &ryb080i ) )
{
app_state = RYB080I_EXAMPLE;
log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
}
break;
}
case RYB080I_EXAMPLE:
{
ryb080i_example( &ryb080i );
break;
}
default:
{
log_error( &logger, " APP STATE." );
break;
}
}
}
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 ryb080i_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static void ryb080i_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 ryb080i_process ( ryb080i_t *ctx )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t overflow_bytes = 0;
int32_t rx_cnt = 0;
int32_t rx_size = ryb080i_generic_read( ctx, 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 RYB080I_OK;
}
return RYB080I_ERROR;
}
static err_t ryb080i_read_response ( ryb080i_t *ctx, uint8_t *rsp )
{
#define READ_RESPONSE_TIMEOUT_MS 30000
uint32_t timeout_cnt = 0;
ryb080i_clear_app_buf ( );
ryb080i_process( ctx );
while ( 0 == strstr( app_buf, rsp ) )
{
ryb080i_process( ctx );
if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
{
ryb080i_clear_app_buf( );
log_error( &logger, " Timeout!" );
return RYB080I_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
Delay_ms ( 200 );
ryb080i_process( ctx );
if ( strstr( app_buf, rsp ) )
{
ryb080i_log_app_buf( );
log_printf( &logger, "--------------------------------\r\n" );
return RYB080I_OK;
}
ryb080i_log_app_buf( );
return RYB080I_ERROR_CMD;
}
static err_t ryb080i_power_up ( ryb080i_t *ctx )
{
err_t error_flag = RYB080I_OK;
log_printf( &logger, ">>> Reset device.\r\n" );
ryb080i_reset_device( &ryb080i );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_READY );
log_printf( &logger, ">>> Check communication.\r\n" );
ryb080i_cmd_run( &ryb080i, RYB080I_CMD_AT );
error_flag |= ryb080i_read_response( &ryb080i, RYB080I_RSP_OK );
log_printf( &logger, ">>> Get software version.\r\n" );
ryb080i_cmd_get( ctx, RYB080I_CMD_SW_VERSION );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_GENERIC );
log_printf( &logger, ">>> Get MAC address.\r\n" );
ryb080i_cmd_get( ctx, RYB080I_CMD_INQUIRE_MAC_ADDRESS );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_GENERIC );
return error_flag;
}
static err_t ryb080i_config_example ( ryb080i_t *ctx )
{
err_t error_flag = RYB080I_OK;
log_printf( &logger, ">>> Set broadcast name to \"%s\".\r\n", ( char * ) DEVICE_NAME );
ryb080i_cmd_set( ctx, RYB080I_CMD_BROADCAST_NAME, DEVICE_NAME );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
log_printf( &logger, ">>> Set device name to \"%s\".\r\n", ( char * ) DEVICE_NAME );
ryb080i_cmd_set( ctx, RYB080I_CMD_BROADCAST_NAME, DEVICE_NAME );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
log_printf( &logger, ">>> Software reset.\r\n" );
ryb080i_cmd_run( ctx, RYB080I_CMD_SW_RESET );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_READY );
#define FULL_POWER_MODE "0"
log_printf( &logger, ">>> Set full power mode.\r\n" );
ryb080i_cmd_set( ctx, RYB080I_CMD_POWER_MODE, FULL_POWER_MODE );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
return error_flag;
}
static err_t ryb080i_example ( ryb080i_t *ctx )
{
err_t error_flag = RYB080I_OK;
uint8_t * __generic_ptr urc_buf_ptr = 0;
uint8_t bt_peer_handle[ 2 ] = { 0 };
uint32_t timeout_cnt = 0;
#define BT_TERMINAL_TIMEOUT_MS 60000
#define BT_TERMINAL_MESSAGE_FREQ_MS 5000
#define TERMINATION_CMD "END"
#define TERMINATION_RESPONSE "END command received, the connection will be terminated in a few seconds."
#define TERMINATION_TIMEOUT "Timeout, closing the connection in a few seconds."
#define NEW_LINE_STRING "\r\n"
#define DISCONNECT_ALL_PEERS "0"
log_printf( &logger, ">>> Waiting for a BT peer to establish connection with the click board...\r\n" );
for ( ; ; )
{
ryb080i_clear_app_buf( );
if ( RYB080I_OK == ryb080i_process( ctx ) )
{
Delay_ms ( 200 );
ryb080i_process( ctx );
ryb080i_log_app_buf( );
if ( strstr( app_buf, RYB080I_RSP_CONNECTED ) )
{
urc_buf_ptr = strstr( app_buf, RYB080I_RSP_CONNECTED ) + strlen ( RYB080I_RSP_CONNECTED ) + 1;
bt_peer_handle[ 0 ] = *urc_buf_ptr;
log_printf( &logger, ">>> BT peer %s has connected.\r\n", bt_peer_handle );
break;
}
}
}
log_printf( &logger, ">>> Waiting for data (up to 60 seconds)...\r\n" );
log_printf( &logger, ">>> Connection will be terminated if the click receives an \"END\" string.\r\n" );
for ( ; ; )
{
ryb080i_clear_app_buf( );
if ( RYB080I_OK == ryb080i_process( ctx ) )
{
Delay_ms ( 200 );
timeout_cnt = 0;
ryb080i_process( ctx );
ryb080i_log_app_buf( );
if ( strstr( app_buf, TERMINATION_CMD ) )
{
log_printf( &logger, ">>> Terminating connection on demand.\r\n" );
ryb080i_cmd_run ( ctx, TERMINATION_RESPONSE );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
log_printf( &logger, ">>> Disconnecting all BT peers.\r\n" );
ryb080i_cmd_set ( ctx, RYB080I_CMD_DISCONNECT, DISCONNECT_ALL_PEERS );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_DISCONNECTED );
break;
}
else if ( strstr( app_buf, RYB080I_RSP_DISCONNECTED ) )
{
urc_buf_ptr = strstr( app_buf, RYB080I_RSP_DISCONNECTED ) + strlen ( RYB080I_RSP_DISCONNECTED ) + 1;
bt_peer_handle[ 0 ] = *urc_buf_ptr;
log_printf( &logger, ">>> BT peer %s has disconnected.\r\n", bt_peer_handle );
log_printf( &logger, ">>> Checking if there are more peers connected.\r\n" );
ryb080i_cmd_get ( ctx, RYB080I_CMD_CONNECTION_STATUS );
}
else if ( strstr( app_buf, RYB080I_RSP_CONNECTED ) )
{
urc_buf_ptr = strstr( app_buf, RYB080I_RSP_CONNECTED ) + strlen ( RYB080I_RSP_CONNECTED ) + 1;
bt_peer_handle[ 0 ] = *urc_buf_ptr;
log_printf( &logger, ">>> BT peer %s has connected.\r\n", bt_peer_handle );
}
else if ( strstr( app_buf, RYB080I_RSP_NO_CONNECTIONS ) )
{
break;
}
}
timeout_cnt++;
if ( 0 == ( timeout_cnt % BT_TERMINAL_MESSAGE_FREQ_MS ) )
{
log_printf( &logger, ">>> Sending \"%s\" message to connected device.\r\n", ( char * ) MESSAGE_CONTENT );
ryb080i_cmd_run ( ctx, MESSAGE_CONTENT );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
}
if ( BT_TERMINAL_TIMEOUT_MS < timeout_cnt )
{
log_printf( &logger, ">>> Terminating connection due to 60s timeout expiration.\r\n" );
ryb080i_cmd_run ( ctx, TERMINATION_TIMEOUT );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_OK );
log_printf( &logger, ">>> Disconnecting all BT peers.\r\n" );
ryb080i_cmd_set ( ctx, RYB080I_CMD_DISCONNECT, DISCONNECT_ALL_PEERS );
error_flag |= ryb080i_read_response( ctx, RYB080I_RSP_DISCONNECTED );
break;
}
Delay_ms ( 1 );
}
return error_flag;
}
// ------------------------------------------------------------------------ END