在线时间147 小时
UID3307768
注册时间2017-1-22
NXP金币0
TA的每日心情 | 慵懒 2019-11-22 09:55 |
---|
签到天数: 179 天 连续签到: 1 天 [LV.7]常住居民III
金牌会员
 
- 积分
- 1377
- 最后登录
- 2019-11-22
|
本帖最后由 队长shiwo 于 2017-7-31 20:33 编辑
LPC54114 开发板上与音频部分相关的模块有:PDM 数字麦克风(SPH0641LM4H)--->板子上的U7 和 I2S 音频接口(WM8904)--->板子上的CN7(音频输出) 和 CN8(音频输入)。
SPH0641LM4H主要特点 :
1、灵敏度范围:-26+/-1DBdB
2、卓越的可靠性及稳定性,100%工厂测试
3. 卓越的信噪比:59dB
4、低功耗,超小体积
5、表面贴装技术
6、优良的温度系数:Max±0.60 dB/℃
7、优良的抗压系数:Max±0.55 dB/Kpa
8、专利新型硅技术,典型应用于手机、数字及模拟录音机、数码相机、便携式游戏控制器、火警报警设备、噪声控制器、汽车电子等。
WM8904主要特点:
1、高信噪比的64分贝
2、235 uA的低电流消耗的低功耗模式
3、多性能模式(睡眠、低功耗、标准性能和超声波模式)
4、平直的频率响应
5、射频屏蔽
6、零高度Mic
7、支持双多路复用通道
8、标准SMD回流
9、超声波支持
10、敏感性匹配
11、体积小
板子上原理图连接:
LPC5411x系列包含了一个无晶振全速USB接口,一个DMIC(数字麦克风)子系统连接两个PDM麦克风和两个IIS接口,DMIC接口用来连接数字PDM麦克风和转换在硬件上的PDM音频数据流成16位PCM音频数据,PDM麦克风操作只需要两种信号线(时钟和数据),而IIS需要三种(时钟、数据和声道选择)。
左边是麦克风接口,右边是两路输出
LPC54114的通过IIS总线的DMA0发送音频数据到WM8904,然后通过CN7播放音频数据
使用万利的Demo程序来测试下:
1、dmic_init()是PDM 数字麦克风(SPH0641LM4H)的初始化函数, 并通过中断函数来控制LD8来指示外部声音对它的影响
- uint8_t dmic_init(void)
- {
- uint8_t ret = 0;
- uint32_t i = 0;
- dmic_channel_config_t dmic_channel_cfg;
-
- /* PDM interface */
- IOCON_PinMuxSet(IOCON, 1, 15, IOCON_FUNC1 | IOCON_DIGITAL_EN); /* PDM CLK 0 */
- IOCON_PinMuxSet(IOCON, 1, 16, IOCON_FUNC1 | IOCON_DIGITAL_EN); /* PDM DATA 0 */
-
- /* DMIC uses 12MHz FRO clock */
- CLOCK_AttachClk(kFRO12M_to_DMIC);
- /*12MHz divided by 15 = 800KHz PDM clock */
- CLOCK_SetClkDiv(kCLOCK_DivDmicClk, 14, false);
- dmic_channel_cfg.divhfclk = kDMIC_PdmDiv1;
- dmic_channel_cfg.osr = 25U;
- dmic_channel_cfg.gainshft = 3U;
- dmic_channel_cfg.preac2coef = kDMIC_CompValueZero;
- dmic_channel_cfg.preac4coef = kDMIC_CompValueZero;
- dmic_channel_cfg.dc_cut_level = kDMIC_DcCut155;
- dmic_channel_cfg.post_dc_gain_reduce = 0U;
- dmic_channel_cfg.saturate16bit = 1U;
- dmic_channel_cfg.sample_rate = kDMIC_PhyFullSpeed;
- DMIC_Init(DMIC0);
-
- DMIC_ConfigIO(DMIC0, kDMIC_PdmStereo);
- DMIC_Use2fs(DMIC0, true);
- DMIC_SetOperationMode(DMIC0, kDMIC_OperationModeInterrupt);
- DMIC_ConfigChannel(DMIC0, kDMIC_Channel0, kDMIC_Left, &dmic_channel_cfg);
- DMIC_ConfigChannel(DMIC0, kDMIC_Channel1, kDMIC_Right, &dmic_channel_cfg);
- DMIC_FifoChannel(DMIC0, kDMIC_Channel0, FIFO_DEPTH, true, true);
- DMIC_FifoChannel(DMIC0, kDMIC_Channel1, FIFO_DEPTH, true, true);
-
- /*Gain of the noise estimator */
- DMIC_SetGainNoiseEstHwvad(DMIC0, 0x02U);
- /*Gain of the signal estimator */
- DMIC_SetGainSignalEstHwvad(DMIC0, 0x01U);
- /* 00 = first filter by-pass, 01 = hpf_shifter=1, 10 = hpf_shifter=4 */
- DMIC_SetFilterCtrlHwvad(DMIC0, 0x01U);
- /*input right-shift of (GAIN x 2 -10) bits (from -10bits (0000) to +14bits (1100)) */
- DMIC_SetInputGainHwvad(DMIC0, 0x04U);
- DisableDeepSleepIRQ(HWVAD0_IRQn);
- DMIC_HwvadEnableIntCallback(DMIC0, DMIC0_HWVAD_Callback);
- DMIC_EnableChannnel(DMIC0, (DMIC_CHANEN_EN_CH0(1) | DMIC_CHANEN_EN_CH1(1)));
- /* reset hwvad internal interrupt */
- DMIC_CtrlClrIntrHwvad(DMIC0, true);
- /* To clear first spurious interrupt */
- for (i = 0; i < 0xFFFFU; i++)
- {
- }
- /*HWVAD Normal operation */
- DMIC_CtrlClrIntrHwvad(DMIC0, false);
- NVIC_ClearPendingIRQ(HWVAD0_IRQn);
- EnableDeepSleepIRQ(HWVAD0_IRQn);
- ret = 1;
-
- return ret;
- }
复制代码
2、wm8904_i2s_init() 是I2S 音频输入/输出接口(WM8904)的初始化函数,并以LD4来指示WM8904的存在。通过对StartSoundPlayback()函数的调用,可播放存储在music.h中的音频数据
- uint8_t wm8904_i2s_init(void)
- {
- // we need initial i2c here, but we initial the right i2c at pct2075 already
-
- /* Initialize PLL clock */
- CLOCK_AttachClk(kFRO12M_to_SYS_PLL);
- CLOCK_SetPLLFreq(&pllSetup);
- CLOCK_AttachClk(kSYS_PLL_to_FLEXCOMM6);
- CLOCK_AttachClk(kSYS_PLL_to_FLEXCOMM7);
- /* Attach PLL clock to MCLK for I2S, no divider */
- CLOCK_AttachClk(kSYS_PLL_to_MCLK);
- SYSCON->MCLKDIV = SYSCON_MCLKDIV_DIV(0U);
- /* reset FLEXCOMM for I2S */
- RESET_PeripheralReset(kFC6_RST_SHIFT_RSTn);
- RESET_PeripheralReset(kFC7_RST_SHIFT_RSTn);
-
- /* I2S */
- // Flexcomm 6 I2S Rx
- IOCON_PinMuxSet(IOCON, 0, 5, IOCON_FUNC1 | IOCON_DIGITAL_EN); /* Flexcomm 6 / SDA */
- IOCON_PinMuxSet(IOCON, 0, 6, IOCON_FUNC1 | IOCON_DIGITAL_EN); /* Flexcomm 6 / WS */
- IOCON_PinMuxSet(IOCON, 0, 7, IOCON_FUNC1 | IOCON_DIGITAL_EN); /* Flexcomm 6 / SCK */
- // Flexcomm 7 I2S Tx
- IOCON_PinMuxSet(IOCON, 1, 12, IOCON_FUNC4 | IOCON_DIGITAL_EN); /* Flexcomm 7 / SCK */
- IOCON_PinMuxSet(IOCON, 1, 13, IOCON_FUNC4 | IOCON_DIGITAL_EN); /* Flexcomm 7 / SDA */
- IOCON_PinMuxSet(IOCON, 1, 14, IOCON_FUNC4 | IOCON_DIGITAL_EN); /* Flexcomm 7 / WS */
- /* MCLK output for I2S */
- IOCON_PinMuxSet(IOCON, 1, 17, IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGITAL_EN);
- SYSCON->MCLKIO = 1U;
- /*
- * enableMaster = true;
- * baudRate_Bps = 100000U;
- * enableTimeout = false;
- 配置WM8904相关寄存器
- */
- WM8904_GetDefaultConfig(&codecConfig);
- codecHandle.i2c = I2C4;
- if (WM8904_Init(&codecHandle, &codecConfig) != kStatus_Success)
- {
- PRINTF("WM8904_Init failed!\r\n");
- led_off(7);
- }
- else
- {
- led_on(7);
- }
- /* Initial volume kept low for hearing safety. */
- /* Adjust it to your needs, 0x0006 for -51 dB, 0x0039 for 0 dB etc. */
- WM8904_SetVolume(&codecHandle, 0x0006, 0x0006);//设置音量
-
- I2S_TxGetDefaultConfig(&s_TxConfig);
- s_TxConfig.divider = CLOCK_GetPllOutFreq() / 48000U / 16U / 2U;
- I2S_RxGetDefaultConfig(&s_RxConfig);
-
- I2S_TxInit(I2S_TX, &s_TxConfig);
- I2S_RxInit(I2S_RX, &s_RxConfig);
-
- DMA_Init(DMA0);
- DMA_EnableChannel(DMA0, I2S_DMA_TX);
- DMA_EnableChannel(DMA0, I2S_DMA_RX);
- DMA_SetChannelPriority(DMA0, I2S_DMA_TX, kDMA_ChannelPriority3);
- DMA_SetChannelPriority(DMA0, I2S_DMA_RX, kDMA_ChannelPriority2);
- DMA_CreateHandle(&s_DmaTxHandle, DMA0, I2S_DMA_TX);
- DMA_CreateHandle(&s_DmaRxHandle, DMA0, I2S_DMA_RX);
- if (true)
- {
- StartSoundPlayback();
- }
- else
- {
- StartDigitalLoopback();
- }
- }
复制代码 3、在函数StartSoundPlayback中创建DMA,并发送两次音频数据
- static void StartSoundPlayback(void)
- {
- PRINTF("Setup looping playback of sine wave\r\n");
- s_TxTransfer.data = &g_Music[0];
- s_TxTransfer.dataSize = sizeof(g_Music);
- I2S_TxTransferCreateHandleDMA(I2S_TX, &s_TxHandle, &s_DmaTxHandle, TxCallback, (void *)&s_TxTransfer);//创建DMA
- I2S_TxTransferSendDMA(I2S_TX, &s_TxHandle, s_TxTransfer);
- I2S_TxTransferSendDMA(I2S_TX, &s_TxHandle, s_TxTransfer); /* TODO needed to queue twice due to current state of driver */
- }
复制代码- /*!
- * @brief One period of sine wave in 108 32-bit samples.
- * One sample contains two 16-bit channels.
- */
- __ALIGN_BEGIN uint8_t g_Music[] __ALIGN_END = {
- 0x00U, 0x00U, 0x00U, 0x00U, 0x71U, 0x07U, 0x71U, 0x07U, 0xDCU, 0x0EU, 0xDCU, 0x0EU, 0x39U, 0x16U, 0x39U, 0x16U,
- 0x84U, 0x1DU, 0x84U, 0x1DU, 0xB5U, 0x24U, 0xB5U, 0x24U, 0xC6U, 0x2BU, 0xC6U, 0x2BU, 0xB2U, 0x32U, 0xB2U, 0x32U,
- 0x71U, 0x39U, 0x71U, 0x39U, 0xFFU, 0x3FU, 0xFFU, 0x3FU, 0x55U, 0x46U, 0x55U, 0x46U, 0x6FU, 0x4CU, 0x6FU, 0x4CU,
- 0x46U, 0x52U, 0x46U, 0x52U, 0xD6U, 0x57U, 0xD6U, 0x57U, 0x19U, 0x5DU, 0x19U, 0x5DU, 0x0CU, 0x62U, 0x0CU, 0x62U,
- 0xABU, 0x66U, 0xABU, 0x66U, 0xF0U, 0x6AU, 0xF0U, 0x6AU, 0xD9U, 0x6EU, 0xD9U, 0x6EU, 0x61U, 0x72U, 0x61U, 0x72U,
- 0x87U, 0x75U,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3U, 0x91U, 0xB3U, 0xABU, 0xB9U, 0xABU, 0xB9U, 0x01U, 0xC0U, 0x01U, 0xC0U,
- 0x8FU, 0xC6U, 0x8FU, 0xC6U, 0x4EU, 0xCDU, 0x4EU, 0xCDU, 0x3AU, 0xD4U, 0x3AU, 0xD4U, 0x4BU, 0xDBU, 0x4BU, 0xDBU,
- 0x7CU, 0xE2U, 0x7CU, 0xE2U, 0xC7U, 0xE9U, 0xC7U, 0xE9U, 0x24U, 0xF1U, 0x24U, 0xF1U, 0x8FU, 0xF8U, 0x8FU, 0xF8U,
- };
复制代码
测试只听到有“嗯嗯嗯嗯嗯嗯”的声音,不知道是哪里有问题了,搞不懂。。。
SPH0641LM4H.pdf
(920.21 KB, 下载次数: 4)
|
|