只需插上耳机,无论你身在何处,都可以收听你喜爱的电台!
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板™配备了一个包含函数和示例代码的库,可用作进一步开发的参考。
功能概述
开发板
Nucleo-64 搭载 STM32F410RB MCU 提供了一种经济高效且灵活的平台,供开发者探索新想法并原型设计他们的项目。该板利用 STM32 微控制器的多功能性,使用户能够为他们的项目选择最佳的性能与功耗平衡。它配备了 LQFP64 封装的 STM32 微控制器,并包含了如用户 LED(同时作为 ARDUINO® 信号)、用户和复位按钮,以及 32.768kHz 晶体振荡器用于精确的计时操作等基本组件。Nucleo-64 板设计考虑到扩展性和灵活性,它特有的 ARDUINO® Uno
V3 扩展连接器和 ST morpho 扩展引脚头,提供了对 STM32 I/O 的完全访问,以实现全面的项目整合。电源供应选项灵活,支持 ST-LINK USB VBUS 或外部电源,确保在各种开发环境中的适应性。该板还配备了一个具有 USB 重枚举功能的板载 ST-LINK 调试器/编程器,简化了编程和调试过程。此外,该板设计旨在简化高级开发,它的外部 SMPS 为 Vcore 逻辑供电提供高效支持,支持 USB 设备全速或 USB SNK/UFP 全速,并内置加密功能,提升了项目的功效
和安全性。通过外部 SMPS 实验的专用连接器、 用于 ST-LINK 的 USB 连接器以及 MIPI® 调试连接器,提供了更多的硬件接口和实验可能性。开发者将通过 STM32Cube MCU Package 提供的全面免费软件库和示例得到广泛支持。这些,加上与多种集成开发环境(IDE)的兼容性,包括 IAR Embedded Workbench®、MDK-ARM 和 STM32CubeIDE,确保了流畅且高效的开发体验,使用户能够充分利用 Nucleo-64 板在他们的项目中的能力。
微控制器概述
MCU卡片 / MCU
建筑
ARM Cortex-M4
MCU 内存 (KB)
128
硅供应商
STMicroelectronics
引脚数
64
RAM (字节)
32768
你完善了我!
配件
Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图
一步一步来
项目组装
实时跟踪您的结果
通过调试模式的应用程序输出
1. 一旦代码示例加载完成,按下 "DEBUG" 按钮将启动构建过程,并将其编程到创建的设置上,然后进入调试模式。
2. 编程完成后,IDE 中将出现一个带有各种操作按钮的标题。点击绿色的 "PLAY" 按钮开始读取通过 Click board™ 获得的结果。获得的结果将在 "Application Output" 标签中显示。
软件支持
库描述
这个库包含FM Click驱动程序的API。
关键功能:
fm_get_received_signal_strength_indicator
- 此函数读取接收信号强度指示器fm_get_channel_frequency
- 此函数根据波段和间距设置计算当前频道频率fm_get_channel
- 此函数从READCHAN寄存器读取CHANNEL位
开源
代码示例
这个示例可以在 NECTO Studio 中找到。欢迎下载代码,或者您也可以复制下面的代码。
/*!
* \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