用SPI2改成I2S2协议,ARM做从机,而且ws和sclk都是外部AD(24bit)提供,采样频率为48k,采回来的数据是个乱的,是不是我配置不对啊。求各位大神看一下
void I2S2_Init(void)
{
__HAL_RCC_SPI2_CLK_ENABLE(); //³õʼ»¯SPI2ʱÖÓ
__HAL_I2S_DISABLE(&HI2S_Handler);
HI2S_Handler.Instance=SPI2;
//HI2S_Handler.Init.MCLKOutput=I2S_MCLKOUTPUT_DISABLE;
HI2S_Handler.Init.Mode=I2S_MODE_SLAVE_RX; //´Ó»ú½ÓÊÕ¹¤×÷ģʽ
HI2S_Handler.Init.Standard=I2S_STANDARD_PHILIPS; //I2S·ÉÀûÆÖ±ê×¼
HI2S_Handler.Init.DataFormat=I2S_DATAFORMAT_24B; //Êý¾Ý³¤¶È24λ
HI2S_Handler.Init.MCLKOutput=I2S_MCLKOUTPUT_DISABLE; //´Ó»ú¹Ø±ÕMCLKʱÖÓ
HI2S_Handler.Init.AudioFreq=I2S_AUDIOFREQ_48K; //ÒôƵ²ÉÑùƵÂÊ 48k
HI2S_Handler.Init.CPOL=I2S_CPOL_LOW; //¼«ÐÔ Ï½µÑØ
HI2S_Handler.Init.ClockSource=I2S_CLOCK_EXTERNAL; //ʱÖÓÓÉÍⲿÌṩ
HI2S_Handler.State=HAL_I2S_STATE_RESET; //״̬±ê־λ
if(HAL_I2S_GetState(&HI2S_Handler)==HAL_I2S_STATE_RESET)
{
HAL_I2S_MspInit(&HI2S_Handler);
}
HAL_I2S_Init(&HI2S_Handler); //³õʼ»¯IIS
//I2S2_DMA_Enable(); //ʹÄÜSPIµÄDMA¹¦ÄÜ
__HAL_I2S_ENABLE(&HI2S_Handler); //ʹÄÜI2S2
}
//I2S2Òý½Å¸´Óóõʼ»¯
void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s)
{
GPIO_InitTypeDef GPIO_Initure1;
__HAL_RCC_GPIOB_CLK_ENABLE(); //³õʼ»¯GPIOBʱÖÓ
GPIO_Initure1.Pin=GPIO_PIN_9|GPIO_PIN_13|GPIO_PIN_15; //PB9,PB13,PB15
GPIO_Initure1.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Initure1.Pull=GPIO_PULLUP; //ÉÏÀ
GPIO_Initure1.Speed=GPIO_SPEED_FREQ_HIGH; //¸ßËÙ
GPIO_Initure1.Alternate=GPIO_AF5_SPI2; //¸´ÓÃΪSPI2
HAL_GPIO_Init(GPIOB,&GPIO_Initure1); //³õʼ»¯PB9/PB13/PB15
}
|