Intermediate
20 min

Integrate dual-mode Bluetooth (BR/EDR and LE) wireless capabilities into your projects with BM78 and PIC18LF46K22

Fully certified 2.4GHz Bluetooth Classic (BR/EDR) and Bluetooth Low Energy (LE) wireless solution

BM78 Click with EasyPIC v8

Published Aug 05, 2024

Click board™

BM78 Click

Dev. board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18LF46K22

Enable dual-mode Bluetooth wireless connectivity for IoT, secure payment systems, home automation, and industrial applications

A

A

Hardware Overview

How does it work?

BM78 Click is based on the BM78, a fully certified 2.4GHz Bluetooth (BR/EDR/LE) wireless module from Microchip. It is designed to integrate dual-mode Bluetooth wireless capability into various projects easily. The BM78 is built around Microchip's IS1678 Bluetooth Dual mode SoC, specifically the ROM-based BM78SPPX5NC2 version. The module includes an on-board Bluetooth stack, power management subsystem, 2.4GHz transceiver, and RF power amplifier. It supports GAP, SDP, SPP, and GATT profiles, enabling data transfer through transparent UART mode for easy integration with any MCU with a UART interface. This makes it ideal for connecting products to smartphones or tablets for convenient data transfer, control, cloud application access, and local connectivity for IoT, secure payment systems, home automation, security, industrial applications, and data logging. BM78 Click provides flexibility with two operational modes: Auto-Pattern and Manual-Pattern. These modes use different state machines and can be selected by setting the appropriate value in the EEPROM memory. By

default, the BM78 module operates in Auto-Pattern mode. The board also includes a MODE SEL switch that allows users to set the module in one of two modes: application mode for normal operation or test mode to change EEPROM values. The module operates normally when all three switches are in the HIGH position. The module enters test mode if only the first switch (1) is in the LOW position. As mentioned, communication between the BM78 and the host MCU is made through a UART interface, standard UART RX and TX pins, and hardware flow control pins (CTS and RTS) for efficient data transfer. The BM78 Click also features a reset (RST) pin for hard resetting the module and two status indicators on the ST1 and ST2 pins. These pins provide various status indications to the host MCU, such as Power-On, deep state, access state, and link state indications, showing whether UART data is being transmitted or not. In addition, this board also includes a SW BT switch, which acts as a software power button, allowing the user to power the BM78 module ON (high) or switch it OFF (low) into Deep Sleep mode to reduce power

consumption. Also, the board features a WAKE button, which transitions the module from Sleep mode to Standby mode, a user-configurable red LED indicator labeled LD2, which indicates various statuses such as standby, link back, low battery, inquiry, or link, and two unpopulated 1x3 headers that provide access to several I/O pins of the BM78. These pins can perform multiple functions, including low battery indication, RSSI, link drop, UART RX, pairing key, and inquiry control, among others. This Click board™, and the module itself, can be operated only with a 3.3V logic voltage level. For this reason, in addition to being powered via a mikroBUS™ socket, users can also opt for external battery power, with power selection managed through the VCC SEL jumper. 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.

BM78 Click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. 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, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board 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 DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC 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.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18LF46K22

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3896

Used MCU Pins

mikroBUS™ mapper

Module Status Indicator 1
RA2
AN
Module Reset / ID SEL
RE1
RST
UART CTS / ID COMM
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Module Status Indicator 2
RC0
PWM
UART RTS
RB0
INT
UART TX
RC6
TX
UART RX
RC7
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

BM78 Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyPIC v8 DIP 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 DIP 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

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

This library contains API for BM78 Click driver.

Key functions:

  • bm78_eeprom_send_cmd - This function is used to send specific EEPROM command by using UART serial interface.

  • bm78_eeprom_write - This function is used to write data into the EEPROM location specified by the address parameter.

  • bm78_flash_eeprom - This function is used write default configuration into the EEPROM.

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 BM78 Click Example.
 *
 * # Description
 * This example demonstrates the use of BM78 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 by writing it into the EEPROM.
 *
 * ## Application Task
 * Reads and processes all incoming data from the Serial Bluetooth Terminal smartphone application and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void bm78_clear_app_buf ( void )
 * - static void bm78_log_app_buf ( void )
 * - static err_t bm78_process ( bm78_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 Ilic
 *
 */     
            
#include "board.h"
#include "log.h"            
#include "bm78.h"

// Application buffer size
#define APP_BUFFER_SIZE             500
#define PROCESS_BUFFER_SIZE         200

static bm78_t bm78;
static log_t logger;

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

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

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

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

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    bm78_cfg_t bm78_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.
    bm78_cfg_setup( &bm78_cfg );
    BM78_MAP_MIKROBUS( bm78_cfg, MIKROBUS_1 );
    if ( UART_ERROR == bm78_init( &bm78, &bm78_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    uint8_t tmp_data[ 16 ];
    bm78_generic_read( &bm78, &tmp_data, 1 );  
    Delay_ms ( 100 );

    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    log_printf( &logger, " Place Click into Write EEPROM mode \r\n" );
    log_printf( &logger, " By setting MODE SEL in the following configuration \r\n" );
    log_printf( &logger, "         | 1 | 2 | 3 |             \r\n" );
    log_printf( &logger, "         | H | L | L |             \r\n" );
    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    log_printf( &logger, " Send YES once you placed Click into Write EEPROM mode \r\n" );
    #define WANTED_ANSWER "YES/r/n"
    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    while ( 1 )
    {
        log_read( &logger, &tmp_data, 5 );
        
        if ( 0 == strstr ( WANTED_ANSWER, tmp_data ) )
        {
            break;
        }
        else
        {
            log_printf( &logger, " Send YES once you placed Click into Write EEPROM mode \r\n" );
        }
    }
    bm78_hw_reset( &bm78 );
    log_printf( &logger, " Writing into the EEPROM \r\n" );
    if ( BM78_ERROR == bm78_flash_eeprom ( &bm78 ) )
    {
        log_error( &logger, " EEPROM Flash failed. " );
        log_printf( &logger, " Check Selected Click mode. \r\n" );
        for ( ; ; );
    }

    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    log_printf( &logger, " Place Click into Application mode \r\n" );
    log_printf( &logger, " By setting MODE SEL in the following configuration \r\n" );
    log_printf( &logger, "         | 1 | 2 | 3 |             \r\n" );
    log_printf( &logger, "         | L | L | L |             \r\n" );
    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    log_printf( &logger, " Send YES once you placed Click into Application mode \r\n" );
    log_printf( &logger, " = = = = = = = = = = = = = = = = = \r\n" );
    while ( 1 )
    {
        log_read( &logger, &tmp_data, 5 );
        
        if ( 0 == strstr ( WANTED_ANSWER, tmp_data ) )
        {
            break;
        }
        else
        {
            log_printf( &logger, " Send YES once you placed Click into Application mode \r\n" );
        }
    }
    bm78_hw_reset( &bm78 );

    log_info( &logger, " Application Task " );
    log_printf( &logger, " Connect to the device using the Serial Bluetooth Terminal App \r\n\r\n" );
}

void application_task ( void ) 
{
    if ( BM78_OK == bm78_process( &bm78 ) ) 
    {
        bm78_log_app_buf( );
        bm78_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 bm78_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void bm78_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 bm78_process ( bm78_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = bm78_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 BM78_OK;
    }
    return BM78_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.