siva surendar / mbed-dev

Fork of mbed-dev by mbed official

Revision:
34:bb6061527455
Parent:
0:9b334a45a8ff
Child:
144:ef7eb2e8f9f7
--- a/targets/hal/TARGET_STM/TARGET_STM32F1/i2c_api.c	Thu Dec 03 15:15:11 2015 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F1/i2c_api.c	Mon Dec 07 08:00:11 2015 +0000
@@ -124,6 +124,15 @@
     // Clear Acknowledge failure flag
     __HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_AF);
 
+    // Wait the STOP condition has been previously correctly sent
+	// This timeout can be avoid in some specific cases by simply clearing the STOP bit
+    timeout = FLAG_TIMEOUT;
+    while ((i2c->CR1 & I2C_CR1_STOP) == I2C_CR1_STOP) {
+        if ((timeout--) == 0) {
+            return 1;
+        }
+    }
+
     // Generate the START condition
     i2c->CR1 |= I2C_CR1_START;