void I2C_Initialize(void)
{
uint32_t tick;
// GPIO clock enable
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_I2C1);
i2c_deinit(I2C1);
gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_11);
/* I2C clock configure */
i2c_clock_config(I2C1, 400000, I2C_DTCY_2);
/* I2C address configure */
i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, 0x00);
/* enable EEPROM_I2CDEV */
i2c_enable(I2C1);
/* enable acknowledge */
i2c_ack_config(I2C1, I2C_ACK_ENABLE);
tick =osKernelGetSysTimerCount();
/* wait until I2C bus is idle */
while(i2c_flag_get(I2C1, I2C_FLAG_I2CBSY))
{
if((tick+30)<osKernelGetSysTimerCount())
{
i2c_deinit(I2C1);
i2c_software_reset_config(I2C1,I2C_SRESET_SET);
i2c_software_reset_config(I2C1,I2C_SRESET_RESET);
I2C_Initialize();
}
}
}
配置有什么问题吗?我以前也是这么配的
|