From 74ecc75bd844b17011e954e092fd5df531f78ba6 Mon Sep 17 00:00:00 2001 From: tkuyucu Date: Wed, 30 Apr 2014 14:00:59 +0200 Subject: [PATCH] I2C NAK fix --- .../targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c index f18d1276b1..c8a2a05ba4 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c @@ -128,16 +128,17 @@ int i2c_do_write(i2c_t *obj, int value) { int i2c_do_read(i2c_t *obj, char * data, int last) { int timeOut = 100000; + + if (last){ + obj->i2c->TASKS_STOP = 1; + } while(!obj->i2c->EVENTS_RXDREADY){ timeOut--; if(timeOut<0) return 1; } obj->i2c->EVENTS_RXDREADY = 0; - - if (last){ - obj->i2c->TASKS_STOP = 1; - } + *data = obj->i2c->RXD; for(int i=0;i<320;i++){