File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -525,6 +525,9 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap)
525
525
526
526
#ifdef I2C_IP_VERSION_V2
527
527
obj_s -> current_hz = obj_s -> hz ;
528
+ #else
529
+ // I2C Xfer operation init
530
+ obj_s -> XferOperation = I2C_FIRST_AND_LAST_FRAME ;
528
531
#endif
529
532
530
533
#if DEVICE_I2CSLAVE
@@ -534,7 +537,6 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap)
534
537
obj_s -> pending_slave_rx_maxter_tx = 0 ;
535
538
#endif
536
539
537
- // I2C Xfer operation init
538
540
obj_s -> event = 0 ;
539
541
STM_I2C_SET_STATE (obj_s , STM_I2C_IDLE );
540
542
}
@@ -820,11 +822,14 @@ int i2c_stop(i2c_t *obj)
820
822
// Generate the STOP condition
821
823
i2c -> CR1 |= I2C_CR1_STOP ;
822
824
823
- /* In case of mixed usage of the APIs (unitary + SYNC)
824
- * re-init HAL state
825
- */
826
- if (obj_s -> XferOperation != I2C_FIRST_AND_LAST_FRAME ) {
827
- i2c_init_internal (obj , NULL );
825
+ obj_s -> XferOperation = I2C_FIRST_AND_LAST_FRAME ;
826
+
827
+ // Wait until condition is generated
828
+ int timeout = FLAG_TIMEOUT ;
829
+ while (__HAL_I2C_GET_FLAG (& obj_s -> handle , I2C_FLAG_BUSY )) {
830
+ if ((timeout -- ) == 0 ) {
831
+ return -1 ;
832
+ }
828
833
}
829
834
830
835
return 0 ;
You can’t perform that action at this time.
0 commit comments