中级
30 分钟

使用 DA14531MOD 和 MK64FN1M0VDC12 构建下一代连接设备

使用 SmartBond TINY 释放物联网创新

BLE TINY click with Clicker 2 for Kinetis

已发布 6月 24, 2024

点击板

BLE TINY click

开发板

Clicker 2 for Kinetis

编译器

NECTO Studio

微控制器单元

MK64FN1M0VDC12

无缝集成BLE功能到物联网系统中,创建先进的连接设备,面向连接的消费者、医疗、智能家居和家电应用的前沿。

A

A

硬件概览

它是如何工作的?

BLE TINY Click基于DA14531MOD,这是一款基于全球最小、功耗最低的Dialog Semiconductor蓝牙5.1系统芯片(SoC)的SmartBond TINY™模块。DA14531基于强大的32位Arm Cortex-M0+,集成了内存以及模拟和数字外设。它配备了下一代Codeless软件,使得设计蓝牙应用程序无需蓝牙知识或高级编程技能,通过全面的AT命令集即可实现。该模块配备软件,以降低使用BLE技术的门槛。DA14531具有可配置的DSPS(串行端口服务)和下一代Codeless软件,设计蓝牙应用程序无需蓝牙知识或高级编程技能。它专门优化以显著降低为IoT系统添加蓝牙低能耗功能的成本。SmartBond TINY模块已通过全球认证,包括美洲的联邦通信委员会(FCC)

认证和欧洲的CE认证。BLE TINY Click使用单线UART接口作为与MCU通信的默认通信协议,用于与主机交换AT命令和数据传输。一个标记为1WIRE EN的开关用于激活这种通信,使模块能够通过单线UART接收和发送引脚或仅通过标准UART TX引脚建立通信。该Click板™使用74LVC1G3157多路复用器,以避免与由相同GPIO驱动的其他功能发生冲突。这样,用户可以使用P0_6引脚,该引脚具有双重功能,可用作UART TX引脚或用于ADC的模拟引脚。通过填充标记为P0_6 SEL的相应跳线选择该引脚的功能。DA14531预设有默认配置。然而,由于GPIO引脚数量少,多个功能被多路复用,并可通过板载跳线根据需要启用。用户还可以使用其他

接口,如SPI或I2C,通过填充相应跳线(P0_11和P0_9 SEL)自行配置模块并编写库。BLE TINY Click还提供带有SWDIO数据和SWCLK时钟信号的JTAG接口在J1头上。这样,用户可以通过JTAG接口为DA14531模块编程特定版本的Codeless软件。此外,通过将该引脚设置为高逻辑电平,可以通过mikroBUS™插座上的硬件复位引脚(标记为RST)复位此Click板™。此Click板™只能在3.3V逻辑电压电平下运行。使用具有不同逻辑电平的MCU之前,必须进行适当的逻辑电压电平转换。此外,它还配备了一个库,包含功能和示例代码,可作为进一步开发的参考。

BLE TINY click hardware overview image

功能概述

开发板

Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性

的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本

身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Clicker 2 for Kinetis dimensions image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

NXP

引脚数

121

RAM (字节)

262144

使用的MCU引脚

mikroBUS™映射器

Analog Signal
PB2
AN
Reset
PB11
RST
SPI Chip Select
PC4
CS
SPI Clock
PC5
SCK
SPI Data OUT
PC7
MISO
SPI Data IN
PC6
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PD3
TX
UART RX
PD2
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

BLE TINY click Schematic schematic

一步一步来

项目组装

Clicker 2 for PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Clicker 2 for Kinetis作为您的开发板开始。

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector Clicker 2 Access - 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
Flip&Click PIC32MZ MCU 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”替换为要显示的参数。

软件支持

库描述

该库包含 BLE TINY Click 驱动程序的 API。

关键功能:

  • bletiny_send_cmd - 发送命令功能

  • bletiny_i2c_config - 配置Click板以进行I2C主通信

  • bletiny_i2c_write - 通过I2C通信向从设备的寄存器地址写入数据的发送命令

开源

代码示例

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

/*!
 * @file main.c
 * @brief BLE TINY Click Example.
 *
 * # Description
 * This example reads and processes data from BLE TINY clicks.
 * Application waits for connection with Click board with phone.
 * Then checks its Coadless FW version and checks connected device.
 * Then waits for command to be stored in it's memory on 0 slot.
 * After that depending on the command stored it executes that type of example.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver and resets device and seds Disconnect and Reset IO commands.
 * Then it waits for the connection to device. When connected it sends commands to
 * check Coadless FW, connected device, its BLE address and signal quality of
 * connection. In the end it waits for command from its memory. After valid
 * command is stored in memory on 0 slot it contines to Application Task.
 *
 * ## Application Task
 * Executes one of thre application task selected in Application Init:I2C, SPI, APP.
 * I2C example uses EEPROM Click board to write and read data of its memory.
 * SPI example uses EEPROM 2 Click board to write and read data of its memory.
 * APP example just reads UART data and logs it to UART Terminal.
 *
 * ## Additional Function
 * - static void bletiny_clear_app_buf ( void )
 * - static err_t bletiny_process ( void )
 * - static void bletiny_error_check( err_t error_flag );
 * - static void bletiny_log_app_buf ( void );
 * - static err_t bletiny_rsp_check ( void );
 * - static void bletiny_example_init ( void );
 * - static void bletiny_application_example ( void );
 * - static void bletiny_i2c_example ( void );
 * - static void bletiny_spi_example ( void );
 *
 * @note
 * For this application you need to install Dialog's mobile application SmartConsole.
 * This application I2C example is created using EEPROM Click board, and for SPI
 * example EEPROM 2 Click board is used.
 *
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "bletiny.h"
#include "conversions.h"

/**
 * @brief Application receiver buffer size
 * @details Specified size of application receiver buffer.
 */
#define PROCESS_BUFFER_SIZE 200

/**
 * @brief Application example type.
 * @details Specified application example type.
 */
typedef enum
{
    BLETINY_APP_CTRL,
    BLETINY_I2C_EXAMPLE,
    BLETINY_SPI_EXAMPLE
}bletiny_example_type_t;

/**
 * @brief Application example state.
 * @details Specified application example state.
 */
typedef enum
{
    BLETINY_CONFIGURE_MASTER,
    BLETINY_CONFIGURE_SLAVE,
    BLETINY_EXAMPLE
}bletiny_example_state_t;

static bletiny_t bletiny;
static log_t logger;

/**
 * @brief Application @b app_buf and its @b app_buf_cnt and @b app_buf_len.
 * @details Application receiver buffer and its counter and current length.
 */
static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;

/**
 * @brief Application example type and state.
 * @details Application example type and state variables.
 */
static bletiny_example_type_t example_type;
static bletiny_example_state_t example_state;

/**
 * @brief Clearing application buffer.
 * @details This function clears memory of application buffer and reset it's length and counter.
 */
static void bletiny_clear_app_buf ( void );

/**
 * @brief 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.
 */
static err_t bletiny_process ( void );

/**
 * @brief Parse errors.
 * @details This function checks for different types of errors and logs them on UART.
 */
static void bletiny_error_check( err_t error_flag );

/**
 * @brief Logs application buffer.
 * @details This function logs data from application buffer.
 */
static void bletiny_log_app_buf ( void );

/**
 * @brief Response check.
 * @details This function checks for response and returns the status of response.
 *
 * @return @li @c  >=0 - Success,
 *         @li @c   <0 - Error.
 *
 * See #err_t definition for detailed explanation.
 */
static err_t bletiny_rsp_check ( void );

/**
 * @brief Selecting application task.
 * @details This function selects application task that will be executed.
 * @note Select task by sending command for sending string in memory(0 slot)
 * with phone application. Example of command: AT+MEM=0,I2C. If memory is
 * not empty the string detected will be shown on UART Terminal.
 */
static void bletiny_example_init ( void );

/**
 * @brief Application example.
 * @details This function executes task for using phone application.
 * @note Example logs if any data is read from Click board. This example
 * should be selected if you want to control device with phone application.
 */
static void bletiny_application_example ( void );

/**
 * @brief I2C example.
 * @details This function executes task for using EEPROM Click board.
 * @note Example configures IO pins for I2C communication and configures I2C.
 * Then writes "MikroE" to memory of EEPROM Click board and then reads it
 * back and logs it to UART Terminal.
 */
static void bletiny_i2c_example ( void );

/**
 * @brief SPI example.
 * @details This function executes task for using EEPROM 2 Click board.
 * @note Example configures IO pins for SPI communication and configures SPI.
 * When configured, it sends command for enableing write to Click board memory.
 * Then writes "MikroE" to memory of EEPROM 2 Click board and then reads it
 * back and logs it to UART Terminal.
 */
static void bletiny_spi_example ( void );

/**
 * @brief Clear every @b chr from @b str.
 * @details This function clears every occurance of @b chr from @b str.
 */
static void bletiny_clear_char( uint8_t *str, char chr );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    bletiny_cfg_t bletiny_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_printf( &logger, "\r\nApplication Init\r\n" );
    Delay_ms( 1000 );

    // Click initialization.
    bletiny_cfg_setup( &bletiny_cfg );
    BLETINY_MAP_MIKROBUS( bletiny_cfg, MIKROBUS_1 );
    err_t init_flag  = bletiny_init( &bletiny, &bletiny_cfg );

    if ( init_flag == UART_ERROR )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    bletiny_default_cfg ( &bletiny );

    bletiny_send_cmd( &bletiny, BLETINY_CMD_ATR );
    bletiny_send_cmd( &bletiny, BLETINY_CMD_ATZ );
    bletiny_send_cmd( &bletiny, BLETINY_CMD_GAPDISCONNECT );
    bletiny_process( );
    bletiny_clear_app_buf( );

    app_buf_len = 0;
    app_buf_cnt = 0;

    //wait for connection
    log_printf( &logger, " Waiting for phone to connect\r\n" );
    while ( 0 == strstr( app_buf, BLETINY_CONNECTED ) )
    {
        bletiny_process( );
    }
    log_printf( &logger, " Connected\r\n" );
    bletiny_clear_app_buf( );
    //send ATI command to check Codless FW
    bletiny_send_cmd( &bletiny, BLETINY_CMD_ATI );
    volatile err_t app_error_flag = bletiny_rsp_check();
    if ( BLETINY_OK == app_error_flag )
    {
        bletiny_log_app_buf();
        log_printf( &logger, "-----------------------------------\r\n" );
    }
    else
    {
        bletiny_error_check( app_error_flag );
    }
    Delay_ms( 1000 );
    //send command to check ble address
    bletiny_send_cmd( &bletiny, BLETINY_CMD_BDADDR );
    app_error_flag = bletiny_rsp_check();
    if ( BLETINY_OK == app_error_flag )
    {
        bletiny_log_app_buf();
        log_printf( &logger, "-----------------------------------\r\n" );
    }
    else
    {
        bletiny_error_check( app_error_flag );
    }
    Delay_ms( 1000 );
    //send ATrI command to check remote connected device
    bletiny_send_cmd( &bletiny, BLETINY_CMD_ATRI );
    app_error_flag = bletiny_rsp_check();
    if ( BLETINY_OK == app_error_flag )
    {
        bletiny_log_app_buf();
        log_printf( &logger, "-----------------------------------\r\n" );
    }
    else
    {
        bletiny_error_check( app_error_flag );
    }
    Delay_ms( 1000 );
    //send RSSI command to check signal quality
    bletiny_send_cmd( &bletiny, BLETINY_CMD_RSSI );
    app_error_flag = bletiny_rsp_check();
    if ( BLETINY_OK == app_error_flag )
    {
        bletiny_log_app_buf();
        log_printf( &logger, "-----------------------------------\r\n" );
    }
    else
    {
        bletiny_error_check( app_error_flag );
    }
    //select example to execute
    bletiny_example_init( );

    bletiny_clear_app_buf( );
    log_printf( &logger, " Application Task \r\n" );
}

void application_task ( void )
{
    static uint8_t info = 0;
    switch ( example_type )
    {
        case BLETINY_I2C_EXAMPLE:
        {
            if (!info)
            {
                info++;
                log_printf( &logger, " I2C example\r\n" );
                bletiny_process( );
                bletiny_clear_app_buf( );
            }
            bletiny_i2c_example( );
            break;
        }
        case BLETINY_SPI_EXAMPLE:
        {
            if (!info)
            {
                info++;
                log_printf( &logger, " SPI example\r\n" );
                bletiny_process( );
                bletiny_clear_app_buf( );
            }
            bletiny_spi_example( );
            break;
        }
        case BLETINY_APP_CTRL:
        {
            if (!info)
            {
                info++;
                log_printf( &logger, " Application example\r\n" );
                bletiny_process( );
                bletiny_clear_app_buf( );
            }
            bletiny_application_example( );
            break;
        }
        default:
        {
            break;
        }
    }
}

void main ( void )
{
    application_init( );

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

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

static err_t bletiny_process ( void )
{
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };

    rx_size = bletiny_generic_read( &bletiny, rx_buff, PROCESS_BUFFER_SIZE );

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

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
           bletiny_clear_app_buf(  );
            return BLETINY_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 )
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
                buf_cnt--;
            }

        }
        return BLETINY_OK;
    }
    return BLETINY_ERROR;
}

static err_t bletiny_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;

    err_t error_flag = bletiny_process(  );
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }

    while ( ( strstr( app_buf, BLETINY_RSP_OK ) == 0 ) &&
            ( strstr( app_buf, BLETINY_RSP_ERROR ) == 0 ) )
    {
        error_flag = bletiny_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }

        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            bletiny_clear_app_buf(  );
            return BLETINY_ERROR_TIMEOUT;
        }

        Delay_ms( 1 );
    }

    if ( strstr( app_buf, BLETINY_RSP_OK ) )
        return BLETINY_OK;
    else if ( strstr( app_buf, BLETINY_RSP_ERROR ) )
        return BLETINY_ERROR_RETURN;
    else
        return BLETINY_ERROR_UNKNOWN;
}

static void bletiny_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 bletiny_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 ] );
    }
    bletiny_clear_app_buf(  );
}

static void bletiny_example_init ( void )
{
    #define EXAMPLE_CMD_LEN 6
    char EXAMPLE_CMD[ EXAMPLE_CMD_LEN ][ 4 ] = { "I2C", "i2c", "SPI", "spi", "APP", "app" };
    log_info( &logger, " Send value to 0 memory index via phone app to select example type." );
    log_info( &logger, " Example of command is: AT+MEM=0,I2C" );
    log_info( &logger, " Types:\r\n > SPI\r\n > I2C \r\n > APP" );

    for ( ; ; )
    {
        bletiny_send_cmd( &bletiny, BLETINY_CMD_CHECK_MEM );

        if ( BLETINY_OK == bletiny_rsp_check() )
        {
            bletiny_clear_char(app_buf, 13);
            bletiny_clear_char(app_buf, 10);

            volatile char *__generic_ptr ok_rsp = strstr( app_buf, BLETINY_RSP_OK );

            if ( ok_rsp )
            {
                for ( uint8_t index = 0; index < EXAMPLE_CMD_LEN; index++ )
                {
                    if ( 0 != strstr(app_buf, EXAMPLE_CMD[ index ]) )
                    {
                        log_printf( &logger, " cmd foud: %s\r\n", EXAMPLE_CMD[ index ] );
                        bletiny_clear_app_buf( );
                        bletiny_send_cmd( &bletiny, BLETINY_CMD_CLEAR_MEM );
                        Delay_ms( 500 );
                        bletiny_process( );
                        bletiny_clear_app_buf( );
                        if ( index < 2 )
                        {
                            example_type = BLETINY_I2C_EXAMPLE;
                            example_state = BLETINY_CONFIGURE_MASTER;
                            return;
                        }
                        else if ( index < 4 )
                        {
                            example_type = BLETINY_SPI_EXAMPLE;
                            example_state = BLETINY_CONFIGURE_MASTER;
                            return;
                        }
                        else
                        {
                            example_type = BLETINY_APP_CTRL;
                            return;
                        }
                    }
                }
                char *__generic_ptr echo_rsp = strstr( app_buf, BLETINY_CMD_CHECK_MEM );

                if (echo_rsp)
                {
                    echo_rsp += sizeof(BLETINY_CMD_CHECK_MEM);
                }
                else
                {
                    echo_rsp = app_buf;
                }

                if ( strcmp(echo_rsp, ok_rsp) )
                {
                    log_printf( &logger, " cmd not found but found: " );
                    while (echo_rsp != ok_rsp)
                    {
                        log_printf( &logger, "%c", *echo_rsp );
                        echo_rsp++;
                    }
                    log_printf( &logger, "\r\n" );
                }
            }
            bletiny_clear_app_buf(  );
        }

        Delay_ms( 2000 );
    }

    Delay_ms( 1000 );
}

static void bletiny_application_example ( void )
{
    bletiny_process( );
    if ( app_buf_len > 0 )
    {
        log_printf( &logger, "%s", app_buf );
        bletiny_clear_app_buf(  );
    }
}

static void bletiny_i2c_example ( void )
{
    switch ( example_state )
    {
        case BLETINY_CONFIGURE_MASTER:
        {
            log_printf( &logger, " Configure master for I2C communication\r\n" );
            bletiny_i2c_config( &bletiny, BLETINY_I2C_CFG_SPEED_100KHZ, BLETINY_I2C_CFG_REG_LEN_1BYTE );
            example_state = BLETINY_EXAMPLE;
            break;
        }
        case BLETINY_EXAMPLE:
        {
            char mem_value[ 16 ] = "MikroE";
            log_printf ( &logger, "Writing Mikroe to EEPROM click\r\n" );
            for ( uint8_t cnt = 0; cnt < 6; cnt++ )
            {
                bletiny_i2c_write( &bletiny, 0x50, cnt + 1, mem_value[ cnt ] );
                Delay_ms( 100 );
            }

            if ( BLETINY_OK == bletiny_i2c_read ( &bletiny, 0x50, 0x01 , mem_value, 6 ) )
            {
                log_printf ( &logger, "Data read: %s\r\n", mem_value );
            }

            break;
        }
        default:
        {
            break;
        }
    }
    Delay_ms( 2000 );
}

static void bletiny_spi_example ( void )
{
    switch ( example_state )
    {
        case BLETINY_CONFIGURE_MASTER:
        {
            log_printf( &logger, " Configure master for SPI communication\r\n" );

            bletiny_spi_config( &bletiny, BLETINY_SPI_CFG_SPEED_2MHZ, BLETINY_SPI_CFG_MODE0 );

            example_state = BLETINY_CONFIGURE_SLAVE;
            break;
        }
        case BLETINY_CONFIGURE_SLAVE:
        {
            uint8_t write_enable = 0x06;
            bletiny_spi_write( &bletiny, &write_enable, 1 );

            example_state = BLETINY_EXAMPLE;
            break;
        }
        case BLETINY_EXAMPLE:
        {
            uint8_t buf[ 10 ] = { 0x02, 0x00, 0x00, 0x01, 'M', 'i', 'k', 'r', 'o', 'E' };
            bletiny_spi_write ( &bletiny, buf, 10 );
            log_printf ( &logger, "Writing Mikroe to EEPROM 2 click\r\n" );
            Delay_ms( 1000 );

            uint8_t data_in[ 4 ] = { 0x03, 0x00, 0x00, 0x01 };
            uint8_t read_data[ 7 ] = { 0 };
            bletiny_spi_write_then_read( &bletiny, data_in, 4, read_data, 6 );
            log_printf ( &logger, "Data read: %s\r\n", read_data );
            break;
        }
        default:
        {
            break;
        }
    }
    Delay_ms( 1000 );
}

static void bletiny_clear_char( uint8_t *str, char chr )
{
    while ( 0 != strchr( str, chr ) )
    {
        str_cut_chr( str, chr );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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