From 6ab5f756bf0002dfb6b686021ff9e1d05bb44670 Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 22 Jul 2010 15:17:46 +0000 Subject: [PATCH] Add missing stop and check errors. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4048 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/drv/lm75.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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); -- 2.25.1