rcu_periph_clock_enable(RCU_GPIOF);
/* enable BOARD_I2C APB1 clock */
rcu_periph_clock_enable(RCU_I2C1);
/* connect PB7 to I2C1_SDA */
//I2C1-SCL-PF1
gpio_af_set(GPIOF, GPIO_AF_4, GPIO_PIN_1);
gpio_mode_set(GPIOF, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_1);
gpio_output_options_set(GPIOF, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
//I2C1-SDA-PF0
gpio_af_set(GPIOF, GPIO_AF_4, GPIO_PIN_0);
gpio_mode_set(GPIOF, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_0);
gpio_output_options_set(GPIOF, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
i2c_clock_config(I2C1, 100000, I2C_DTCY_2);
/* I2C address configure */
i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, I2C1_SLAVE_ADDRESS7);
/* enable I2C1 */
i2c_enable(I2C1);
/* enable acknowledge */
i2c_ack_config(I2C1, I2C_ACK_ENABLE);
这是我硬件I2C的配置,然后读I2C的时候一直卡在 while(i2c_flag_get(I2C1, I2C_FLAG_I2CBSY));
I2C的总线繁忙这里。
但是我把这两个管教配置成模拟的管脚时能够读到I2C里面的值。
请教下我的硬件I2C配置有误吗? |