Intermediate
30 min

Elevate your Bluetooth audio experience with BM83 and PIC18LF26K40

Immerse in pure audio bliss

BT Audio 3 Click with EasyPIC v8

Published Nov 01, 2023

Click board™

BT Audio 3 Click

Dev Board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18LF26K40

Fully certified BT 5.0 stereo audio solution with voice and audio post-processing capability for Bluetooth audio applications

A

A

Hardware Overview

How does it work?

BT Audio 3 Click is based on the BM83 SoC, a fully certified Bluetooth v5.0 stereo audio module with high-performing voice and audio post-processing capability for Bluetooth audio applications from Microchip. Based on an onboard Bluetooth stack and audio profile design, the module supports 24-bit/96kHz audio. Integrated IS2083 dual-mode audio IC features Digital Signal Processor (DSP) that decodes AAC and SBC codecs and executes advanced audio and voice processing, such as Wide-Band (WB) speech Acoustic Echo Cancellation (AEC) and Noise Reduction (NR). More information on the many features and characteristics of the module itself can be found on the official website of the Microchip BM83 module. The BM83 module provides an I2S digital audio interface configured in Master mode to connect with the external DSP, the AK4430. In this mode, the BM83 serves as a master to provide clock and frame synchronous signals for the master/slave data synchronizations. The master clock output is delivered to an external I2S device (AK4430) to drive its system clock and save crystal costs. The BM83 module receives audio from the smartphone via its PCB antenna and then forwards it to an external speaker via the AK4430,

connected to the LINE OUT connector. The AK4430 supports Mute operation accessible through the SM pin routed to the AN pin on the mikroBUS™ socket and two audio data interface formats, MSB-first or I2S format, selectable via SMD jumper labeled as OUT SET, by positioning it to an appropriate position marked as 1 or 0. This Click board™ also has an onboard digital MEMS microphone, the SPH0641LU4H-1, populated on the bottom side of the board. The MEMS microphone enables an expansive sound range from audible frequency to ultrasonic (100Hz - 80kHz). Even though it is placed on the bottom side, with the help of the top side opening marked with MIC, an uninterrupted flow of sound to the microphone is enabled. Also, microphone data processing selection via SMD jumper labeled as MIC SEL is possible by positioning it to an appropriate position marked as 1 or 0, on which clock edge data will be asserted or latched. The BM83 communicates with MCU using the UART interface with commonly used UART RX and TX pins. It operates at 115200 bps by default configuration to transmit and exchange data with the host MCU. In addition to interface pins, this Click board™ also uses a Reset pin, RST pin on the

mikroBUS™ socket, MOD pin routed to the INT pin of the mikroBUS™ socket used to enter Test Mode during reset, and MFB pin routed to the PWM pin of the mikroBUS™ socket used for BM83 Wake-Up feature. Also, this Click board™ comes with several audio control buttons, such as volume up/down, rewind/forward, play/pause, and one multifunction button, as well as with two additional LED indicators, blue and red LEDs labeled LED1 and LED2 used for optional user-configurable visual indication. Even though this board uses both mikroBUS ™ power rails, this Click board ™ can only be operated with a 3.3V logic voltage level, selectable through a VBAT SEL jumper, which allows power supply by 3V3 or external battery. 5V is only used for the internal adapter to charge the battery in battery-powered applications. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board ™ equipped comes equipped with a library containing functions and an example code that can be used, as a reference, for further development.

BT Audio 3 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

default

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

3728

You complete me!

Accessories

These standard small stereo earphones offer a high-quality listening experience with their top-notch stereo cable and connector. Designed for universal compatibility, they effortlessly connect to all MIKROE mikromedia and multimedia boards, making them an ideal choice for your electronic projects. With a rated power of 100mW, the earphones provide crisp audio across a broad frequency range from 20Hz to 20kHz. They boast a sensitivity of 100 ± 5dB and an impedance of 32Ω ± 15%, ensuring optimal sound quality. The Φ15mm speaker delivers clear and immersive audio. Cost-effective and versatile, these earphones are perfect for testing your prototype devices, offering an affordable and reliable audio solution to complement your projects.

BT Audio 3 Click accessories image

Used MCU Pins

mikroBUS™ mapper

MUTE Mode
RA3
AN
Reset
RA0
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
BT Wake-UP
RC1
PWM
Test Mode
RB1
INT
UART TX
RC6
TX
UART RX
RC7
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
2

Take a closer look

Schematic

BT Audio 3 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
LTE IoT 5 Click front image hardware assembly
MCU DIP 28 hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
EasyPIC v8 28pin-DIP Access - 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

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for BT Audio 3 Click driver.

Key functions:

  • btaudio3_set_device_name - This function sets the local device name

  • btaudio3_music_control - This function sends a music control command with a desired action

  • btaudio3_set_eq_mode - This function sets the equalizer mode

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 BT Audio 3 Click Example.
 *
 * # Description
 * This example demonstrates the use of BT Audio 3 click board by reading the commands
 * received from remote device and performing adequate actions accordingly.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and configures the click board.
 *
 * ## Application Task
 * Reads all the received events and parses them.
 *
 * ## Additional Function
 * - static err_t btaudio3_event_handler ( btaudio3_t *ctx ) - This function handles SPP data event 
 * and several BTM state events added in. The other events will just be displayed on the USB UART in hex format.
 *
 * @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. So make sure to pair your device with the click board and
 * connect it to using the Serial Bluetooth Terminal application, then you will be able 
 * to send commands listed below.
 * 
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "btaudio3.h"

static btaudio3_t btaudio3;
static log_t logger;

// Bluetooth device name
#define DEVICE_NAME                 "BT Audio 3 click"

// SPP Commands list
#define COMMAND_PLAY                "play"          // play music
#define COMMAND_PAUSE               "pause"         // pause music
#define COMMAND_STOP                "stop"          // stop music
#define COMMAND_NEXT                "next"          // next song
#define COMMAND_PREVIOUS            "prev"          // previous song
#define COMMAND_VOLUME_UP           "up"            // volume up
#define COMMAND_VOLUME_DOWN         "down"          // volume down
#define COMMAND_UNMUTE              "unmute"        // unmute output
#define COMMAND_MUTE                "mute"          // mute output
#define COMMAND_MODE_UP             "mode"          // switch equalizer mode
#define COMMAND_CALL                "call"          // call command followed by the nuber
#define COMMAND_VOICE               "voice"         // start voice recognition app

/**
 * @brief BT Audio 3 event handler function.
 * @details This function handles SPP data event and several BTM state events added in.
 * The other events will just be displayed on the USB UART in hex format.
 * @param[in] ctx : Click context object.
 * See #btaudio3_t object definition for detailed explanation.
 * @return @li @c  >=0 - Command ACK event response,
 *         @li @c   -1 - Error.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t btaudio3_event_handler ( btaudio3_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    btaudio3_cfg_t btaudio3_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.
    btaudio3_cfg_setup( &btaudio3_cfg );
    BTAUDIO3_MAP_MIKROBUS( btaudio3_cfg, MIKROBUS_1 );
    if ( UART_ERROR == btaudio3_init( &btaudio3, &btaudio3_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( BTAUDIO3_OK != btaudio3_default_cfg ( &btaudio3 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    if ( BTAUDIO3_OK != btaudio3_set_device_name ( &btaudio3, DEVICE_NAME ) )
    {
        log_error( &logger, " Set device name." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    if ( BTAUDIO3_OK == btaudio3_read_event ( &btaudio3 ) ) 
    {
        btaudio3_event_handler ( &btaudio3 );
    }
}

void main ( void ) 
{
    application_init( );

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

static err_t btaudio3_event_handler ( btaudio3_t *ctx )
{
    err_t error_flag = BTAUDIO3_OK;
    static btaudio3_eq_mode_t eq_mode = BTAUDIO2_EQ_MODE_OFF;
    switch ( ctx->event_packet.opcode )
    {
        case BTAUDIO3_EVT_REPORT_SPP_DATA:
        {
            if ( 0 == ctx->event_packet.param_buf[ 1 ] ) // single packet
            {                
                uint16_t payload_len = ( ( uint16_t ) ctx->event_packet.param_buf[ 4 ] << 8 ) | 
                                                      ctx->event_packet.param_buf[ 5 ];
                if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PLAY ) )
                {
                    error_flag |= btaudio3_music_control ( &btaudio3, BTAUDIO3_PLAY );
                    log_printf( &logger, " > play music\r\n\n" );
                } 
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PAUSE ) )
                {
                    error_flag |= btaudio3_music_control ( &btaudio3, BTAUDIO3_PAUSE );
                    log_printf( &logger, " > pause music\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_STOP ) )
                {
                    error_flag |= btaudio3_music_control ( &btaudio3, BTAUDIO3_STOP );
                    log_printf( &logger, " > stop music\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_NEXT ) )
                {
                    error_flag |= btaudio3_music_control ( &btaudio3, BTAUDIO3_NEXT_SONG );
                    log_printf( &logger, " > next song\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_PREVIOUS ) )
                {
                    error_flag |= btaudio3_music_control ( &btaudio3, BTAUDIO3_PREVIOUS_SONG );
                    log_printf( &logger, " > previous song\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOLUME_UP ) )
                {
                    error_flag |= btaudio3_volume_up ( &btaudio3, 0, BTAUDIO3_VOLUME_MASK_A2DP );
                    log_printf( &logger, " > volume up\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOLUME_DOWN ) )
                {
                    error_flag |= btaudio3_volume_down ( &btaudio3, 0, BTAUDIO3_VOLUME_MASK_A2DP );
                    log_printf( &logger, " > volume down\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_UNMUTE ) )
                {
                    btaudio3_soft_unmute_output ( &btaudio3 );
                    log_printf( &logger, " > unmute output\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_MUTE ) )
                {
                    btaudio3_soft_mute_output ( &btaudio3 );
                    log_printf( &logger, " > mute output\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_CALL ) )
                {
                    uint8_t phone_number[ 19 ] = { 0 };
                    memcpy ( phone_number, strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_CALL ) + 5, payload_len - 7 );
                    error_flag |= btaudio3_make_call ( &btaudio3, 0x00, phone_number );
                    log_printf( &logger, " > calling number: %s\r\n\n", phone_number );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_VOICE ) )
                {
                    error_flag |= btaudio3_send_mmi_action ( ctx, 0, BTAUDIO3_MMI_VOICE_DIAL );
                    log_printf( &logger, " > start voice recognition\r\n\n" );
                }
                else if ( strstr ( &ctx->event_packet.param_buf[ 6 ], COMMAND_MODE_UP ) )
                {
                    if ( BTAUDIO2_EQ_MODE_USER1 == eq_mode )
                    {
                        eq_mode = BTAUDIO2_EQ_MODE_OFF;
                    }
                    else
                    {
                        eq_mode++;
                    }
                    btaudio3_set_eq_mode ( &btaudio3, eq_mode );
                    log_printf( &logger, " > equalizer mode: " );
                    switch ( eq_mode )
                    {
                        case BTAUDIO2_EQ_MODE_OFF:
                        {
                            log_printf( &logger, "off\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_SOFT:
                        {
                            log_printf( &logger, "soft\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_BASS:
                        {
                            log_printf( &logger, "bass\r\n\n" );
                            break;
                        } 
                        case BTAUDIO2_EQ_MODE_TREBLE:
                        {
                            log_printf( &logger, "treble\r\n\n" );
                            break;
                        }  
                        case BTAUDIO2_EQ_MODE_CLASSIC:
                        {
                            log_printf( &logger, "classic\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_ROCK:
                        {
                            log_printf( &logger, "rock\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_JAZZ:
                        {
                            log_printf( &logger, "jazz\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_POP:
                        {
                            log_printf( &logger, "pop\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_DANCE:
                        {
                            log_printf( &logger, "dance\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_RNB:
                        {
                            log_printf( &logger, "rnb\r\n\n" );
                            break;
                        }
                        case BTAUDIO2_EQ_MODE_USER1:
                        {
                            log_printf( &logger, "user1\r\n\n" );
                            break;
                        }
                        default:
                        {
                            log_printf( &logger, "unknown\r\n\n" );
                            break;
                        }
                    }
                }
                else
                {
                    log_printf( &logger, " Unknown command: ", &ctx->event_packet.param_buf[ 6 ] );
                    for ( uint16_t cnt = 0; cnt < payload_len; cnt++ )
                    {
                        log_printf( &logger, "%c", ctx->event_packet.param_buf[ cnt + 6 ] );
                    }
                    log_printf( &logger, "\r\n\n" );
                }
            }
            break;
        }
        case BTAUDIO3_EVT_BTM_STATE:
        {
            switch ( ctx->event_packet.param_buf[ 0 ] )
            {
                case BTAUDIO3_BTM_STATE_PAIRING_SUCCESSFULL:
                {
                    log_printf( &logger, " < Pairing successfull - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO3_BTM_STATE_SCO_LINK_CONNECTED:
                {
                    log_printf( &logger, " < SCO link connected - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO3_BTM_STATE_SCO_LINK_DISCONNECTED:
                {
                    log_printf( &logger, " < SCO link disconnected - linked device ID: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO3_BTM_STATE_ACL_CONNECTED:
                {
                    log_printf( &logger, " < ACL connected - linked data base: %u\r\n\n", 
                                ( uint16_t ) ctx->event_packet.param_buf[ 1 ] );
                    break;
                }
                case BTAUDIO3_BTM_STATE_ACL_DISCONNECTED:
                {
                    log_printf( &logger, " < ACL disconnected - " );
                    if ( 0 == ctx->event_packet.param_buf[ 1 ] )
                    {
                        log_printf( &logger, "disconnection\r\n\n" );
                    }
                    else if ( 1 == ctx->event_packet.param_buf[ 1 ] )
                    {
                        log_printf( &logger, "link loss\r\n\n" );
                    }
                    break;
                }
                case BTAUDIO3_BTM_STATE_STANDBY_STATE:
                {
                    log_printf( &logger, " < Standby state\r\n\n" );
                    log_printf( &logger, " > ReEnter pairing mode\r\n\n" );
                    error_flag |= btaudio3_enter_pairing_mode ( &btaudio3 );
                    break;
                }
                case BTAUDIO3_BTM_STATE_UNKNOWN_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < Unknown audio source\r\n\n" );
                    break;
                }
                case BTAUDIO3_BTM_STATE_AUX_IN_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < AUX-IN audio source\r\n\n" );
                    break;
                }
                case BTAUDIO3_BTM_STATE_A2DP_AUDIO_SOURCE:
                {
                    log_printf( &logger, " < A2DP audio source\r\n\n" );
                    break;
                }
                default:
                {
                    log_printf( &logger, " < EVENT BTM STATE: " );
                    for ( uint16_t cnt = 0; cnt < ctx->event_packet.param_len; cnt++ )
                    {
                        log_printf( &logger, "0x%.2X ", ( uint16_t ) ctx->event_packet.param_buf[ cnt ] );
                    }
                    log_printf( &logger, "\r\n\n" );
                    break;
                }
            }
            break;
        }
        default: 
        {
            log_printf( &logger, " < EVENT 0x%.2X: ", ( uint16_t ) ctx->event_packet.opcode );
            for ( uint16_t cnt = 0; cnt < ctx->event_packet.param_len; cnt++ )
            {
                log_printf( &logger, "0x%.2X ", ( uint16_t ) ctx->event_packet.param_buf[ cnt ] );
            }
            log_printf( &logger, "\r\n\n" );
            break;
        }
    }
    return error_flag;
}

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

Additional Support

Resources