初学者
10 分钟

使用Si4703和STM32F031K6保持信息畅通和娱乐

调频,调高音量,尽情摇滚!

FM Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

FM Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

只需插上耳机,无论你身在何处,都可以收听你喜爱的电台!

A

A

硬件概览

它是如何工作的?

FM Click基于Si4703,这是一款来自Silicon Labs的广播FM收音机调谐器。该收音机在全球范围内的FM波段工作,频率范围为76-108MHz,天线使用耳机。立体声音频连接器支持三和四导线耳机,建议电缆长度为1.1m至1.45m,以获得最佳信号接收效果。Si4703是行业中体积最小的FM调谐器之一,配备了32.768kHz的参考时钟,以获得更好的频率容差。它 具有左右两个音频输出。每个输出使用来自德州仪器

的音频功率放大器LM4864来放大通道输出。这些放大器可以提供大约200mW的连续平均功率到8Ω负载。FM Click也可以作为立体声设备和单声道使用。FM Click可以通过mikroBUS™插座的I2C串行接口与主机MCU通信。除了通信引脚之外,此板还使用了其他几个引脚。SEN引脚路由到mikroBUS™插座的CS引脚,用作串行接口激活信号,与I2C引脚结合使用,形 成3线接口。RST引脚用作通用复位功能,另外还有两

个用户可配置的引脚,GP2和GP1,路由到mikroBUS™插座的AN和INT引脚。这些I/O引脚可以用作中断请求(搜索/调谐或RDS准备)或立体声/单声道指示器。这个Click板™只能使用3.3V逻辑电压电平操作。在使用具有不同逻辑电平的MCU之前,板子必须执行适当的逻辑电压电平转换。但是,该Click板™配备了一个包含函数和示例代码的库,可用作进一步开发的参考。

FM Click hardware overview image

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

这款标准小型立体声耳机采用顶级立体声电缆和连接器,为用户提供高品质的听觉体验。设计通用兼容性,它们轻松连接到所有MIKROE mikromedia和多媒体板,是您电子项目的理想选择。耳机额定功率为100mW,能够在20Hz至20kHz的广泛频率范围内提供清晰的音频。它们具有100 ± 5dB的灵敏度和32Ω ± 15%的阻抗,确保了最佳的音质。直径为Φ15mm的扬声器提供清晰、沉浸式的音频。这些耳机具有性价比高、多功能的特点,非常适合测试您的原型设备,为您的项目提供经济实惠、可靠的音频解决方案。

FM Click accessories image

使用的MCU引脚

mikroBUS™映射器

General Purpose I/O
PA0
AN
Reset
PA11
RST
Serial Enable Input
PA4
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
PA12
INT
NC
NC
TX
NC
NC
RX
Serial Clock Input
PB6
SCL
Serial Data Input
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

FM Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 32 with STM32F031K6 MCU作为您的开发板开始。

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

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

这个库包含FM Click驱动程序的API。

关键功能:

  • fm_get_received_signal_strength_indicator - 此函数读取接收信号强度指示器

  • fm_get_channel_frequency - 此函数根据波段和间距设置计算当前频道频率

  • fm_get_channel - 此函数从READCHAN寄存器读取CHANNEL位

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * \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

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。