我按下面的方法初始化GD32F130的I2C接口,再调用I2C_GenerateSTART(I2C2, ENABLE);发送Start信号,SDA和SCL均无反应,各位大师帮忙看看。
void I2C_Configuration(void)
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
/* Connect pin to Periph */
GPIO_PinAFConfig( GPIOA , GPIO_PinSource0, GPIO_AF_1 );
GPIO_PinAFConfig( GPIOA , GPIO_PinSource1, GPIO_AF_1 );
/* PA0,1 SCL and SDA */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType= GPIO_OType_OD; //设置管脚为复用功能开漏输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //I2C接口使用的GPIO管脚初始化
I2C_DeInit(I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; //设置I2C接口模式
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; //设置I2C接口的高低电平周期
I2C_InitStructure.I2C_OwnAddress1 = 0x30; //设置I2C接口的主机地址
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; //设置是否开启ACK响应
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 100000; //100K速度
I2C_Cmd(I2C2, ENABLE); //使能I2C接口
I2C_Init(I2C2, &I2C_InitStructure); //I2C接口初始化
/*允许1字节1应答模式*/
I2C_AcknowledgeConfig(I2C2, ENABLE); //使能I2C接口响应
}
|