现在使用st103芯片对外设的音源进行录音,该音源的传输格式为I2S,使用DMA进行接收,但是在试验时,播放音源数据为正弦波时,DMA中的数据有时候对有时错(音源的波形没有变化),请问是怎么回事?困扰很久了,希望大牛们能帮忙解决,谢谢!
其中部分代码如下:
// I2S
/* Configure SPI2 and SPI3 pins: CK, WS and SD */ //有两路录音数据,两个I2S通道接收
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_12
| GPIO_Pin_13 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*disable all*/
I2S_Cmd(SPI2, DISABLE);
I2S_Cmd(SPI3, DISABLE);
DMA_Cmd(DMA2_Channel1, DISABLE);
DMA_Cmd(DMA1_Channel4, DISABLE);
/*config dma*/
DMA_DeInit(DMA1_Channel4);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SPI2_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)RecordData_SBufferA; 存储数据的全局变量s16 RecordData_SBufferA[2048]
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = RecordData_BufferLength; 2048
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel4, &DMA_InitStructure);
SPI_I2S_DeInit(SPI2);
//------------------I2S2 configuration----------------------------------//
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI2, &I2S_InitStructure);
// Enable SPI2 DMA Rx request /
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);
DMA_ClearFlag(DMA1_FLAG_TC4 | DMA1_FLAG_TE4 | DMA1_FLAG_HT4 | DMA1_FLAG_GL4);
// Enable DMA1 Channel4 Transfer Complete interrupt /
DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Channel4, DMA_IT_HT, ENABLE);
DMA_ITConfig(DMA1_Channel4, DMA_IT_TE, ENABLE);
/*another dma */
DMA_DeInit(DMA2_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SPI3_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr =(u32)RecordData_MBufferA;存储数据的全局变量s16 RecordData_MBufferA[2048]
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = RecordData_BufferLength; 2048
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel1, &DMA_InitStructure);
SPI_I2S_DeInit(SPI3);
// I2S2 peripheral configuration /
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI3, &I2S_InitStructure);
/* Enable SPI3 DMA Rx request */
SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA2_Channel1, ENABLE);
DMA_Cmd(DMA1_Channel4, ENABLE);
// Enable the SPI2/I2S2 peripheral /
I2S_Cmd(SPI2, ENABLE);
/* Enable the SPI3/I2S3 peripheral */
I2S_Cmd(SPI3, ENABLE);
当开始播放正弦波时,RecordData_MBufferA的数据有时正确有时错误,请问是为什么?(I2S3的音源未打开)谢谢 |