搞好了IIS3主发送,但是IIS2还是没有检测到波形,代码如下。*******************************************************************
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);/*JTAG+SW完全禁止*/
/* Disable the JTAG interface and enable the SWJ interface */
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
/* Configure SPI2 pins: CK-PB13, WS-PB12 and SD-PB15 ---------------------*/
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;/*I2S2作为主发,数据复用推挽输出*/
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure SPI2: MCK PC6,输出时钟-----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure I2S3 (SPI3) pins: MCLK */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure I2S3 (SPI3) pins: BCLK and ADCDAT */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure I2S3 (SPI3) pins: ADCLRC (WS) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/**********************************/
void I2S_Configuration(void){
I2S_InitTypeDef I2S_InitStructure;
SPI_I2S_DeInit(SPI3);
SPI_I2S_DeInit(SPI2);
/* I2S peripheral configuration */
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; /* I also tried it with 32b... nothing */
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
I2S_Init(SPI3, &I2S_InitStructure);
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
/* I2S2 configuration */
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
I2S_Init(SPI2, &I2S_InitStructure);
/* Enable the I2S3 RxNE interrupt */
SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_RXNE, ENABLE);
/* Enable the I2S2 TxE interrupt */
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, ENABLE);
/* Enable the I2S3 */
I2S_Cmd(SPI3, ENABLE);
/* Enable the I2S2 */
I2S_Cmd(SPI2, ENABLE);
}
---------------------------------------------------------------------------------
//配置系统时钟,使能各外设时钟
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA
|RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
|RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE
|RCC_APB2Periph_ADC1 | RCC_APB2Periph_AFIO
|RCC_APB2Periph_SPI1, ENABLE );
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL ,ENABLE );
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4
|RCC_APB1Periph_USART3|RCC_APB1Periph_TIM2
, ENABLE );
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}
//配置所有外设
void Init_All_Periph(void)
{
RCC_Configuration();
InitDis();
GPIO_Configuration();
I2S_Configuration();
NVIC_Configuration();
USART1_Configuration();
USART1Write((u8*)" FireBull GPIO_example",sizeof(" FireBull GPIO_example"));
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
int main(void)
{
Init_All_Periph();
while(1)
{
/* Turn on LD2 and LD3 */
GPIO_SetBits(GPIOD, GPIO_Pin_8);
/* Turn off LD1 */
GPIO_ResetBits(GPIOD, GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11);
/* Insert delay */
Delay(0xEFFFF);
/* Turn on LD2 and LD3 */
GPIO_SetBits(GPIOD, GPIO_Pin_9);
/* Turn off LD1 */
GPIO_ResetBits(GPIOD, GPIO_Pin_8 | GPIO_Pin_10 | GPIO_Pin_11);
/* Insert delay */
Delay(0xEFFFF);
/* Turn on LD4 */
GPIO_SetBits(GPIOD, GPIO_Pin_10);
/* Turn off LD2 and LD3 */
GPIO_ResetBits(GPIOD, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_11);
/* Insert delay */
Delay(0xEFFFF);
}
} |