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 
00059 deg_t lm75_read(uint8_t sens_addr)
00060 {
00061     uint8_t data[2];
00062     int16_t degree;
00063     int16_t deci_degree;
00064 
00065     i2c_start_w(SELECT_ADDRESS(sens_addr));
00066     i2c_put(LM75_PAD_BYTE);
00067     i2c_start_r(SELECT_ADDRESS(sens_addr));
00068     i2c_recv(data, sizeof(data));
00069 
00070     degree = (int16_t)data[0];
00071     deci_degree = (int16_t)(((data[1] >> 7) & 1 ) * 5);
00072 
00073     LOG_INFO("[%d.%d C]\n", degree, deci_degree);
00074 
00075     return degree * 10 + deci_degree;
00076 }
00077 
00078 void lm75_init(void)
00079 {
00080     // Check dependence
00081     MOD_CHECK(i2c);
00082     LM75_HW_INIT();
00083 }
00084 
00085