Advanced
30 min

Quickly add Bluetooth Low Energy connectivity to your embedded projects with CYW20822-P4TAI040 and STM32G474RE

Low-power Bluetooth 5.0 solution for a wide range of IoT applications

BT-EZ 2 Click with Nucleo 64 with STM32G474RE MCU

Published Sep 01, 2025

Click board™

BT-EZ 2 Click

Dev. board

Nucleo 64 with STM32G474RE MCU

Compiler

NECTO Studio

MCU

STM32G474RE

Bring Bluetooth Low Energy to your design from wearables to smart home devices

A

A

Hardware Overview

How does it work?

BT-EZ 2 Click is based on the CYW20822-P4TAI040, a fully integrated Bluetooth Low Energy wireless module from Infineon that combines the CYW20822 silicon device with onboard crystal oscillator, passive components, embedded flash memory, and an integrated trace antenna. This module is pre-loaded with EZ-Serial firmware, offering a user-friendly command interface for configuration and use, and is fully qualified by the Bluetooth SIG as a cost-optimized Bluetooth 5.0 solution suitable for a wide range of embedded applications. With 1MB of embedded flash memory, the module supports non-volatile storage for self-sufficient operation and over-the-air firmware updates, ensuring flexibility and long-term adaptability. The integrated 16MHz Arm Cortex-M0 microcontroller enables efficient performance, while the radio supports multiple Bluetooth Low Energy data rates, including 2Mbps, 1Mbps, 500kbps, and 125kbps, giving developers scalability for different use cases. The module delivers a maximum transmit output power of +4dBm and achieves a connection range of up to 250 meters in ideal line-of-sight conditions, while the receiver offers high sensitivity of –101dBm at 125kbps, ensuring robust communication even in challenging environments. These capabilities make BT-EZ 2 Click an excellent

solution for wearable devices, smart home systems, IoT nodes, healthcare monitoring, and industrial applications where dependable Bluetooth connectivity, low power consumption, and simple integration are required. This Click board™ establishes communication between the CYW20822-P4TAI040 module and the host MCU through a UART interface, using standard UART RX and TX pins and hardware flow control via CTS and RTS pins. The default communication speed is set at 115200bps, ensuring efficient data exchange. The board also features a UART SEL jumper that allows the selection of the UART TX signal purpose, enabling it to function either as a standard UART TX signal for data exchange or as a UART TX debug signal, with the mode determined by placing the jumper in the DAT or DBG position. In addition to the interface pins, the board features a reset (RST) pin for hard-resetting the module when necessary, CYS pin for choosing between Command/Data mode (HIGH for command, LOW for data), and SWD pads designed for use with MIKROE's 6-pin Needle Cable, providing an optional flash and debug SWD (Serial Wire Debug) interface functionality. BT-EZ 2 Click also provides additional user-configurable features and control options, three unpopulated 2-pin headers to

enhance flexibility and ease of use in different application scenarios. The NTC header is intended for connecting an external Negative Temperature Coefficient thermistor, which allows developers to implement temperature-dependent control or monitoring, although its specific role depends on the intended application. The MODE header is used for low-power mode control, enabling the module to be configured for reduced energy consumption. The BOOT header provides access to boot control functionality, allowing the user to manage firmware loading or recovery processes as required during development or field updates. In addition to these headers, the board features user-friendly elements such as a BUTTON switch for triggering custom-defined actions or module commands, as well as two LED indicators, a red LED (LED1) and a yellow LED (LED2), which can be used to provide status feedback, signal communication activity, or serve as general-purpose indicators during prototyping and debugging. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. It also comes equipped with a library containing functions and example code that can be used as a reference for further development.

BT-EZ 2 Click hardware overview image

Features overview

Development board

Nucleo-64 with STM32G474R MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32G474RE MCU double side image

Microcontroller Overview

MCU Card / MCU

STM32G474RE front image

Architecture

ARM Cortex-M4

MCU Memory (KB)

512

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

128k

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Command/Data Mode Control
PA15
AN
Reset / ID SEL
PC12
RST
UART CTS / ID COMM
PB12
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
UART RTS
PC14
INT
UART TX
PA3
TX
UART RX
PA2
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

BT-EZ 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 64 with STM32G474RE MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32G474RE MCU front image hardware assembly
LTE Cat.1 6 Click front image hardware assembly
Prog-cut hardware assembly
LTE Cat.1 6 Click complete accessories setup image hardware assembly
Board mapper by product8 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 image step 6 hardware assembly
Clicker 4 for STM32F4 HA 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

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

BT-EZ 2 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description
This example demonstrates the use of BT-EZ 2 Click board by processing data from a connected BLE device.

Key functions:

  • btez2_cfg_setup - This function initializes Click configuration structure to initial values.

  • btez2_init - This function initializes all necessary pins and peripherals used for this Click board.

  • btez2_cmd_action - This function sends a specified action command to the Click module.

  • btez2_cmd_set - This function sends a specified set command to the Click module.

  • btez2_read_packet - This function reads a response or event packet from the Click module and stores it in ctx->evt_pkt structure.

Application Init
Initializes the driver and logger.

Application Task
Application task is split in few stages:

  • BTEZ2_POWER_UP: Powers up the device and checks the communication.

  • BTEZ2_CONFIG_EXAMPLE: Restores factory settings and reads the BT address and name.

  • BTEZ2_EXAMPLE: Performs a BT terminal example by processing all data from a connected BLE device and sending back an adequate response messages.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief BT-EZ 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of BT-EZ 2 Click board by processing data
 * from a connected BLE 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:
 *  - BTEZ2_POWER_UP:
 * Powers up the device and checks the communication.
 *  - BTEZ2_CONFIG_EXAMPLE:
 * Restores factory settings and reads the BT address and name.
 *  - BTEZ2_EXAMPLE:
 * Performs a BT terminal example by processing all data from a connected BLE device 
 * and sending back an adequate response messages.
 *
 * ## Additional Function
 * - static void btez2_clear_app_buf ( void )
 * - static void btez2_log_app_buf ( void )
 * - static err_t btez2_process ( btez2_t *ctx )
 * - static err_t btez2_wait_packet ( btez2_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code )
 * - static err_t btez2_power_up ( btez2_t *ctx )
 * - static err_t btez2_config_example ( btez2_t *ctx )
 * - static err_t btez2_example ( btez2_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 "btez2.h"

// Message content
#define MESSAGE_CONTENT     "BT-EZ 2 Click board - demo example."

static btez2_t btez2;
static log_t logger;

// Application buffer size
#define APP_BUFFER_SIZE     500
#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
{
    BTEZ2_POWER_UP = 1,
    BTEZ2_CONFIG_EXAMPLE,
    BTEZ2_EXAMPLE

} btez2_app_state_t;

static btez2_app_state_t app_state = BTEZ2_POWER_UP;

/**
 * @brief BT-EZ 2 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void btez2_clear_app_buf ( void );

/**
 * @brief BT-EZ 2 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void btez2_log_app_buf ( void );

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

/**
 * @brief BT-EZ 2 wait packet function.
 * @details This function waits for a packet message, reads and displays it on the USB UART.
 * @param[in] ctx : Click context object.
 * See #btez2_t object definition for detailed explanation.
 * @param[in] timeout_s : Timeout in seconds.
 * @param[in] rsp_flag : 1 - response packet, 0 - event packet.
 * @param[in] cmd_code : Expected command code string.
 * @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 btez2_wait_packet ( btez2_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code );

/**
 * @brief BT-EZ 2 power up function.
 * @details This function powers up the device and checks communication.
 * @param[in] ctx : Click context object.
 * See #btez2_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 btez2_power_up ( btez2_t *ctx );

/**
 * @brief BT-EZ 2 config example function.
 * @details This function restores factory settings, and reads the BT address and name.
 * @param[in] ctx : Click context object.
 * See #btez2_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 btez2_config_example ( btez2_t *ctx );

/**
 * @brief BT-EZ 2 example function.
 * @details This function performs a BT terminal example by processing all data from
 * a connected BLE device and sending back an adequate response messages.
 * @param[in] ctx : Click context object.
 * See #btez2_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 btez2_example ( btez2_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    btez2_cfg_t btez2_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.
    btez2_cfg_setup( &btez2_cfg );
    BTEZ2_MAP_MIKROBUS( btez2_cfg, MIKROBUS_1 );
    if ( UART_ERROR == btez2_init( &btez2, &btez2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

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

void application_task ( void ) 
{
    switch ( app_state )
    {
        case BTEZ2_POWER_UP:
        {
            if ( BTEZ2_OK == btez2_power_up( &btez2 ) )
            {
                app_state = BTEZ2_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case BTEZ2_CONFIG_EXAMPLE:
        {
            if ( BTEZ2_OK == btez2_config_example( &btez2 ) )
            {
                app_state = BTEZ2_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case BTEZ2_EXAMPLE:
        {
            btez2_example( &btez2 );
            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 btez2_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void btez2_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 btez2_process ( btez2_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = btez2_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 BTEZ2_OK;
    }
    return BTEZ2_ERROR;
}

static err_t btez2_wait_packet ( btez2_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code ) 
{
    err_t error_flag = BTEZ2_OK;
    uint32_t timeout_cnt = 0;
    while ( ( timeout_cnt < timeout_s ) || ( BTEZ2_WAIT_TIMEOUT_INFINITE == timeout_s ) )
    {
        error_flag = btez2_read_packet( ctx );
        if ( BTEZ2_OK == error_flag )
        {
            if ( BTEZ2_PACKET_TYPE_EVENT == ctx->evt_pkt.rsp_flag )
            {
                log_printf ( &logger, " < EVENT >\r\n" );
            }
            else
            {
                log_printf ( &logger, " < RESPONSE >\r\n" );
            }
            
            if ( ( BTEZ2_PACKET_TYPE_EVENT == ctx->evt_pkt.rsp_flag ) && 
                 ( strstr( ctx->evt_pkt.command, BTEZ2_EVT_SYS_ERROR ) ) )
            {
                log_printf( &logger, "   Wrong CMD!\r\n" );
                error_flag = BTEZ2_ERROR_CMD;
                break;
            }
            else
            {
                log_printf ( &logger, "   Command: %s\r\n", ctx->evt_pkt.command );
                if ( BTEZ2_PACKET_TYPE_RESPONSE == ctx->evt_pkt.rsp_flag )
                {
                    log_printf ( &logger, "   Type: " );
                    switch ( ctx->evt_pkt.command_type )
                    {
                        case '/':
                        {
                            log_printf ( &logger, "Action\r\n" );
                            break;
                        }
                        case 'S':
                        {
                            log_printf ( &logger, "Set\r\n" );
                            break;
                        }
                        case 'G':
                        {
                            log_printf ( &logger, "Get\r\n" );
                            break;
                        }
                        case '.':
                        {
                            log_printf ( &logger, "Profile\r\n" );
                            break;
                        }
                        default:
                        {
                            log_printf ( &logger, "Unknown\r\n" );
                            break;
                        }
                    }
                    if ( ctx->evt_pkt.rsp_result )
                    {
                        log_printf( &logger, "   Result: %.4X\r\n", ctx->evt_pkt.rsp_result );
                        if ( ( ctx->evt_pkt.rsp_flag == rsp_flag ) && 
                             ( 0 == strcmp( ctx->evt_pkt.command, cmd_code ) ) )
                        { 
                            error_flag = BTEZ2_ERROR;
                            break;
                        }
                    }
                    else
                    {
                        log_printf( &logger, "   Result: OK\r\n" );
                    }
                }
                if ( strlen ( ctx->evt_pkt.payload ) )
                {
                    log_printf ( &logger, "   Payload: %s\r\n", ctx->evt_pkt.payload );
                }
                
                if ( ( ctx->evt_pkt.rsp_flag == rsp_flag ) && 
                     ( 0 == strcmp( ctx->evt_pkt.command, cmd_code ) ) )
                { 
                    error_flag = BTEZ2_OK;
                    break;
                }
            }
        }
        else
        {
            timeout_cnt++;
        }
    }
    if ( ( timeout_cnt >= timeout_s ) && ( 0 != timeout_s ) )
    {
        log_printf( &logger, " < TIMEOUT >\r\n" );
        error_flag = BTEZ2_ERROR_TIMEOUT;
    }
    log_printf( &logger, "--------------------------------\r\n" );
    return error_flag;
}

static err_t btez2_power_up ( btez2_t *ctx )
{
    err_t error_flag = BTEZ2_OK;

    log_printf( &logger, ">> Reset device.\r\n" );
    btez2_set_cmd_mode( ctx );
    btez2_reset_device( ctx );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_EVENT, 
                                          BTEZ2_EVT_GAP_ADV_STATE_CHANGED );

    log_printf( &logger, ">> Check communication.\r\n" );
    btez2_cmd_action( ctx, BTEZ2_CMD_SYS_PING, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_RESPONSE, 
                                          BTEZ2_CMD_SYS_PING );

    return error_flag;
}

static err_t btez2_config_example ( btez2_t *ctx )
{
    err_t error_flag = BTEZ2_OK;

    log_printf( &logger, ">> Factory reset.\r\n" );
    btez2_cmd_action( ctx, BTEZ2_CMD_SYS_FACTORY_RESET, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_EVENT, 
                                          BTEZ2_EVT_GAP_ADV_STATE_CHANGED );
    
    log_printf( &logger, ">> Save settings.\r\n" );
    btez2_cmd_action( ctx, BTEZ2_CMD_SYS_STORE_CONFIG, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_RESPONSE, 
                                          BTEZ2_CMD_SYS_STORE_CONFIG );
    
    log_printf( &logger, ">> Reboot.\r\n" );
    btez2_cmd_action( ctx, BTEZ2_CMD_SYS_REBOOT, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_EVENT, 
                                          BTEZ2_EVT_GAP_ADV_STATE_CHANGED );

    log_printf( &logger, ">> Get BT address.\r\n" );
    btez2_cmd_get( ctx, BTEZ2_CMD_SYS_BT_ADDRESS, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_RESPONSE, 
                                          BTEZ2_CMD_SYS_BT_ADDRESS );
    
    log_printf( &logger, ">> Get device name.\r\n" );
    btez2_cmd_get( ctx, BTEZ2_CMD_GAP_DEVICE_NAME, NULL );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_5S, 
                                          BTEZ2_PACKET_TYPE_RESPONSE, 
                                          BTEZ2_CMD_GAP_DEVICE_NAME );
    
    return error_flag;
}

static err_t btez2_example ( btez2_t *ctx )
{
    err_t error_flag = BTEZ2_OK;
    uint32_t timeout_cnt = 0;

    #define BT_TERMINAL_TIMEOUT_MS      60000
    #define BT_TERMINAL_MESSAGE_FREQ_MS 5000
    
    Delay_ms ( 100 );
    log_printf( &logger, ">> Waiting for a BT peer to establish connection with the Click board...\r\n" );
    error_flag |= btez2_wait_packet( ctx, BTEZ2_WAIT_TIMEOUT_INFINITE, 
                                          BTEZ2_PACKET_TYPE_EVENT, 
                                          BTEZ2_EVT_CYSPP_STATUS );
    log_printf( &logger, ">> BT peer has connected.\r\n" );
    btez2_set_data_mode( ctx );

    log_printf( &logger, ">> Waiting for data (up to 60 seconds)...\r\n" );
    for ( ; ; )
    {
        btez2_clear_app_buf( );
        if ( BTEZ2_OK == btez2_process( ctx ) )
        {
            Delay_ms ( 100 );
            timeout_cnt = 0;
            btez2_process( ctx );
            btez2_log_app_buf( );
            if ( strstr( app_buf, BTEZ2_EVT_GAP_DISCONNECTED ) )
            {
                log_printf( &logger, ">> BT peer has disconnected.\r\n" );
                btez2_set_cmd_mode( ctx );
                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 );
            error_flag |= btez2_generic_write ( ctx, MESSAGE_CONTENT, strlen ( MESSAGE_CONTENT ) );
            error_flag |= btez2_generic_write ( ctx, BTEZ2_PACKET_END, strlen ( BTEZ2_PACKET_END ) );
            Delay_ms ( 100 );
        }
        if ( BT_TERMINAL_TIMEOUT_MS < timeout_cnt )
        {
            btez2_set_cmd_mode( ctx );
            break;
        }
        Delay_ms ( 1 );
    }

    return error_flag;
}

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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.