使用307的I2S3連接CS43L22播放SD卡中的WAV,能正常3秒左右,后面就是雜音了。用調(diào)試器跟蹤SD讀取數(shù)據(jù)是正確的,現(xiàn)在找不到原因,
static void i2s3_init(void)
{
? ? GPIO_InitTypeDef GPIO_InitStructure={0};
? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
? ? GPIO_PinRemapConfig( GPIO_Remap_SWJ_JTAGDisable, ENABLE );
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_Init(GPIOA, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3 | GPIO_Pin_5;
? ? GPIO_Init(GPIOB, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
? ? GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void i2s_open(uint16_t *audio_buffer, uint16_t buffer_size,
? ? ? ? uint32_t sample_rate, uint32_t frame_format) {
? ? I2S_InitTypeDef I2S_InitStructure = { 0 };
? ? DMA_InitTypeDef DMA_InitStructure = { 0 };
? ? NVIC_InitTypeDef NVIC_InitStructure={0};
? ? RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA2, ENABLE);
? ? NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel2_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
? ? DMA_DeInit(DMA2_Channel2);
? ? DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &SPI3->DATAR;
? ? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) audio_buffer;
? ? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
? ? DMA_InitStructure.DMA_BufferSize = buffer_size;
? ? 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_Channel2, &DMA_InitStructure);
? ? DMA_ITConfig(DMA2_Channel2, DMA_IT_TC | DMA_IT_HT, ENABLE);
? ? DMA_ClearFlag(DMA2_FLAG_TC2 | DMA2_FLAG_HT2);
? ? I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
? ? I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
? ? I2S_InitStructure.I2S_DataFormat = frame_format;
? ? I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
? ? I2S_InitStructure.I2S_AudioFreq = sample_rate;
? ? I2S_InitStructure.I2S_CPOL = I2S_CPOL_High;
? ? I2S_Init(SPI3, &I2S_InitStructure);
? ? /* SPI DMA enable */
? ? SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx, ENABLE);
? ? I2S_Cmd(SPI3, ENABLE);
? ? DMA_Cmd(DMA2_Channel2, ENABLE);
}
void DMA2_Channel2_IRQHandler(void) {
? ? if (DMA_GetITStatus(DMA2_FLAG_TC2)) {
? ? ? ? DMA_ClearFlag(DMA2_FLAG_TC2);
? ? ? ? free_buffer = 1;
? ? ? ? read_flag = 1;
? ? }
? ? if (DMA_GetITStatus(DMA2_FLAG_HT2)) {
? ? ? ? DMA_ClearFlag(DMA2_FLAG_HT2);
? ? ? ? free_buffer = 0;
? ? ? ? read_flag = 1;
? ? }
}