Intermediate
30 min

Unlock the magic of Bluetooth with BGM220P and TM4C129ENCPDT

Our Bluetooth marvel!

BLE 9 Click with Fusion for Tiva v8

Published Jul 29, 2023

Click board™

BLE 9 Click

Dev Board

Fusion for Tiva v8

Compiler

NECTO Studio

MCU

TM4C129ENCPDT

Discover the true essence of wireless convenience with our advanced Bluetooth solution, connecting your devices effortlessly and eliminating the hassle of cables

A

A

Hardware Overview

How does it work?

BLE 9 Click is based on the BGM220P, an RF performance Bluetooth Low Energy solution that provides BT/BLE connectivity for any embedded application from Silicon Labs. It supports Bluetooth 5.2, direction-finding, and Bluetooth Mesh Low Power Node protocols to deliver industry-leading accuracy. It has worldwide regulatory certifications and a fully-upgradeable software stack as advanced development and debugging tool. The BGM220P module combines the EFR32BG22 wireless System on a Chip (SoC), required decoupling capacitors and inductors, 38.4 MHz and 32.768 kHz crystals, an RF matching circuit, and an integrated ceramic onboard chip antenna. The EFR32BG22 SoC, inside the BGM220P module, includes an Arm Cortex-M33 processing core, up to 32Kb of RAM, up to 512kB of flash memory, and a 2.4GHz radio transceiver, offering up to 8dB output power. This Click board™ offers enhanced performance,

security, and reliability to support IoT products running on Bluetooth networks. BLE 9 Click communicates with MCU using the UART interface as its default communication protocol with the option for the users to use other interfaces, such as SPI and I2C, if they want to configure the module and write the library by themselves using these protocols. It also can be used in a stand-alone SoC configuration without an external host processor. In addition to these protocol pins, this Click board™ also has serial UART connections labeled as CTS and RTS, routed on the CS and INT pins of the mikroBUS™ socket, as well as the Reset pin provided and routed at the RST pin of the mikroBUS™ socket. An additional GPIO pin, labeled as IO routed on the PWM pin of the mikroBUS™ socket, is left for configuration purposes as the user desires. An onboard jumper selects the function of the CS mikroBUS™ pin between the SPI or UART communication pin.

Selection is performed by positioning the SMD jumper, labeled as CTS or CS, to an appropriate position. At the bottom of the BLE 9 Click is an additional header, the Mini Simplicity Debug Connector, which fully supports debugging and programming capabilities. With this header, the user can use a serial wire debug interface for programming and debugging, using SWCLK and SWDIO pins, with a Virtual UART COM port and Virtual UART-SWD-based interface also available through the SWD interface (SWDIO, SWCLK, and SWO). 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. Also, it comes equipped with a library containing functions and an example code that can be used, as a reference, for further development.

BLE 9 Click hardware overview image

Features overview

Development board

Fusion for TIVA v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different 32-bit ARM® Cortex®-M based MCUs from Texas Instruments, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over a WiFi network. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, Fusion for TIVA v8 provides a fluid and immersive working experience, allowing access

anywhere and under any circumstances at any time. Each part of the Fusion for TIVA v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. Fusion for TIVA v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Fusion for Tiva v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

Texas Instruments

Pin count

128

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PK3
RST
UART CTS / SPI Chip Select
PH0
CS
SPI Clock
PQ0
SCK
SPI Data OUT
PQ3
MISO
SPI Data IN
PQ2
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
User-Configurable I/0
PL4
PWM
UART RTS
PQ4
INT
UART TX
PK1
TX
UART RX
PK0
RX
I2C Clock
PD2
SCL
I2C Data
PD3
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

BLE 9 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Fusion for Tiva v8 as your development board.

Fusion for PIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
v8 SiBRAIN 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

Track your results in real time

Application Output via UART Mode

1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.

2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.

3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.

4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART_Application_Output

Software Support

Library Description

This library contains API for BLE 9 Click driver.

Key functions:

  • ble9_adv_create_id - This function creates adequate ID

  • ble9_adv_start - This function starts advertising

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

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

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

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * 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 ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

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 ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

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

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

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * 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 ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

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 ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

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

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

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * 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 ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

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 ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ 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.