中级
20 分钟

使用BT840和TM4C1299KCZAD控制智能家居设备和家电

基于nRF52840 SoC的高要求物联网应用的蓝牙低功耗(BLE)连接

BT840 Click with Fusion for Tiva v8

已发布 1月 20, 2025

点击板

BT840 Click

开发板

Fusion for Tiva v8

编译器

NECTO Studio

微控制器单元

TM4C1299KCZAD

为物联网设备提供安全且远距离的蓝牙低功耗 (Bluetooth LE) 连接

A

A

硬件概览

它是如何工作的?

BT840 Click 基于 Fanstel 的 BT840,这是一款超低功耗的蓝牙低能耗 (BLE) 模块,专为满足现代物联网应用的苛刻需求而设计。它集成了 Nordic Semiconductor 的 nRF52840 QIAA SoC,该 SoC 配备强大的 Cortex M4F MCU,拥有 1MB 的闪存和 256KB 的 RAM。此外,该模块还包括 ARM® TrustZone® Cryptocell-310 协处理器,确保敏感数据的强大行业级安全性。它通过标准 UART 接口与主 MCU 通信,简化了集成,便于开发高性能、低功耗的物联网系统。BT840 模块是一个完整的射频解决方案,配备嵌入式 2.4GHz 多协议收发器并支持 NFC 功能,使其适用于广泛的物联网用例。集成的 PCB 路径天线可实现可靠的通信,最大传输功率为 +4.9dBm,支持长距离性能。根据数据速率,它可以在 1Mbps 下实现高达 150 米的通信范围,在 

125kbps 下实现高达 210 米的通信范围,为各种应用提供了卓越的灵活性。BT840 Click 非常适合需要高效且安全无线通信的物联网设备,支持超低功耗、长距离连接和高吞吐量。其先进功能(包括加密加速器)确保了数据传输的安全性和可靠性,满足工业、商业和消费物联网应用的关键需求。正如前述,BT840 Click 通过 UART 接口与主 MCU 通信,使用 TX 和 RX 引脚以默认波特率 115200bps 进行数据交换。除了 UART 接口外,板上还提供专用控制引脚以增强功能:WUP 引脚通过切换逻辑状态唤醒模块,而 CMD 引脚通过设置为高电平启用命令模式。BT840 Click 还包括一个外部 NFC 天线 u.Fl 接口,支持高级近场通信 (NFC) 功能。模块的 NFC 块支持 NFC-A 标签,允许从低功耗模式进行近距离检测和场唤醒功能。这一特性通过实现 Out-Of-Band (OOB) 蓝牙配对

简化了设备配对,优化了物联网系统的部署。此外,该板具有一个未焊接的 6 针接头,用于直接访问模块的 GPIO 信号,提供了灵活性以进行自定义配置和扩展功能。板上还配备了四个红色 LED 指示灯(LED1-LED4),可配置为用户特定的应用,另有两个按钮:一个 RST 按钮用于重置模块,另一个通用 BTN 按钮用于额外功能。为了实现串行线调试,SWDIO 连接引脚可用于调试和开发。在板的背面有低功耗 (LP) 断开跳线,通过切断这些跳线,可以断开 LED 和 ClickID 部分的电源,大大降低功耗,在对能耗敏感的应用中实现高效运行。该 Click 板™ 仅可在 3.3V 逻辑电压下运行。在使用其他逻辑电平的 MCU 之前,必须进行适当的逻辑电压电平转换。此外,该 Click 板™ 配备了功能库和示例代码,可用作进一步开发的参考。

BT840 Click hardware overview image

功能概述

开发板

Fusion for TIVA v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持广泛的微控制器,如不同的32位ARM® Cortex®-M基础MCUs,来自Texas Instruments,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次通过WiFi网络实现的嵌入式调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,Fusion for TIVA v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何

时候都能访问。Fusion for TIVA v8开发板的每个部分都包含了使同一板块运行最高效的必要组件。一个先进的集成CODEGRIP程序/调试模块提供许多有价值的编程/调试选项,包括对JTAG、SWD和SWO Trace(单线输出)的支持,并与Mikroe软件环境无缝集成。此外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB HOST/DEVICE、CAN(如果MCU卡支持的话)和以

太网也包括在内。此外,它还拥有广受好评的 mikroBUS™标准,为MCU卡提供了标准化插座(SiBRAIN标准),以及两种显示选项,用于TFT板线产品和基于字符的LCD。Fusion for TIVA v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

Fusion for Tiva v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

类型

8th Generation

建筑

ARM Cortex-M4

MCU 内存 (KB)

512

硅供应商

Texas Instruments

引脚数

212

RAM (字节)

262144

使用的MCU引脚

mikroBUS™映射器

Module Wake-Up
PE3
AN
Reset
PB6
RST
ID COMM
PE7
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Command Mode Control
PD0
PWM
NC
NC
INT
UART TX
PA1
TX
UART RX
PA0
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

BT840 Click Schematic schematic

一步一步来

项目组装

Fusion for PIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以Fusion for Tiva v8作为您的开发板开始

Fusion for PIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
v8 SiBRAIN 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image 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”替换为要显示的参数。

软件支持

库描述

BT840 Click 演示应用程序使用 NECTO Studio开发,确保与 mikroSDK 的开源库和工具兼容。该演示设计为即插即用,可与所有具有 mikroBUS™ 插座的 开发板、入门板和 mikromedia 板完全兼容,用于快速实现和测试。

示例描述
本示例展示了如何使用 BT840 Click 板,通过处理来自连接的蓝牙 (BT) 设备的数据。

关键功能:

  • bt840_cfg_setup - 配置对象初始化函数。

  • bt840_init - 初始化函数。

  • bt840_cmd_run - 此函数向 Click 模块发送指定的命令。

  • bt840_cmd_set - 此函数向 Click 模块的指定命令设置一个值。

  • bt840_cmd_get - 此函数用于从 Click 模块的指定命令获取值。

应用初始化
初始化驱动程序和日志记录器。

应用任务
应用任务分为以下几个阶段:

  • BT840_POWER_UP: - 启动设备并读取系统信息。

  • BT840_CONFIG_EXAMPLE: - 设置 BT 设备名称。

  • BT840_EXAMPLE: - 执行一个 BT 终端示例,通过处理来自连接的 BT 设备的所有数据并发送适当的响应消息。

开源

代码示例

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

/*!
 * @file main.c
 * @brief BT840 Click Example.
 *
 * # Description
 * This example demonstrates the use of BT840 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:
 *  - BT840_POWER_UP:
 * Powers up the device and reads the system information.
 *  - BT840_CONFIG_EXAMPLE:
 * Sets the BT device name.
 *  - BT840_EXAMPLE:
 * Performs a BT terminal example by processing all data from a connected BT device 
 * and sending back an adequate response messages.
 *
 * ## Additional Function
 * - static void bt840_clear_app_buf ( void )
 * - static void bt840_log_app_buf ( void )
 * - static err_t bt840_process ( bt840_t *ctx )
 * - static err_t bt840_read_response ( bt840_t *ctx, uint8_t *rsp )
 * - static err_t bt840_power_up ( bt840_t *ctx )
 * - static err_t bt840_config_example ( bt840_t *ctx )
 * - static err_t bt840_example ( bt840_t *ctx )
 *
 * @note
 * We have used the Serial Bluetooth Terminal smartphone application for the test. 
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "bt840.h"
#include "generic_pointer.h"

// Message content
#define MESSAGE_CONTENT     "BT840 Click board - demo example."

// Local device name.
#define DEVICE_NAME         "BT840 Click"

static bt840_t bt840;
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
{
    BT840_POWER_UP = 1,
    BT840_CONFIG_EXAMPLE,
    BT840_EXAMPLE

} bt840_app_state_t;

static bt840_app_state_t app_state = BT840_POWER_UP;

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

/**
 * @brief BT840 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void bt840_log_app_buf ( void );

/**
 * @brief BT840 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #bt840_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 bt840_process ( bt840_t *ctx );

/**
 * @brief BT840 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 #bt840_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 bt840_read_response ( bt840_t *ctx, uint8_t *rsp );

/**
 * @brief BT840 power up function.
 * @details This function powers up the device, and reads the system information.
 * @param[in] ctx : Click context object.
 * See #bt840_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 bt840_power_up ( bt840_t *ctx );

/**
 * @brief BT840 config example function.
 * @details This function sets the BT device name.
 * @param[in] ctx : Click context object.
 * See #bt840_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 bt840_config_example ( bt840_t *ctx );

/**
 * @brief BT840 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 #bt840_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 bt840_example ( bt840_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    bt840_cfg_t bt840_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.
    bt840_cfg_setup( &bt840_cfg );
    BT840_MAP_MIKROBUS( bt840_cfg, MIKROBUS_1 );
    if ( UART_ERROR == bt840_init( &bt840, &bt840_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

    app_state = BT840_POWER_UP;
    log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}

void application_task ( void ) 
{
    switch ( app_state )
    {
        case BT840_POWER_UP:
        {
            if ( BT840_OK == bt840_power_up( &bt840 ) )
            {
                app_state = BT840_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case BT840_CONFIG_EXAMPLE:
        {
            if ( BT840_OK == bt840_config_example( &bt840 ) )
            {
                app_state = BT840_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case BT840_EXAMPLE:
        {
            bt840_example( &bt840 );
            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 bt840_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void bt840_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 bt840_process ( bt840_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = bt840_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 BT840_OK;
    }
    return BT840_ERROR;
}

static err_t bt840_read_response ( bt840_t *ctx, uint8_t *rsp ) 
{
    #define READ_RESPONSE_TIMEOUT_MS 30000
    uint32_t timeout_cnt = 0;
    bt840_clear_app_buf ( );
    bt840_process( ctx );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, BT840_RSP_FAIL ) ) )
    {
        bt840_process( ctx );
        if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
        {
            bt840_log_app_buf( );
            bt840_clear_app_buf( );
            log_error( &logger, " Timeout!" );
            return BT840_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 200 );
    bt840_process( ctx );
    bt840_log_app_buf( );
    if ( strstr( app_buf, rsp ) )
    {
        log_printf( &logger, "--------------------------------\r\n" );
        return BT840_OK;
    }
    return BT840_ERROR_CMD;
}

static err_t bt840_power_up ( bt840_t *ctx )
{
    err_t error_flag = BT840_OK;
    
    log_printf( &logger, ">>> Reset device.\r\n" );
    bt840_set_cmd_mode( &bt840 );
    bt840_reset_device( &bt840 );
    bt840_wakeup_device( &bt840 );
    while ( BT840_OK == bt840_process( ctx ) )
    {
        bt840_log_app_buf( );
        bt840_clear_app_buf ( );
    }
    log_printf( &logger, "--------------------------------\r\n" );

    log_printf( &logger, ">>> Factory reset.\r\n" );
    bt840_cmd_run( &bt840, BT840_CMD_DEFAULT_RESET );
    error_flag |= bt840_read_response( &bt840, BT840_RSP_OK );

    log_printf( &logger, ">>> Check communication.\r\n" );
    bt840_cmd_run( &bt840, BT840_CMD_AT );
    error_flag |= bt840_read_response( &bt840, BT840_RSP_OK );

    log_printf( &logger, ">>> Get software version.\r\n" );
    bt840_cmd_get( ctx, BT840_CMD_GET_SW_VERSION );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );

    log_printf( &logger, ">>> Get MAC address.\r\n" );
    bt840_cmd_get( ctx, BT840_CMD_GET_MAC );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );

    return error_flag;
}

static err_t bt840_config_example ( bt840_t *ctx )
{
    err_t error_flag = BT840_OK;

    log_printf( &logger, ">>> Set device name to \"%s\".\r\n", ( char * ) DEVICE_NAME );
    bt840_cmd_set( ctx, BT840_CMD_DEVICE_NAME, DEVICE_NAME );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, ">>> Save settings.\r\n" );
    bt840_cmd_set( &bt840, BT840_CMD_SAVE_SETTINGS, "1" );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );
    
    log_printf( &logger, ">>> Reboot.\r\n" );
    bt840_cmd_run( ctx, BT840_CMD_RESET );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );
    
    return error_flag;
}

static err_t bt840_example ( bt840_t *ctx )
{
    err_t error_flag = BT840_OK;
    uint32_t timeout_cnt = 0;
    uint8_t data_len = 0;
    uint8_t byte_cnt = 0;
    uint8_t * __generic_ptr start_ptr = NULL;

    #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"
    
    log_printf( &logger, ">>> Waiting for a BT peer to establish connection with the Click board...\r\n" );
    for ( ; ; )
    {
        bt840_clear_app_buf( );
        if ( BT840_OK == bt840_process( ctx ) )
        {
            Delay_ms ( 200 );
            bt840_process( ctx );
            bt840_log_app_buf( );
            if ( strstr( app_buf, BT840_RSP_CONNECTED ) )
            {
                log_printf( &logger, "--------------------------------\r\n" );
                log_printf( &logger, ">>> BT peer has connected.\r\n" );
                bt840_set_data_mode( &bt840 );
                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 ( ; ; )
    {
        bt840_clear_app_buf( );
        if ( BT840_OK == bt840_process( ctx ) )
        {
            Delay_ms ( 100 );
            timeout_cnt = 0;
            bt840_process( ctx );
            bt840_log_app_buf( );
            start_ptr = strstr( app_buf, BT840_RSP_RECEIVE );
            if ( start_ptr )
            {
                start_ptr += strlen ( BT840_RSP_RECEIVE );
                data_len = *start_ptr;
                log_printf( &logger, "<<< Received data (HEX): " );
                for ( byte_cnt = 0; byte_cnt < data_len; byte_cnt++ )
                {
                    log_printf( &logger, "0x%.2X ", *( start_ptr + byte_cnt + 1 ) );
                }
                log_printf( &logger, "\r\n" );
                log_printf( &logger, "<<< Received data (STR): %s", ( start_ptr + 1 ) );
                log_printf( &logger, "--------------------------------\r\n" );
            }
            if ( strstr( app_buf, TERMINATION_CMD ) )
            {
                log_printf( &logger, ">>> Terminating connection on demand.\r\n" );
                data_len = strlen ( TERMINATION_RESPONSE ) + strlen ( NEW_LINE_STRING );
                bt840_generic_write ( ctx, &data_len, 1 );
                bt840_generic_write ( ctx, TERMINATION_RESPONSE, strlen ( TERMINATION_RESPONSE ) );
                bt840_generic_write ( ctx, NEW_LINE_STRING, strlen ( NEW_LINE_STRING ) );
                Delay_ms ( 100 );
                error_flag |= bt840_read_response( ctx, BT840_RSP_SEND );

                log_printf( &logger, ">>> Disconnecting BT peer.\r\n" );
                bt840_set_cmd_mode( &bt840 );
                bt840_cmd_set( ctx, BT840_CMD_DISCONNECT, "1" );
                error_flag |= bt840_read_response( ctx, BT840_RSP_DISCONNECTED );
                break;
            }
            else if ( strstr( app_buf, BT840_RSP_DISCONNECTED ) )
            {
                log_printf( &logger, ">>> BT peer has disconnected.\r\n" );
                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 );
            data_len = strlen ( MESSAGE_CONTENT ) + strlen ( NEW_LINE_STRING );
            bt840_generic_write ( ctx, &data_len, 1 );
            bt840_generic_write ( ctx, MESSAGE_CONTENT, strlen ( MESSAGE_CONTENT ) );
            bt840_generic_write ( ctx, NEW_LINE_STRING, strlen ( NEW_LINE_STRING ) );
            Delay_ms ( 100 );
            error_flag |= bt840_read_response( ctx, BT840_RSP_SEND );
        }
        if ( BT_TERMINAL_TIMEOUT_MS < timeout_cnt )
        {
            log_printf( &logger, ">>> Terminating connection due to 60s timeout expiration.\r\n" );
            data_len = strlen ( TERMINATION_TIMEOUT ) + strlen ( NEW_LINE_STRING );
            bt840_generic_write ( ctx, &data_len, 1 );
            bt840_generic_write ( ctx, TERMINATION_TIMEOUT, strlen ( TERMINATION_TIMEOUT ) );
            bt840_generic_write ( ctx, NEW_LINE_STRING, strlen ( NEW_LINE_STRING ) );
            Delay_ms ( 100 );
            error_flag |= bt840_read_response( ctx, BT840_RSP_SEND );

            log_printf( &logger, ">>> Disconnecting BT peer.\r\n" );
            bt840_set_cmd_mode( &bt840 );
            bt840_cmd_set( ctx, BT840_CMD_DISCONNECT, "1" );
            error_flag |= bt840_read_response( ctx, BT840_RSP_DISCONNECTED );
            break;
        }
        Delay_ms ( 1 );
    }

    log_printf( &logger, ">>> Reboot.\r\n" );
    bt840_cmd_run( ctx, BT840_CMD_RESET );
    error_flag |= bt840_read_response( ctx, BT840_RSP_OK );
    
    return error_flag;
}

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

额外支持

资源

喜欢这个项目吗?

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