Intermediate
30 min

Explore your favorite melodies with Si4731 and STM32F031K6

From AM's soulful beats to FM's vibrant tunes

AM/FM Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

AM/FM Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Immerse yourself in a symphony of sound as our radio receiver opens up the airwaves, bringing the rich tapestry of AM and FM music directly to your ears

A

A

Hardware Overview

How does it work?

AM/FM Click is based on the Si4731, a digital CMOS AM/FM radio receiver IC that integrates the complete broadcast tuner and receiver function from antenna input to digital audio output from Silicon Labs. The audio signal from the output of the Si4731 is brought to a mini 3.5 female jack on board over the LM4910 - an output capacitor-less stereo 35mW headphone amplifier from Texas Instruments. That way, it is ensured that the user can plug in the headphones directly into the Click board™ without the need for any external amplifier. The Si4731 IC The device leverages the Silicon Labs broadcast-proven digital low-IF architecture, enabling a cost-effective digital audio platform for consumer electronic applications with high TDMA noise immunity, superior radio performance, and high fidelity audio power amplification. The audio signal is processed to

have the optimal dynamic qualities. The integrated DSP also handles the signal's stereo MPX encoding and FM modulation. The low-level digital intermediate frequency (IF) signal is filtered out and sent to the outputs, amplified, filtered, and digitized with high-resolution analog-to-digital converters (ADCs). This advanced architecture allows the Si4731- to perform channel selection, FM demodulation, and stereo audio processing to achieve superior performance compared to traditional analog architectures. The Click is designed for communication over the I2C/2-wire control interface. When selecting 2-wire mode, the SCLK pin should stay at a HIGH logic level during the rising edge on the RST pin and stay HIGH until after the first start condition. Also, a start condition must not occur within 300nS before the rising edge on the RST pin. The 2-wire

bus mode uses only the SCL and SDA pins for communication. The Si4731 IC has the capability of the received signal measurement. The antenna used to broadcast the signal can also be used to accept the incoming signal sent by the receiving device. Although it can be used both to receive and transmit signals, the antenna can't operate in both modes simultaneously. This feature can be useful when calibrating the transmission power of the click board. 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.

AM/FM Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

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.

AM/FM Click accessories image

Used MCU Pins

mikroBUS™ mapper

General-Purpose Output 1
PA0
AN
Reset
PA11
RST
I2C Address Selection
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Shutdown
PA8
PWM
General-Purpose Output 2
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

AM/FM Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU Access 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
STM32 M4 Clicker HA MCU/Select 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 via Debug Mode

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

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for AM/FM Click driver.

Key functions:

  • amfm_tune_up - This function increments current frequency for 10 KHz

  • amfm_set_volume - This function sets volume level in range: 0 - 63

  • amfm_get_stc -This function checks STC bit state

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 
 * \brief AmFm Click example
 * 
 * # Description
 * This app simulate RADIO RECEIVER.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes device.
 * 
 * ## Application Task  
 * Several additional functions are executed and printed over the terminal.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "amfm.h"

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

static amfm_t amfm;
static log_t logger;

float aux;
uint8_t volume = 0x3F;
uint8_t mute_flag = 0;
uint8_t status;
uint16_t station_1 = 0;
uint16_t station_2 = 0;
uint16_t station_3 = 0;
uint16_t station_4 = 0;
uint16_t station_5 = 0;
uint16_t station_frequency = 0;
uint8_t memory = 0;

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

void amfm_case_memorize ( )
{
    switch ( memory )
    {
        case 0 :
        {
            station_1 = station_frequency;
            memory += 1;
            log_printf( &logger, "> > > station 1 memorized\r\n" );
            break;
        }
        case 1 :
        {
            station_2 = station_frequency;
            memory += 1;
            log_printf( &logger, "> > > station 2 memorized\r\n" );
            break;
        }
        case 2 :
        {
            station_3 = station_frequency;
            memory += 1;
            log_printf( &logger, "> > > station 3 memorized\r\n" );
            break;
        }
        case 3 :
        {
            station_4 = station_frequency;
            memory += 1;
            log_printf( &logger, "> > > station 4 memorized\r\n" );
            break;
        }
        case 4 :
        {
            station_5 = station_frequency;
            memory = 0;
            log_printf( &logger, "> > > station 5 memorized\r\n" );
            break;
        }
        default :
        {
            break;
        }
    }
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_station_1 ( amfm_t *ctx )
{
    log_printf( &logger, "> > > tune station 1 \r\n" );
    amfm_tune_frequency( ctx, station_1 );
    log_printf( &logger, "> > > tune done \r\n" );
    aux = station_1 / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_station_2 ( amfm_t *ctx )
{
    log_printf( &logger, "> > > tune station 2 \r\n" );
    amfm_tune_frequency( ctx, station_2 );
    log_printf( &logger, "> > > tune done \r\n" );
    aux = station_2 / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_station_3 ( amfm_t *ctx )
{
    log_printf( &logger, "> > > tune station 3 \r\n" );
    amfm_tune_frequency( ctx, station_3 );
    log_printf( &logger, "> > > tune done \r\n" );
    aux = station_3 / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_station_4 ( amfm_t *ctx )
{
    log_printf( &logger, "> > > tune station 4 \r\n" );
    amfm_tune_frequency( ctx, station_4 );
    log_printf( &logger, "> > > tune done \r\n" );
    aux = station_4 / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_station_5 ( amfm_t *ctx )
{
    log_printf( &logger, "> > > tune station 5 \r\n" );
    amfm_tune_frequency( ctx, station_5 );
    log_printf( &logger, "> > > tune done \r\n" );
    aux = station_5 / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_seek ( amfm_t *ctx )
{
    log_printf( &logger, "> > > seek \r\n" );
    amfm_seek( ctx );
    log_printf( &logger, "> > > seek done \r\n" );
    station_frequency =  amfm_get_channel( ctx );
    aux = station_frequency / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_plus ( amfm_t *ctx )
{
    if ( volume < 63 )
    {
        volume += 1;
        amfm_set_volume( ctx, volume );
        log_printf( &logger, "> > > volume: %u \r\n", volume );
    }
    else
    {
        log_printf( &logger, "> > > volume: MAX \r\n" );
    }
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_minus ( amfm_t *ctx )
{
    if ( volume > 0 )
    {
        volume -= 1;
        amfm_set_volume( ctx, volume );
        log_printf( &logger, "> > > volume: %u \r\n", volume );
    }
    else
    {
        log_printf( &logger, "> > > volume: MIN \r\n" );
    }
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_mute ( amfm_t *ctx )
{
    if ( 0 == mute_flag )
    {
        amfm_mute( ctx );
        log_printf( &logger, "> > > mute ON \r\n" );
        mute_flag = 1;
    }
    else
    {
        amfm_unmute( ctx );
        log_printf( &logger, "> > > mute OFF \r\n" );
        mute_flag = 0;
    }
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_tune_up ( amfm_t *ctx )
{
    amfm_tune_up( ctx );
    station_frequency = amfm_get_channel( ctx );
    aux = station_frequency / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

void amfm_case_tune_down ( amfm_t *ctx )
{
    amfm_tune_down( ctx );
    station_frequency = amfm_get_channel( ctx );
    aux = station_frequency / 100.0;
    log_printf( &logger, "> > > frequency: %f MHz \r\n", aux );
    log_printf( &logger, "-----------------------------------------\r\n" );
}

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

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

    amfm_cfg_setup( &cfg );
    AMFM_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    amfm_init( &amfm, &cfg );

    Delay_ms ( 100 );
    status = amfm_init_device( &amfm );
    if ( 0 == status )
    {
        log_printf( &logger, "> > > app init done < < <\r\n" );
    }
    else if ( 1 == status )
    {
        log_printf( &logger, "> > >    timeout    < < <\r\n" );
    }
    Delay_ms ( 1000 );
    
    amfm_case_seek( &amfm );
    amfm_case_memorize( );
    Delay_ms ( 1000 );
    
    amfm_case_seek( &amfm );
    amfm_case_memorize( );
    Delay_ms ( 1000 );
    
    amfm_case_seek( &amfm );
    amfm_case_memorize( );
    Delay_ms ( 1000 );
    
    amfm_case_seek( &amfm );
    amfm_case_memorize( );
    Delay_ms ( 1000 );
    
    amfm_case_seek( &amfm );
    amfm_case_memorize( );
    Delay_ms ( 1000 );
    
    amfm_case_plus( &amfm );
    Delay_ms ( 1000 );
}

void application_task ( void )
{
    amfm_case_station_1( &amfm );
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
       
    amfm_case_station_2( &amfm );
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    amfm_case_station_3( &amfm );
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    amfm_case_station_4( &amfm );
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    amfm_case_station_5( &amfm );
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

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;
}

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