I2C hang recover function added

Dependencies:   UniGraphic mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LM75B.h Source File

LM75B.h

00001 #ifndef _LM75B_H_
00002 #define _LM75B_H_
00003 
00004 #include "mbed.h"
00005 
00006 /**
00007 * NXP LM75B Digital temperature sensor and thermal watchdog
00008 *
00009 * @code
00010 #include "mbed.h"
00011 #include "LM75B.h"
00012 #define LM75B_I2C_ADDRESS (0x48)
00013 
00014 #if defined (TARGET_KL25Z)
00015 #define PIN_SCL  PTE1
00016 #define PIN_SDA  PTE0
00017 #elif defined (TARGET_KL46Z)
00018 #define PIN_SCL  PTE1
00019 #define PIN_SDA  PTE0
00020 #elif defined (TARGET_K64F)
00021 #define PIN_SCL  PTE24
00022 #define PIN_SDA  PTE25
00023 #elif defined (TARGET_K22F)
00024 #define PIN_SCL  PTE1
00025 #define PIN_SDA  PTE0
00026 #elif defined (TARGET_KL05Z)
00027 #define PIN_SCL  PTB3
00028 #define PIN_SDA  PTB4
00029 #elif defined (TARGET_NUCLEO_F411RE)
00030 #define PIN_SCL  PB_8
00031 #define PIN_SDA  PB_9
00032 #else
00033  #error TARGET NOT DEFINED
00034 #endif
00035 
00036 int main() {
00037     int8_t itemp = 0 ;
00038     float ftemp = 0.0 ;
00039     LM75B lm75b(PIN_SDA, PIN_SCL, LM75B_I2C_ADDRESS) ;
00040     
00041     while(1) {
00042         itemp = lm75b.temp() ;
00043         lm75b.getTemp(&ftemp) ;
00044         printf("Temp = %d C degree,  %.3f C degree\n", itemp, ftemp) ;
00045         wait(1) ;
00046     }
00047 }
00048 * @endcode
00049 */
00050 class LM75B
00051 {
00052 public:
00053   /**
00054   * LM75B constructor
00055   *
00056   * @param i2c pointer to the I2C object
00057   * @param addr addr of the I2C peripheral
00058   */
00059   LM75B(I2C *i2c, int addr);
00060 
00061   /**
00062   * LM75B destructor
00063   */
00064   ~LM75B();
00065 
00066   /**
00067   * get temperature as one byte (signed)
00068   * @param *temp int8_t returns integer part of the temperature
00069   * @return 0: success not-0: failure
00070   */
00071   int temp(int8_t *temp) ;
00072   
00073   /**
00074    * get temperature as 11 bit (float)
00075    * @param *temp float returns the temperature as float 
00076    * @return 0: success not-0: failure
00077    */
00078   int getTemp(float *temp) ;
00079   
00080   /**
00081    * get configuration register
00082    * @param ptr_byte uint8_t pointer value for the register
00083    * @param *config_data uint8_t value of the config register
00084    * @return 0: success non-0: failure
00085    */
00086   int getConfig(uint8_t ptr_byte, uint8_t *config_data) ;
00087   
00088   /**
00089    * set configuration register
00090    * @param ptr_byte uint8_t pointer value for the register
00091    * @param config_data uint8_t value to set in the config register
00092    * @return 0: success non-0: failure
00093    */
00094   int setConfig(uint8_t ptr_byte, uint8_t config_data) ;
00095 
00096 private:
00097   I2C *p_i2c;
00098   int m_addr;
00099   int readRegs(int addr, uint8_t * data, int len);
00100   int writeRegs(uint8_t * data, int len);
00101 
00102 };
00103 
00104 #endif