Advanced
30 min

Provide Bluetooth 5.4 wireless communication with Vela IF820 (453-00171R) module and PIC32MX470F512H

Bluetooth Classic (BR/EDR) and Bluetooth Low Energy (LE) 5.4 solution for flexible connectivity

Vela IF820 Click with 6LoWPAN clicker

Published Mar 03, 2025

Click board™

Vela IF820 Click

Dev. board

6LoWPAN clicker

Compiler

NECTO Studio

MCU

PIC32MX470F512H

Provide Bluetooth® 5.4 connectivity with dual-mode support for industrial IoT and smart home applications

A

A

Hardware Overview

How does it work?

Vela IF820 Click is based on the Vela IF820 (453-00171R) module from Ezurio, offering an advanced solution for Bluetooth® communication with dual-mode support. This allows operation with both classic Bluetooth and Bluetooth Low Energy (LE), enabling an easy transition from legacy Bluetooth standards to modern LE technology within a single hardware solution. The Vela IF820 is powered by the Infineon Technologies AIROC™ CYW20820 chipset, featuring a high-performance Arm® Cortex®-M4 processor running at a maximum clock speed of 96MHz. Its architecture allows for standalone operation without requiring an external microcontroller, thanks to the integrated Bluetooth protocol stack stored in ROM. This module comes with an integrated antenna and complies with the Bluetooth® Core Specification version 5.4. It supports Basic Data Rate (BR) and Enhanced Data Rate (EDR) at 2Mbps and 3Mbps, as well as extended synchronous connection-oriented communication. Additionally, it provides Bluetooth® LE 1M PHY and 2M PHY support, ensuring robust wireless performance. With an output power of up to 10dBm EIRP and excellent receiver sensitivity (-94 dBm for Bluetooth LE at 1 Mbps), the Vela IF820 ensures reliable and efficient connectivity.

Due to its versatile capabilities, this board is suitable for various applications, including industrial automation, wireless sensor networks, IoT devices, smart home systems, medical monitoring, and other embedded solutions requiring stable and high-performance Bluetooth communication. The 453-00171R and the host MCU are communicated through a UART interface, using standard UART RX and TX pins and hardware flow control pins (CTS/RTS- Clear to Send/Ready to Send) for efficient data transfer. The module defaults to a communication speed of 115200bps, allowing for data exchange over AT commands. In addition to the interface pins, this board includes several auxiliary pins that enhance its functionality. The HWE (Host Wake) signal is used by the module to notify the host system when the Bluetooth device requires attention, ensuring efficient power management and responsiveness. The SPP (Serial Port Profile) pin is dedicated to managing Bluetooth SPP connections, typically serving for connection control or status indication, making it particularly useful for applications requiring reliable serial communication over Bluetooth. Additionally, the RST pin is dedicated to resetting the module, offering the same functionality as the onboard

RESET button, ensuring a convenient way to restart the module when necessary. The board features SWD pads designed for use with MIKROE's 6-pin Needle Cable, enabling optional flash programming and debug functionality via the SWD (Serial Wire Debug) interface. This allows for efficient firmware development, debugging, and troubleshooting, making it easier to optimize and maintain the module’s performance. The back side of the board features multiple test points, providing access to 15 GPIO signals from the module, as well as the Bluetooth UART interface required for flashing EZ-Serial and HCI firmware. Additionally, the DWE pin is available, serving as a signal from the host to the module, indicating that the host MCU requires attention, ensuring efficient communication and system responsiveness. 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.

Vela IF820 Click hardware overview image

Features overview

Development board

6LoWPAN Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC microcontroller, the PIC32MX470F512H from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Along with this microcontroller, the board also contains a 2.4GHz ISM band transceiver, allowing you to add wireless communication to your target application. Its compact design provides a fluid and immersive working experience, allowing access anywhere

and under any circumstances. Each part of the 6LoWPAN Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the 6LoWPAN Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current for the Clicker board, which is more than enough to operate all onboard and additional modules, or it can power

over two standard AA batteries. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. 6LoWPAN Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

6LoWPAN clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

512

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

131072

You complete me!

Accessories

6-pin Needle Cable is a compact programming cable made from high-quality materials for longevity and easy portability with a tiny square footprint, similar to a 0805 resistor. Designed for quick programming and debugging, it features a 6-pin 0.1″ pitch ribbon connector and is hand-held or temporarily fixable.

Vela IF820 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Host Wake
RG9
AN
Reset / ID SEL
RD6
RST
UART RTS / ID COMM
RE5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Bluetooth SPP Control
RB8
PWM
UART CTS
RD0
INT
UART TX
RF4
TX
UART RX
RF5
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Vela IF820 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the 6LoWPAN clicker as your development board.

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Board mapper by product7 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

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

Vela IF820 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 Vela IF820 Click by processing data from a connected BT Classic device.

Key functions:

  • velaif820_cfg_setup - Config Object Initialization function.

  • velaif820_init - Initialization function.

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

  • velaif820_cmd_get - This function sends a specified get command to the Click module.

  • velaif820_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:

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

  • VELAIF820_CONFIG_EXAMPLE: Restores factory settings, sets BT Classic flags and reads the BT address and name.

  • VELAIF820_EXAMPLE: Performs a BT terminal example by processing all data from a connected BT Classic 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 Vela IF820 Click Example.
 *
 * # Description
 * This example demonstrates the use of Vela IF820 Click board by processing data
 * from a connected BT Classic 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:
 *  - VELAIF820_POWER_UP:
 * Powers up the device and checks the communication.
 *  - VELAIF820_CONFIG_EXAMPLE:
 * Restores factory settings, sets BT Classic flags and reads the BT address and name.
 *  - VELAIF820_EXAMPLE:
 * Performs a BT terminal example by processing all data from a connected BT Classic device 
 * and sending back an adequate response messages.
 *
 * ## Additional Function
 * - static void velaif820_clear_app_buf ( void )
 * - static void velaif820_log_app_buf ( void )
 * - static err_t velaif820_process ( velaif820_t *ctx )
 * - static err_t velaif820_wait_packet ( velaif820_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code )
 * - static err_t velaif820_power_up ( velaif820_t *ctx )
 * - static err_t velaif820_config_example ( velaif820_t *ctx )
 * - static err_t velaif820_example ( velaif820_t *ctx )
 *
 * @note
 * We have used the Serial Bluetooth Terminal smartphone application for the test. 
 * A smartphone and the Click board must be paired in order to exchange messages with each other.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "velaif820.h"

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

static velaif820_t velaif820;
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
{
    VELAIF820_POWER_UP = 1,
    VELAIF820_CONFIG_EXAMPLE,
    VELAIF820_EXAMPLE

} velaif820_app_state_t;

static velaif820_app_state_t app_state = VELAIF820_POWER_UP;

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

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

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

/**
 * @brief Vela IF820 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 #velaif820_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 velaif820_wait_packet ( velaif820_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code );

/**
 * @brief Vela IF820 power up function.
 * @details This function powers up the device and checks communication.
 * @param[in] ctx : Click context object.
 * See #velaif820_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 velaif820_power_up ( velaif820_t *ctx );

/**
 * @brief Vela IF820 config example function.
 * @details This function restores factory settings, sets BT Classic flags and reads the BT address and name.
 * @param[in] ctx : Click context object.
 * See #velaif820_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 velaif820_config_example ( velaif820_t *ctx );

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

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    velaif820_cfg_t velaif820_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.
    velaif820_cfg_setup( &velaif820_cfg );
    VELAIF820_MAP_MIKROBUS( velaif820_cfg, MIKROBUS_1 );
    if ( UART_ERROR == velaif820_init( &velaif820, &velaif820_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

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

void application_task ( void ) 
{
    switch ( app_state )
    {
        case VELAIF820_POWER_UP:
        {
            if ( VELAIF820_OK == velaif820_power_up( &velaif820 ) )
            {
                app_state = VELAIF820_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case VELAIF820_CONFIG_EXAMPLE:
        {
            if ( VELAIF820_OK == velaif820_config_example( &velaif820 ) )
            {
                app_state = VELAIF820_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case VELAIF820_EXAMPLE:
        {
            velaif820_example( &velaif820 );
            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 velaif820_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void velaif820_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 velaif820_process ( velaif820_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = velaif820_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 VELAIF820_OK;
    }
    return VELAIF820_ERROR;
}

static err_t velaif820_wait_packet ( velaif820_t *ctx, uint8_t timeout_s, uint8_t rsp_flag, uint8_t *cmd_code ) 
{
    err_t error_flag = VELAIF820_OK;
    uint32_t timeout_cnt = 0;
    while ( ( timeout_cnt < timeout_s ) || ( VELAIF820_WAIT_TIMEOUT_INFINITE == timeout_s ) )
    {
        error_flag = velaif820_read_packet( ctx );
        if ( VELAIF820_OK == error_flag )
        {
            if ( VELAIF820_PACKET_TYPE_EVENT == ctx->evt_pkt.rsp_flag )
            {
                log_printf ( &logger, " < EVENT >\r\n" );
            }
            else
            {
                log_printf ( &logger, " < RESPONSE >\r\n" );
            }
            
            if ( ( VELAIF820_PACKET_TYPE_EVENT == ctx->evt_pkt.rsp_flag ) && 
                 ( strstr( ctx->evt_pkt.command, VELAIF820_EVT_SYS_ERROR ) ) )
            {
                log_printf( &logger, "   Wrong CMD!\r\n" );
                error_flag = VELAIF820_ERROR_CMD;
                break;
            }
            else if ( ( ctx->evt_pkt.rsp_flag == rsp_flag ) && 
                      ( strstr( ctx->evt_pkt.command, cmd_code ) ) )
            {
                log_printf ( &logger, "   Command: %s\r\n", ctx->evt_pkt.command );
                if ( VELAIF820_PACKET_TYPE_RESPONSE == ctx->evt_pkt.rsp_flag )
                {
                    if ( ctx->evt_pkt.rsp_result )
                    {
                        log_printf( &logger, "   Result: %.4X\r\n", ctx->evt_pkt.rsp_result );
                        error_flag = VELAIF820_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 );
                }
                error_flag = VELAIF820_OK;
                break;
            }
            else
            {
                log_printf ( &logger, "   Command: %s\r\n", ctx->evt_pkt.command );
                if ( VELAIF820_PACKET_TYPE_RESPONSE == ctx->evt_pkt.rsp_flag )
                {
                    if ( ctx->evt_pkt.rsp_result )
                    {
                        log_printf( &logger, "   Result: %.4X\r\n", ctx->evt_pkt.rsp_result );
                    }
                    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 );
                }
            }
        }
        else
        {
            timeout_cnt++;
        }
    }
    if ( ( timeout_cnt >= timeout_s ) && ( 0 != timeout_s ) )
    {
        log_printf( &logger, " < TIMEOUT >\r\n" );
        error_flag = VELAIF820_ERROR_TIMEOUT;
    }
    log_printf( &logger, "--------------------------------\r\n" );
    return error_flag;
}

static err_t velaif820_power_up ( velaif820_t *ctx )
{
    err_t error_flag = VELAIF820_OK;

    log_printf( &logger, ">> Reset device.\r\n" );
    velaif820_set_cmd_mode( ctx );
    velaif820_reset_device( ctx );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_EVENT, 
                                              VELAIF820_EVT_GAP_ADV_STATE_CHANGED );

    log_printf( &logger, ">> Check communication.\r\n" );
    velaif820_cmd_action( ctx, VELAIF820_CMD_SYS_PING, NULL );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_RESPONSE, 
                                              VELAIF820_CMD_SYS_PING );

    return error_flag;
}

static err_t velaif820_config_example ( velaif820_t *ctx )
{
    err_t error_flag = VELAIF820_OK;

    log_printf( &logger, ">> Factory reset.\r\n" );
    velaif820_cmd_action( ctx, VELAIF820_CMD_SYS_FACTORY_RESET, NULL );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_EVENT, 
                                              VELAIF820_EVT_GAP_ADV_STATE_CHANGED );
    
    #define SET_BT_CLASSIC_FLAG "T=92"
    log_printf( &logger, ">> Set BT Classic flags.\r\n" );
    velaif820_cmd_set( ctx, VELAIF820_CMD_SYS_TRANSPORT, SET_BT_CLASSIC_FLAG );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_RESPONSE, 
                                              VELAIF820_CMD_SYS_TRANSPORT );
    
    log_printf( &logger, ">> Save settings.\r\n" );
    velaif820_cmd_action( ctx, VELAIF820_CMD_SYS_STORE_CONFIG, NULL );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_RESPONSE, 
                                              VELAIF820_CMD_SYS_STORE_CONFIG );
    
    log_printf( &logger, ">> Reboot.\r\n" );
    velaif820_cmd_action( ctx, VELAIF820_CMD_SYS_REBOOT, NULL );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_EVENT, 
                                              VELAIF820_EVT_GAP_ADV_STATE_CHANGED );

    log_printf( &logger, ">> Get BT address.\r\n" );
    velaif820_cmd_get( ctx, VELAIF820_CMD_SYS_BT_ADDRESS, NULL );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_RESPONSE, 
                                              VELAIF820_CMD_SYS_BT_ADDRESS );
    
    #define GET_BT_CLASSIC_NAME "T=1"
    log_printf( &logger, ">> Get device name.\r\n" );
    velaif820_cmd_get( ctx, VELAIF820_CMD_GAP_DEVICE_NAME, GET_BT_CLASSIC_NAME );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                              VELAIF820_PACKET_TYPE_RESPONSE, 
                                              VELAIF820_CMD_GAP_DEVICE_NAME );
    
    return error_flag;
}

static err_t velaif820_example ( velaif820_t *ctx )
{
    err_t error_flag = VELAIF820_OK;
    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."
    
    Delay_ms ( 100 );
    log_printf( &logger, ">> Waiting for a BT peer to establish connection with the Click board...\r\n" );
    error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_INFINITE, 
                                              VELAIF820_PACKET_TYPE_EVENT, 
                                              VELAIF820_EVT_BT_CONNECTED );
    log_printf( &logger, ">> BT peer has connected.\r\n" );
    velaif820_set_data_mode( ctx );

    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 ( ; ; )
    {
        velaif820_clear_app_buf( );
        if ( VELAIF820_OK == velaif820_process( ctx ) )
        {
            Delay_ms ( 100 );
            timeout_cnt = 0;
            velaif820_process( ctx );
            velaif820_log_app_buf( );
            if ( strstr( app_buf, TERMINATION_CMD ) )
            {
                log_printf( &logger, ">> Terminating connection on demand.\r\n" );
                error_flag |= velaif820_generic_write ( ctx, TERMINATION_RESPONSE, strlen ( TERMINATION_RESPONSE ) );
                error_flag |= velaif820_generic_write ( ctx, VELAIF820_PACKET_END, strlen ( VELAIF820_PACKET_END ) );
                Delay_ms ( 1000 );

                log_printf( &logger, ">> Disconnecting BT peer.\r\n" );
                velaif820_set_cmd_mode( ctx );
                error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                                          VELAIF820_PACKET_TYPE_EVENT, 
                                                          VELAIF820_EVT_BT_DISCONNECTED );
                break;
            }
            else if ( strstr( app_buf, VELAIF820_EVT_BT_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 );
            error_flag |= velaif820_generic_write ( ctx, MESSAGE_CONTENT, strlen ( MESSAGE_CONTENT ) );
            error_flag |= velaif820_generic_write ( ctx, VELAIF820_PACKET_END, strlen ( VELAIF820_PACKET_END ) );
            Delay_ms ( 100 );
        }
        if ( BT_TERMINAL_TIMEOUT_MS < timeout_cnt )
        {
            log_printf( &logger, ">> Terminating connection due to 60s timeout expiration.\r\n" );
            error_flag |= velaif820_generic_write ( ctx, TERMINATION_TIMEOUT, strlen ( TERMINATION_TIMEOUT ) );
            error_flag |= velaif820_generic_write ( ctx, VELAIF820_PACKET_END, strlen ( VELAIF820_PACKET_END ) );
            Delay_ms ( 1000 );

            log_printf( &logger, ">> Disconnecting BT peer.\r\n" );
            velaif820_set_cmd_mode( ctx );
            error_flag |= velaif820_wait_packet( ctx, VELAIF820_WAIT_TIMEOUT_5S, 
                                                      VELAIF820_PACKET_TYPE_EVENT, 
                                                      VELAIF820_EVT_BT_DISCONNECTED );
            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.