初始化代码:
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2,ENABLE);
//GPIO PART
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//I2C PART
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C1_OwnAddress1;//define by myself
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED_100K;
I2C_Cmd(I2C2,ENABLE);
I2C_Init(I2C2,&I2C_InitStructure);
I2C_AcknowledgeConfig(I2C1, ENABLE);
外部接一个MEMS器件,I2C线上上拉电阻10K,电平3.5V
初始化跑完GPIO_INIT之后管脚上就从高电平变成低电平了,在后面做完I2C_INIT也没回变回来,导致I2C.SR第一位始终是1,做SWRST也没用,I2C通信不上,求助啊!!! |