Beginner
10 min

Stay informed and entertained with Si4703 and PIC32MZ2048EFM100

Tune in, turn up, and rock on!

FM Click with Curiosity PIC32 MZ EF

Published Jan 31, 2024

Click board™

FM Click

Dev. board

Curiosity PIC32 MZ EF

Compiler

NECTO Studio

MCU

PIC32MZ2048EFM100

Just plug in your headphones and access your favorite stations wherever you go!

A

A

Hardware Overview

How does it work?

FM Click is based on the Si4703, a broadcast FM radio tuner from Silicon Labs. The radio tuner works in a worldwide FM band from 76-108MHz, whereas the antenna uses headphones. The stereo audio connector supports three and four-conductor earphones with a recommended cable length from 1.1m to 1.45m for the best signal reception. The Si4703, one of the industry’s smallest FM tuners, comes with a 32.768kHz reference clock for better frequency tolerance. It has two audio outputs, left and right. Each output uses an LM4864, an audio power amplifier from Texas Instruments, to amplify

the channel outputs. These amplifiers can deliver about 200mW of continuous average power into an 8Ω load. The FM Click is also used as a stereo device and mono. The FM Click can communicate to the host MCU over the I2C serial interface of the mikroBUS™ socket. Besides communication pins, this board also uses several others. The SEN pin routed to the CS pin of the mikroBUS™ socket serves as a serial interface activation signal, which, combined with I2C pins, forms a 3-wire interface. The RST pin is used as a general reset feature alongside two user-configurable pins, GP2 and

GP1, routed to the AN and INT pins of the mikroBUS™ socket. These I/O pins can be used as interrupt requests (seek/tune or RDS ready) or stereo/mono indicators. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

FM Click hardware overview image

Features overview

Development board

Curiosity PIC32 MZ EF development board is a fully integrated 32-bit development platform featuring the high-performance PIC32MZ EF Series (PIC32MZ2048EFM) that has a 2MB Flash, 512KB RAM, integrated FPU, Crypto accelerator, and excellent connectivity options. It includes an integrated programmer and debugger, requiring no additional hardware. Users can expand

functionality through MIKROE mikroBUS™ Click™ adapter boards, add Ethernet connectivity with the Microchip PHY daughter board, add WiFi connectivity capability using the Microchip expansions boards, and add audio input and output capability with Microchip audio daughter boards. These boards are fully integrated into PIC32’s powerful software framework, MPLAB Harmony,

which provides a flexible and modular interface to application development a rich set of inter-operable software stacks (TCP-IP, USB), and easy-to-use features. The Curiosity PIC32 MZ EF development board offers expansion capabilities making it an excellent choice for a rapid prototyping board in Connectivity, IOT, and general-purpose applications.

Curiosity PIC32MZ EF double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

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.

FM Click accessories image

Used MCU Pins

mikroBUS™ mapper

General Purpose I/O
RPB4
AN
Reset
RA9
RST
Serial Enable Input
RPD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
General Purpose I/O
RF13
INT
NC
NC
TX
NC
NC
RX
Serial Clock Input
RPA14
SCL
Serial Data Input
RPA15
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

FM Click Schematic schematic

Step by step

Project assembly

Curiosity PIC32MZ EF front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity PIC32 MZ EF as your development board.

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity PIC32 MZ EF MB 1 Access - upright/background 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
Curiosity PIC32 MZ EF 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

This library contains API for FM Click driver.

Key functions:

  • fm_get_received_signal_strength_indicator - This function reads recived signal strength indicatior

  • fm_get_channel_frequency - This function calculates current channel frequency based on band and space settings

  • fm_get_channel - This function reads CHANNEL bits from READCHAN register

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 
 * \brief Fm Click example
 * 
 * # Description
 * This click represent FM radio tuner which supports worldwide FM band (76 – 108 MHz)
 * and has a set of features such as automatic frequency and gain control, seek tuning and volume control.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializing I2C driver, powering up device, setting basic settings for Europe, 
 * setting values of seek threshold, volume, snr threshold and impulse detection threshold.
 * Seek and memorize 5 radio stations with a signal strength above the set limit.
 * 
 * ## Application Task  
 * Tunes all memorized stations. Switches the stations each 10 seconds.
 * 
 * ## Additional Functions
 * - void fm_case_plus( fm_t *ctx )      - Increases volume
 * - void fm_case_minus( fm_t *ctx )     - Decreases volume
 * - void fm_case_seek( fm_t *ctx )      - Seeks next station
 * - void fm_case_tune( fm_t *ctx )      - Tunes default station
 * - void fm_case_memorize( )            - Memorizes current station
 * - void fm_case_station1( fm_t *ctx )  - Tunes memorized station 1
 * - void fm_case_station2( fm_t *ctx )  - Tunes memorized station 2
 * - void fm_case_station3( fm_t *ctx )  - Tunes memorized station 3
 * - void fm_case_station4( fm_t *ctx )  - Tunes memorized station 4
 * - void fm_case_station5( fm_t *ctx )  - Tunes memorized station 5
 * - void fm_case_mute( fm_t *ctx )      - Mutes device
 * - void fm_case_tune_up( fm_t *ctx )   - Fine tunes frequency
 * - void fm_case_tune_down( fm_t *ctx ) - Fine tunes frequency
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "fm.h"

// ------------------------------------------------------------------ VARIABLES

#define SIGNAL_STRENGTH_LOWER_LIMIT 25

static fm_t fm;
static log_t logger;

static uint16_t received_signal_strength_indicator;
static uint16_t station_channel;
static uint16_t station1;
static uint16_t station2;
static uint16_t station3;
static uint16_t station4;
static uint16_t station5;

static uint8_t memory;
static uint8_t mute;
static uint8_t received_data;
static uint8_t data_ready;
static uint8_t error_flag;
static uint8_t cnt;

static float channel_frequency;
static float tuned_frequency;
static float tune_freq;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

void fm_case_plus ( fm_t *ctx  )
{
    error_flag = fm_volume_up( ctx );

    if ( error_flag == 0 )
    {
        log_printf( &logger, "volume up\r\n" );
    }
    else
    {
        log_printf( &logger, "volume max\r\n" );
    }
}

void fm_case_minus ( fm_t *ctx )
{
    error_flag = fm_volume_down( ctx );

    if ( error_flag == 0 )
    {
        log_printf( &logger, "volume down\r\n" );
    }
    else
    {
        log_printf( &logger, "volume min\r\n" );
    }
}

void fm_case_seek ( fm_t *ctx )
{
    fm_seek( ctx );

    Delay_ms( 500 );

    fm_end_seek( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );
    station_channel = fm_get_channel( ctx );
}

void fm_case_tune ( fm_t *ctx )
{
    error_flag = fm_tune( ctx, tune_freq );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    if ( error_flag == 0 )
    {
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        tuned_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx );

        log_printf( &logger, "tune complete\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", tuned_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "frequency not in valid range\r\n" );
    }
}

void fm_case_memorize ( )
{
    switch ( memory )
    {
        case 0 :
        {
            station1 = station_channel;
            memory += 1;

            log_printf( &logger, "station 1 memorized\r\n" );

            break;
        }
        case 1 :
        {
            station2 = station_channel;
            memory += 1;

            log_printf( &logger, "station 2 memorized\r\n" );

            break;
        }
        case 2 :
        {
            station3 = station_channel;
            memory += 1;

            log_printf( &logger, "station 3 memorized\r\n" );
            
            break;
        }
        case 3 :
        {
            station4 = station_channel;
            memory += 1;

            log_printf( &logger, "station 4 memorized\r\n" );

            break;
        }
        case 4 :
        {
            station5 = station_channel;
            memory = 0;

            log_printf( &logger, "station 5 memorized\r\n" );

            break;
        }
        default :
        {
            break;
        }
    }
}

void fm_case_mute ( fm_t *ctx )
{
    if ( mute == 0 )
    {
        fm_mute_enable( ctx );

        log_printf( &logger, "mute enabled\r\n" );

        mute = 1;
    }
    else if ( mute == 1 )
    {
        fm_mute_disable( ctx );

        log_printf( &logger, "mute disabled\r\n" );

        mute = 0;
    }
}

void fm_case_station_1 ( fm_t *ctx  )
{
    fm_tune_channel( ctx, station1 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 1 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_2 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station2 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 2 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_3 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station3 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 3 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_4 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station4 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 4 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_5 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station5 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 5 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_tune_up ( fm_t *ctx )
{
    error_flag = fm_fine_tune_up( ctx );

    if ( error_flag == 0 )
    {
        Delay_ms( 100 );

        fm_end_tune( ctx );

        Delay_ms( 10 );
        
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        channel_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx ); 

        log_printf( &logger, "tune up\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "upper band limit reached\r\n" );
    }
}

void fm_case_tune_down ( fm_t *ctx )
{
    error_flag = fm_fine_tune_down( ctx );

    if ( error_flag == 0 )
    {
        Delay_ms( 100 );

        fm_end_tune( ctx );

        Delay_ms( 10 );
    
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        channel_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx );

        log_printf( &logger, "tune down\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "lower band limit reached\r\n" );
    }
}

void fm_case_wrong_command ( )
{
    log_printf( &logger, "wrong command\r\n" );
}

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    fm_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 ----" );

    //  Click initialization.

    fm_cfg_setup( &cfg );
    FM_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    fm_init( &fm, &cfg );
    
    Delay_ms( 500 );
    fm_default_cfg( &fm );

    memory = 0;
    mute = 0;
    fm_case_mute( &fm );
     
    for ( cnt = 0; cnt < 5;  )
    {
        log_printf( &logger, "seeking...\r\n" );
        do 
        {
            received_signal_strength_indicator = 0;
            fm_case_seek( &fm );
        }
        while ( received_signal_strength_indicator < SIGNAL_STRENGTH_LOWER_LIMIT ); //rssi value
        
        log_printf( &logger, "station found\r\n" );
        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );
        log_printf( &logger, "channel frequency: %.2f MHz\r\n", channel_frequency );
        fm_case_memorize( );
        log_printf( &logger, "-----------------------\r\n" );
        Delay_ms( 100 );
        cnt++;
    }  
    
    mute = 1;
    fm_case_mute( &fm );
    log_printf( &logger, "playing memorized stations...\r\n\r\n" );
}

void application_task ( void )
{ 
    fm_case_station_1( &fm );
    Delay_ms( 10000 );
       
    fm_case_station_2( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_3( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_4( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_5( &fm );
    Delay_ms( 10000 );
}

void main ( void )
{
    application_init( );

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

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