@@ -310,21 +310,21 @@ int rt_hw_i2c_init(void)
310310 i2c_obj -> parent .timeout = RT_TICK_PER_SECOND ; // Default 1s timeout
311311
312312 /* Enable clocks */
313- rcu_periph_clock_enable (config -> periph_clk );
314313 rcu_periph_clock_enable (config -> scl_clk );
315314 if (config -> scl_clk != config -> sda_clk )
316315 {
317316 rcu_periph_clock_enable (config -> sda_clk );
318317 }
318+ rcu_periph_clock_enable (config -> periph_clk );
319319
320320 /* Configure GPIO */
321+ gpio_af_set (config -> scl_port , config -> scl_af , config -> scl_pin );
321322 gpio_mode_set (config -> scl_port , GPIO_MODE_AF , GPIO_PUPD_PULLUP , config -> scl_pin );
322323 gpio_output_options_set (config -> scl_port , GPIO_OTYPE_OD , GPIO_OSPEED_50MHZ , config -> scl_pin );
323- gpio_af_set ( config -> scl_port , config -> scl_af , config -> scl_pin );
324-
324+
325+ gpio_af_set ( config -> sda_port , config -> sda_af , config -> sda_pin );
325326 gpio_mode_set (config -> sda_port , GPIO_MODE_AF , GPIO_PUPD_PULLUP , config -> sda_pin );
326327 gpio_output_options_set (config -> sda_port , GPIO_OTYPE_OD , GPIO_OSPEED_50MHZ , config -> sda_pin );
327- gpio_af_set (config -> sda_port , config -> sda_af , config -> sda_pin );
328328
329329 /* Configure I2C peripheral */
330330 i2c_deinit (config -> i2c_periph );
@@ -335,7 +335,7 @@ int rt_hw_i2c_init(void)
335335
336336 /* Configure NVIC for interrupts */
337337 nvic_irq_enable (config -> ev_irq_type , 2 );
338- nvic_irq_enable (config -> er_irq_type , 2 );
338+ nvic_irq_enable (config -> er_irq_type , 1 );
339339
340340 /* Register I2C bus device */
341341 result = rt_i2c_bus_device_register (& i2c_obj -> parent , config -> device_name );
0 commit comments