|
@@ -62,7 +62,7 @@ static void gd32_i2c_busy_recovery(uint32_t i2c_periph){
|
|
|
|
|
|
|
|
void gd32_i2c_init(uint32_t i2c_device, uint32_t rate){
|
|
void gd32_i2c_init(uint32_t i2c_device, uint32_t rate){
|
|
|
uint32_t device = iic_device(i2c_device);
|
|
uint32_t device = iic_device(i2c_device);
|
|
|
-
|
|
|
|
|
|
|
+ i2c_clk[i2c_device] = rate;
|
|
|
rcu_periph_clock_enable(RCU_GPIOB);
|
|
rcu_periph_clock_enable(RCU_GPIOB);
|
|
|
if (device == I2C0) {
|
|
if (device == I2C0) {
|
|
|
rcu_periph_clock_enable(RCU_I2C0);
|
|
rcu_periph_clock_enable(RCU_I2C0);
|
|
@@ -70,14 +70,14 @@ void gd32_i2c_init(uint32_t i2c_device, uint32_t rate){
|
|
|
_i2c_deinit(I2C0);
|
|
_i2c_deinit(I2C0);
|
|
|
gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_8|GPIO_PIN_9);
|
|
gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_8|GPIO_PIN_9);
|
|
|
gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_8|GPIO_PIN_9);
|
|
gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_8|GPIO_PIN_9);
|
|
|
- //gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_8|GPIO_PIN_9);
|
|
|
|
|
|
|
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_8|GPIO_PIN_9);
|
|
|
} else {
|
|
} else {
|
|
|
rcu_periph_clock_enable(RCU_I2C1);
|
|
rcu_periph_clock_enable(RCU_I2C1);
|
|
|
gd32_i2c_busy_recovery(I2C1);
|
|
gd32_i2c_busy_recovery(I2C1);
|
|
|
_i2c_deinit(I2C1);
|
|
_i2c_deinit(I2C1);
|
|
|
gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_10|GPIO_PIN_11);
|
|
gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_10|GPIO_PIN_11);
|
|
|
gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_10|GPIO_PIN_11);
|
|
gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_10|GPIO_PIN_11);
|
|
|
- //gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_10|GPIO_PIN_11);
|
|
|
|
|
|
|
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_10|GPIO_PIN_11);
|
|
|
}
|
|
}
|
|
|
i2c_clock_config(device, rate, I2C_DTCY_2);
|
|
i2c_clock_config(device, rate, I2C_DTCY_2);
|
|
|
i2c_enable(device);
|
|
i2c_enable(device);
|