我的I2S模式如下
void MX_I2S1_Init(void)
{
hi2s1.Instance = SPI1;
hi2s1.Init.Mode = I2S_MODE_SLAVE_RX;
hi2s1.Init.Standard = I2S_STANDARD_MSB;
hi2s1.Init.DataFormat = I2S_DATAFORMAT_16B_EXTENDED;
hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
hi2s1.Init.AudioFreq = 64000U;
hi2s1.Init.CPOL = I2S_CPOL_LOW;
if (HAL_I2S_Init(&hi2s1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
DMA如下
/* I2S1 DMA Init */
/* SPI1_RX Init */
hdma_spi1_rx.Instance = DMA1_Channel2;
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_spi1_rx.Init.Mode = DMA_NORMAL;
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
HAL_DMA_DeInit(&hdma_spi1_rx);
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
然后用HAL_I2S_Receive_DMA(&hi2s1,(uint16_t *)&mic_Buffer.buffer[mic_Buffer.end],SAMPLES_PER_USB_FRAME);
接受I2S数据。但是始终是16位数据,因为用的是AC108音频芯片。我要用24位数据,我改了DataFormat也不行。请教大神指点一下。 |