lm75.c
Go to the documentation of this file.
00001 00039 #include "lm75.h" 00040 00041 #include "hw/hw_lm75.h" 00042 00043 #include "cfg/cfg_lm75.h" 00044 00045 #include <cfg/debug.h> 00046 #include <cfg/module.h> 00047 00048 // Define logging setting (for cfg/log.h module). 00049 #define LOG_LEVEL LM75_LOG_LEVEL 00050 #define LOG_FORMAT LM75_LOG_FORMAT 00051 00052 #include <cfg/log.h> 00053 00054 #include <drv/i2c.h> 00055 #include <drv/ntc.h> // Macro and data type to manage celsius degree 00056 00057 #define SELECT_ADDRESS(addr) LM75_ADDRESS_BYTE | (addr << 1) 00058 #define LM75_ADDRESS_BYTE 0x91 00059 #define LM75_PAD_BYTE 0x0 00060 00061 00062 #if !CONFIG_I2C_DISABLE_OLD_API 00063 00064 deg_t lm75_read_1(uint8_t sens_addr) 00065 { 00066 return lm75_read_2(&local_i2c_old_api, sens_addr); 00067 } 00068 #endif /* !CONFIG_I2C_DISABLE_OLD_API */ 00069 00070 00071 /* 00072 * New API 00073 */ 00074 deg_t lm75_read_2(I2c *i2c, uint8_t sens_addr) 00075 { 00076 uint8_t data[2]; 00077 int16_t deci_degree; 00078 00079 i2c_start_w(i2c, SELECT_ADDRESS(sens_addr), 1, I2C_NOSTOP); 00080 i2c_putc(i2c, LM75_PAD_BYTE); 00081 i2c_start_r(i2c, SELECT_ADDRESS(sens_addr), sizeof(data), I2C_STOP); 00082 i2c_read(i2c, data, sizeof(data)); 00083 00084 if (i2c_error(i2c)) 00085 return EOF; 00086 00087 deci_degree = ((data[0] << 8) | data[1]); 00088 deci_degree >>= 7; 00089 deci_degree *= 5; 00090 00091 LOG_INFO("[%d.%d C]\n", deci_degree / 10, ABS(deci_degree % 10)); 00092 00093 return deci_degree; 00094 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/bertos_logo.png)