From: asterix Date: Thu, 22 Jul 2010 15:17:46 +0000 (+0000) Subject: Add missing stop and check errors. X-Git-Tag: 2.6.0~294 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=6ab5f756bf0002dfb6b686021ff9e1d05bb44670;p=bertos.git Add missing stop and check errors. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4048 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/lm75.c b/bertos/drv/lm75.c index db8f8a94..5d24e0ae 100644 --- a/bertos/drv/lm75.c +++ b/bertos/drv/lm75.c @@ -62,10 +62,20 @@ deg_t lm75_read(uint8_t sens_addr) int16_t degree; int16_t deci_degree; - i2c_start_w(SELECT_ADDRESS(sens_addr)); - i2c_put(LM75_PAD_BYTE); - i2c_start_r(SELECT_ADDRESS(sens_addr)); - i2c_recv(data, sizeof(data)); + if( !(i2c_start_w(SELECT_ADDRESS(sens_addr)) + && i2c_put(LM75_PAD_BYTE) + && i2c_start_r(SELECT_ADDRESS(sens_addr))) ) + { + i2c_stop(); + return EOF; + } + + if ( !i2c_recv(data, sizeof(data)) ) + { + i2c_stop(); + return EOF; + } + i2c_stop(); degree = (int16_t)data[0]; deci_degree = (int16_t)(((data[1] >> 7) & 1 ) * 5);