|
具体可以查看手册,我这里将代码贴出来,添加到V4,V5或者V6板子的驱动末尾即可:
- /*
- *********************************************************************************************************
- * 函 数 名: Si47XX_FMSeekStart
- * 功能说明: 搜索有效的FM频率
- * 形 参: _SeekMode 搜索模式;
- * 返 回 值: 0 失败, 1 成功
- *********************************************************************************************************
- */
- static uint8_t Si47XX_FMSeekStart(SEEK_MODE_E _SeekMode)
- {
- uint32_t uiTimeOut;
- uint8_t ucCmdBuf[2];
-
- /*
- FM_SEEK_START
- Begins searching for a valid frequency.
- CMD 0x21 FM_SEEK_START
- ARG1 bit7:4 Reserved Always write to 0.
- bit3 SEEKUP Seek Up/Down.
- Determines the direction of the search, either UP = 1, or DOWN = 0.
- bit2 WRAP Wrap/Halt.
- Determines whether the seek should Wrap = 1, or Halt = 0 when it hits the
- band limit.
- bit1:0 Reserved Always write to 0.
- STATUS ?0x80 Reply Status. Clear-to-send high.
- */
-
- ucCmdBuf[0] = 0x21;
- switch(_SeekMode)
- {
- case SEEKDOWN_HALT:
- {
- ucCmdBuf[1] = 0x00;
- break;
- }
-
- case SEEKDOWN_WRAP:
- {
- ucCmdBuf[1] = 0x04;
- break;
- }
-
- case SEEKUP_HALT:
- {
- ucCmdBuf[1] = 0x08;
- break;
- }
-
- case SEEKUP_WRAP:
- {
- ucCmdBuf[1] = 0x0C;
- break;
- }
- }
- /* AN332 page = 277
- Powerup in Analog Mode
- CMD 0x01 POWER_UP
- ARG1 0xC0 Set to FM Receive. Enable interrupts.
- ARG2 0x05 Set to Analog Audio Output
- STATUS →0x80 Reply Status. Clear-to-send high.
- */
- SI4730_SendCmd(ucCmdBuf, 2);
- /*
- 第1个形参表示最大轮询次数; 如果成功,返回值uiTimeOut > 0 表示实际轮询次数
- 第2个形参1表示结束后发送STOP
- */
- uiTimeOut = SI4730_WaitStatus80(1000, 1);
- if (uiTimeOut == 0)
- {
- return 0;
- }
- return 1;
- }
- /*
- *********************************************************************************************************
- * 函 数 名: Si47XX_FMSeek
- * 功能说明: 搜索所有可用的FM频道
- * 形 参: _SeekMode 搜索模式
- * _pFre 数组地址,用于记录搜索到的频道
- * _FMLength 搜索到频道数。
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void Si47XX_FMSeek(SEEK_MODE_E _SeekMode, uint16_t *_pFre, uint16_t *_FMLength)
- {
- uint32_t uiTimeOut;
- uint8_t ucCmdBuf[7];
- uint16_t i = 0;
-
- while(1)
- {
- uiTimeOut = 0;
- do
- {
- Si47XX_FMSeekStart(_SeekMode);
- SI4730_GetFMTuneStatus(ucCmdBuf);
-
- uiTimeOut++;
- }
- while(((ucCmdBuf[0]&0x01) == 0) && (uiTimeOut < 5000) && ((ucCmdBuf[0]&0x80) == 0));
-
- /* 搜索完成一次后,一定要加100ms的延迟才能开启下次搜索 */
- bsp_DelayMS(100);
-
- if((ucCmdBuf[0]&0x01) == 0x01)
- {
- /* 记录搜索到的频道 */
- _pFre[i++] = (uint16_t)(ucCmdBuf[1] << 8) + ucCmdBuf[2];
- }
-
- #if 0
- printf("---- = %d, %d\r\n", (ucCmdBuf[1] << 8) + ucCmdBuf[2], i);
- #endif
-
- /* 搜索到FM频段末尾, 记录搜索到的总的频道数 */
- if((ucCmdBuf[0]&0x80) != 0)
- {
- *_FMLength = i;
- break;
- }
- }
- }
复制代码
|
|