小弟初次用stm32开发,使用I2C库函数 ,发现在初始化I2C完后, 用示波器 量测PB8 PB9 始终为低电平,并不为高。 请问 问题出在哪呢。
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/*--HSI 8MHZ--*/
RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
/*--ʹÄÜI2CʱÖÓ--*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_Init(GPIOB , &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOB , &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource8,GPIO_AF_1);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource9,GPIO_AF_1);
}
void I2C_Configuration(void)
{
I2C_InitTypeDef I2C_InitStruct;
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStruct.I2C_DigitalFilter = 0x00;
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_Timing = 0x00210507;
I2C_Cmd(I2C1 , ENABLE);
I2C_Init(I2C1 , &I2C_InitStruct);
} |