只需插上耳机,无论你身在何处,都可以收听你喜爱的电台!
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板™配备了一个包含函数和示例代码的库,可用作进一步开发的参考。
功能概述
开发板
Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE
mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口
来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。
微控制器概述
MCU卡片 / MCU

建筑
PIC32
MCU 内存 (KB)
2048
硅供应商
Microchip
引脚数
100
RAM (字节)
524288
你完善了我!
配件
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
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