Beginner
10 min

Ensure a crisp and clear musical experience that transcends expectations using Si4732 and PIC18LF45K40

Tune into timeless melodies: Your gateway to AM/FM musical bliss!

AM/FM 2 Click with Curiosity HPC

Published Nov 01, 2023

Click board™

AM/FM 2 Click

Dev Board

Curiosity HPC

Compiler

NECTO Studio

MCU

PIC18LF45K40

Experience the nostalgia of classic tunes and the freshness of modern beats with our radio solution, seamlessly delivering a spectrum of musical bliss from both AM and FM bands.

A

A

Hardware Overview

How does it work?

AM/FM 2 Click is based on the Si4732, a broadcast AM/FM/SE/LW/RDS radio receiver from Skyworks. It features TDMA noise immunity, superior radio performance, high-fidelity audio power amplification, advanced AN/FM seek tunning, automatic frequency control (AFC), and automatic gain control (AGC). It also features a digital FM stereo decoder, programmable de-emphasis, advanced audio processing, and seven selectable AM channel filters. The Si4732 integrates an RDS/RBDS processor, which allows embedding of small amounts of digital information in conventional FM radio broadcasts. The Si4732 can receive the FM band broadcast in a range of 64 up to 108MHz and AM band from 520 up to 1710KHz. In addition, the receiver supports the SW band (2.3 – 26.1 MHz) and LW band (153 – 279 KHz). The AM/FM 2 Click uses an SMA connector and

external antenna to receive both AM and LW radio signals, while it also comes with a PTH for usage with a wire antenna. The FM and SW bands use a 3.5mm audio jack and connected earphones as an antenna, although a wire antenna is left as an option over an additional PTH. The Si4732 can receive or transmit the FM signal over the antenna but can not use both modes simultaneously. The audio signal from the output of the Si4732 is brought to the onboard 3.5mm female audio jack over the LM4910, eliminating the need for any external amplifier. There are four selectable digital sample precisions (8, 16, 20, and 24 bits). The sample rate can be set between 320000 and 48000Hz. AM/FM 2 Click uses a standard 2-Wire I2C interface to communicate with the host MCU. The I2C address can be selected over the ADDR SEL jumper with 0 default position. In cases

where the AM reception is too strong, the front-end attenuators can be engaged using the GP1 pin. The radio receiver has interrupt abilities, which can be used over the GP2 pin. Both GP1 and GP2 are turned off over unpopulated R8 and R9 resistor jumpers. To use them, you should solder 0Ω resistors. There is also an additional RST pin for resetting the radio receiver. The LM4910 features a low-power consumption shutdown mode activated over the ENA pin with LOW logic. 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. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

AM/FM 2 Click hardware overview image

Features overview

Development board

Curiosity HPC, standing for Curiosity High Pin Count (HPC) development board, supports 28- and 40-pin 8-bit PIC MCUs specially designed by Microchip for the needs of rapid development of embedded applications. This board has two unique PDIP sockets, surrounded by dual-row expansion headers, allowing connectivity to all pins on the populated PIC MCUs. It also contains a powerful onboard PICkit™ (PKOB), eliminating the need for an external programming/debugging tool, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, a set of indicator LEDs, push button switches and a variable potentiometer. All

these features allow you to combine the strength of Microchip and Mikroe and create custom electronic solutions more efficiently than ever. Each part of the Curiosity HPC development board contains the components necessary for the most efficient operation of the same board. An integrated onboard PICkit™ (PKOB) allows low-voltage programming and in-circuit debugging for all supported devices. When used with the MPLAB® X Integrated Development Environment (IDE, version 3.0 or higher) or MPLAB® Xpress IDE, in-circuit debugging allows users to run, modify, and troubleshoot their custom software and hardware

quickly without the need for additional debugging tools. Besides, it includes a clean and regulated power supply block for the development board via the USB Micro-B connector, alongside all communication methods that mikroBUS™ itself supports. Curiosity HPC development board allows you to create a new application in just a few steps. Natively supported by Microchip software tools, it covers many aspects of prototyping thanks to many number of different Click boards™ (over a thousand boards), the number of which is growing daily.

Curiosity HPC double image

Microcontroller Overview

MCU Card / MCU

PIC18LF45K40

Architecture

PIC

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

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.

AM/FM 2 Click accessories image

Used MCU Pins

mikroBUS™ mapper

Amplifier Enable
RA1
AN
Reset
RD0
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
General-Purpose I/O
RC2
PWM
General-Purpose I/O
RB5
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

AM/FM 2 Click Schematic schematic

Step by step

Project assembly

Curiosity HPC front no-mcu image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity HPC as your development board.

Curiosity HPC front no-mcu image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity HPC 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
Necto DIP image step 7 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for AM/FM 2 Click driver.

Key functions:

  • amfm2_seek_station - AM/FM 2 seek station function.

  • amfm2_tuning_freq - AM/FM 2 tuning frequency function.

  • amfm2_get_tuning_freq - AM/FM 2 get tuning frequency function.

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 AM/FM 2 Click example
 *
 * # Description
 * This example demonstrates the use of the AM/FM 2 Click board™.
 * The app represents a radio tuner that supports worldwide AM/FM bands 
 * and has features such as automatic frequency control, seek station, and volume control.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The initialization of I2C module and log UART.
 * After driver initialization, the app sets the default configuration 
 * and searches and memorizes for a valid frequency of the 5 radio stations.
 *
 * ## Application Task
 * This example demonstrates the use of the AM/FM 2 Click board™.
 * The application switches all 5 previously memorized radio frequencies every 10 seconds.
 * Results are being sent to the UART Terminal, where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "amfm2.h"

static amfm2_t amfm2;
static log_t logger;

static float mem_station_freq[ 5 ] = { 0 };
static uint8_t rsp_status = 0;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    amfm2_cfg_t amfm2_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.
    amfm2_cfg_setup( &amfm2_cfg );
    AMFM2_MAP_MIKROBUS( amfm2_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == amfm2_init( &amfm2, &amfm2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( AMFM2_ERROR == amfm2_default_cfg ( &amfm2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    Delay_ms ( 100 );
    
    log_printf( &logger, " Begins searching for a valid frequency...\r\n" );
    log_printf( &logger, "--------------------\r\n" );
    for ( uint8_t n_cnt = 0; n_cnt < 5; n_cnt++ )
    {
        if ( AMFM2_OK == amfm2_seek_station( &amfm2, &rsp_status ) )
        {
            if ( AMFM2_RSP_STATUS_CTS & rsp_status )
            {
                log_printf( &logger, " The search is done.\r\n" );
                if ( AMFM2_OK == amfm2_get_tuning_freq( &amfm2, &mem_station_freq[ n_cnt ] ) )
                {
                    log_printf( &logger, " Frequency: %.2f MHz \r\n", mem_station_freq[ n_cnt ] );
                    log_printf( &logger, "- - - - - - - - - - \r\n" );
                    Delay_ms( 100 );
                }
            }
        }
    }
    log_printf( &logger, "--------------------\r\n" );
    Delay_ms( 100 );
    
    if ( AMFM2_OK == amfm2_set_volume( &amfm2, AMFM2_SET_VOLUME_MAX, &rsp_status ) )
    {
        log_printf( &logger, " Set max volume \r\n" );
        Delay_ms( 100 );
    }
    
    log_info( &logger, " Application Task " );
    log_printf( &logger, "--------------------\r\n" );
    Delay_ms( 100 );
}

void application_task ( void ) 
{
    for ( uint8_t n_cnt = 0; n_cnt < 5; n_cnt++ )
    {
        if ( AMFM2_OK == amfm2_tuning_freq( &amfm2, mem_station_freq[ n_cnt ], &rsp_status ) )
        {
            log_printf( &logger, " FM Station %d \r\nFrequency: %.2f MHz\r\n", 
                       ( uint16_t ) ( n_cnt + 1 ), mem_station_freq[ n_cnt ] );
            log_printf( &logger, "--------------------\r\n" );
            Delay_ms( 10000 );
        }
    }
}

void main ( void ) 
{
    application_init( );

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

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

Additional Support

Resources