LM75B Digital temperature sensor and thermal watchdog

Dependents:   testLM75B testSensor TCPSocket_Client

Revision:
0:1cf64e89f29d
Child:
1:61987c319606
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.h	Wed Jul 06 07:02:52 2016 +0000
@@ -0,0 +1,80 @@
+#ifndef LM75B_H
+#define LM75B_H
+
+#include "mbed.h"
+
+/**
+* NXP LM75B Digital temperature sensor and thermal watchdog
+*
+* @code
+#include "mbed.h"
+#include "LM75B.h"
+#define LM75B_I2C_ADDRESS (0x48)
+
+#if defined (TARGET_KL25Z)
+#define PIN_SCL  PTE1
+#define PIN_SDA  PTE0
+#elif defined (TARGET_KL46Z)
+#define PIN_SCL  PTE1
+#define PIN_SDA  PTE0
+#elif defined (TARGET_K64F)
+#define PIN_SCL  PTE24
+#define PIN_SDA  PTE25
+#elif defined (TARGET_K22F)
+#define PIN_SCL  PTE1
+#define PIN_SDA  PTE0
+#elif defined (TARGET_KL05Z)
+#define PIN_SCL  PTB3
+#define PIN_SDA  PTB4
+#elif defined (TARGET_NUCLEO_F411RE)
+#define PIN_SCL  PB_8
+#define PIN_SDA  PB_9
+#else
+ #error TARGET NOT DEFINED
+#endif
+
+int main() {
+    int8_t itemp = 0 ;
+    float ftemp = 0.0 ;
+    LM75B lm75b(PIN_SDA, PIN_SCL, LM75B_I2C_ADDRESS) ;
+    
+    while(1) {
+        itemp = lm75b->temp() ;
+        lm75b->getTemp(&ftemp) ;
+        printf("Temp = %d C degree,  %.3f C degree\n", itemp, ftemp) ;
+        wait(1) ;
+    }
+}
+* @endcode
+*/
+class LM75B
+{
+public:
+  /**
+  * LM75B constructor
+  *
+  * @param sda SDA pin
+  * @param sdl SCL pin
+  * @param addr addr of the I2C peripheral
+  */
+  LM75B(PinName sda, PinName scl, int addr);
+
+  /**
+  * LM75B destructor
+  */
+  ~LM75B();
+
+  int8_t temp(void) ;
+  void getTemp(float *temp) ;
+  uint8_t getConfig(uint8_t ptr_byte) ;
+  void setConfig(uint8_t ptr_byte, uint8_t config_data) ;
+
+private:
+  I2C m_i2c;
+  int m_addr;
+  void readRegs(int addr, uint8_t * data, int len);
+  void writeRegs(uint8_t * data, int len);
+
+};
+
+#endif
\ No newline at end of file