中级会员
 
- 积分
- 311
- 金钱
- 311
- 注册时间
- 2016-10-1
- 在线时间
- 117 小时
|
1金钱
本帖最后由 20161001 于 2016-10-1 11:52 编辑
原理图是这个,用的103VCT6 ,播放声音,声音数据是个数组放在单片机的flash里直接读取。
现在情况是,通过iic可以设置静音,包括声音音量大小。我改变IIC设置的数值能感觉到默认的电流声音的大小是可以改变证明IIC设置是正确的。
但是I2S数据好像没什么效果,发出去的数据也听不到声音。我插的是耳机。
不知道哪里的问题。
[mw_shl_code=applescript,true]void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOE| RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
/* I2S2 SD, CK and WS pins configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}[/mw_shl_code]
[mw_shl_code=applescript,true]void I2S_Config(uint16_t Standard, uint16_t MCLKOutput, uint16_t AudioFreq)
{
I2S_InitTypeDef I2S_InitStructure;
/* Enable I2S2 APB1 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
/* Deinitialize SPI2 peripheral */
SPI_I2S_DeInit(SPI2);
/* I2S2 peripheral configuration */
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_InitStructure.I2S_AudioFreq = AudioFreq;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI2, &I2S_InitStructure);
/* Disable the I2S2 TXE Interrupt */
//SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, DISABLE);
/* Enable the SPI2/I2S2 peripheral */
I2S_Cmd(SPI2, ENABLE);
/* Enable the I2S3 TxE interrupt */
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, ENABLE);
}[/mw_shl_code]
语音数据是在中断函数中不断发送的,这个中断函数是可以正常进入的。并且在线仿真,可以看到数据寄存器是有发送的数据的。但实际就是没有有声音。
[mw_shl_code=applescript,true]void SPI2_IRQHandler(void)
{
/* Check the interrupt source */
if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_TXE) == SET)
{
/* Send a data from I2S3 */
SPI_I2S_SendData(SPI2, AUDIO_SAMPLE1[TxIdx++]);
if(TxIdx>=2000)
TxIdx=0;
}
}[/mw_shl_code]
|
|