大佬帮忙看一下,这个I2C初始换后为什么SCL没有时钟,代码如下:
I2C_HandleTypeDef hi2c2;
/*I2C_GPIO 配置*/
static void I2C_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_I2C2_CLK_ENABLE(); //使能I2C时钟
__HAL_RCC_GPIOH_CLK_ENABLE(); //使能GPIOH时钟
/*PH4 SCL2, PH5 SDA2*/
GPIO_InitStructure.Pin=GPIO_PIN_4; //PH4
GPIO_InitStructure.Mode=GPIO_MODE_AF_OD; //复用开漏输出
GPIO_InitStructure.Pull=GPIO_PULLUP; //
GPIO_InitStructure.Speed=GPIO_SPEED_FREQ_HIGH; //高速
GPIO_InitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init(GPIOH,&GPIO_InitStructure); //初始化GPIOH4
GPIO_InitStructure.Pin=GPIO_PIN_5; //PH5
GPIO_InitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init(GPIOH,&GPIO_InitStructure); //初始化GPIOH5
/* Force the I2C peripheral clock reset */
__HAL_RCC_I2C2_FORCE_RESET();
/* Release the I2C peripheral clock reset */
__HAL_RCC_I2C2_RELEASE_RESET();
}
/* I2C工作模式配置 */
static void I2C_Init(void)
{
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x00901954;
hi2c2.Init.OwnAddress1 = 0;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0XFF;
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
HAL_I2C_Init(&hi2c2);
HAL_I2CEx_AnalogFilter_Config(&hi2c2, I2C_ANALOGFILTER_ENABLE);
} |