rau cha / mbed-src-I2CWaitFix

Fork of mbed-src by mbed official

Revision:
13:bd9ff402dd42
Parent:
11:f9e72c209510
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC11U24/hal/i2c_api.c
--- a/vendor/NXP/LPC11U24/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC11U24/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -124,13 +124,18 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     // write the stop bit
     i2c_conset(obj, 0, 1, 0, 0);
     i2c_clear_SI(obj);
     
     // wait for STO bit to reset
-    while(I2C_CONSET(obj) & (1 << 4));
+    int timeout = 0;
+    while(I2C_CONSET(obj) & (1 << 4)){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }