I2C hang recover function added

Dependencies:   UniGraphic mbed vt100

In this version, check_i2c_pins function was added in edge_mgr.cpp.

プログラムの起動時、I2Cモジュールを初期化する前に、I2Cに使用するピンの電位を確認し
もし一方でも Low に張り付いていた場合、SCL を GPIO 出力に設定して 
所定回数 (I2C_UNLOCK_TRIAL_CYCLE) 反転させることにより、疑似リセットクロックを生成します。

その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。

Committer:
gaku_miyagawa
Date:
Mon Jun 18 02:55:38 2018 +0000
Revision:
2:de22987be9ba
Parent:
0:d895cd1cd897
SBU SPECIAL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:d895cd1cd897 1 #ifndef _LM75B_H_
Rhyme 0:d895cd1cd897 2 #define _LM75B_H_
Rhyme 0:d895cd1cd897 3
Rhyme 0:d895cd1cd897 4 #include "mbed.h"
Rhyme 0:d895cd1cd897 5
Rhyme 0:d895cd1cd897 6 /**
Rhyme 0:d895cd1cd897 7 * NXP LM75B Digital temperature sensor and thermal watchdog
Rhyme 0:d895cd1cd897 8 *
Rhyme 0:d895cd1cd897 9 * @code
Rhyme 0:d895cd1cd897 10 #include "mbed.h"
Rhyme 0:d895cd1cd897 11 #include "LM75B.h"
Rhyme 0:d895cd1cd897 12 #define LM75B_I2C_ADDRESS (0x48)
Rhyme 0:d895cd1cd897 13
Rhyme 0:d895cd1cd897 14 #if defined (TARGET_KL25Z)
Rhyme 0:d895cd1cd897 15 #define PIN_SCL PTE1
Rhyme 0:d895cd1cd897 16 #define PIN_SDA PTE0
Rhyme 0:d895cd1cd897 17 #elif defined (TARGET_KL46Z)
Rhyme 0:d895cd1cd897 18 #define PIN_SCL PTE1
Rhyme 0:d895cd1cd897 19 #define PIN_SDA PTE0
Rhyme 0:d895cd1cd897 20 #elif defined (TARGET_K64F)
Rhyme 0:d895cd1cd897 21 #define PIN_SCL PTE24
Rhyme 0:d895cd1cd897 22 #define PIN_SDA PTE25
Rhyme 0:d895cd1cd897 23 #elif defined (TARGET_K22F)
Rhyme 0:d895cd1cd897 24 #define PIN_SCL PTE1
Rhyme 0:d895cd1cd897 25 #define PIN_SDA PTE0
Rhyme 0:d895cd1cd897 26 #elif defined (TARGET_KL05Z)
Rhyme 0:d895cd1cd897 27 #define PIN_SCL PTB3
Rhyme 0:d895cd1cd897 28 #define PIN_SDA PTB4
Rhyme 0:d895cd1cd897 29 #elif defined (TARGET_NUCLEO_F411RE)
Rhyme 0:d895cd1cd897 30 #define PIN_SCL PB_8
Rhyme 0:d895cd1cd897 31 #define PIN_SDA PB_9
Rhyme 0:d895cd1cd897 32 #else
Rhyme 0:d895cd1cd897 33 #error TARGET NOT DEFINED
Rhyme 0:d895cd1cd897 34 #endif
Rhyme 0:d895cd1cd897 35
Rhyme 0:d895cd1cd897 36 int main() {
Rhyme 0:d895cd1cd897 37 int8_t itemp = 0 ;
Rhyme 0:d895cd1cd897 38 float ftemp = 0.0 ;
Rhyme 0:d895cd1cd897 39 LM75B lm75b(PIN_SDA, PIN_SCL, LM75B_I2C_ADDRESS) ;
Rhyme 0:d895cd1cd897 40
Rhyme 0:d895cd1cd897 41 while(1) {
Rhyme 0:d895cd1cd897 42 itemp = lm75b.temp() ;
Rhyme 0:d895cd1cd897 43 lm75b.getTemp(&ftemp) ;
Rhyme 0:d895cd1cd897 44 printf("Temp = %d C degree, %.3f C degree\n", itemp, ftemp) ;
Rhyme 0:d895cd1cd897 45 wait(1) ;
Rhyme 0:d895cd1cd897 46 }
Rhyme 0:d895cd1cd897 47 }
Rhyme 0:d895cd1cd897 48 * @endcode
Rhyme 0:d895cd1cd897 49 */
Rhyme 0:d895cd1cd897 50 class LM75B
Rhyme 0:d895cd1cd897 51 {
Rhyme 0:d895cd1cd897 52 public:
Rhyme 0:d895cd1cd897 53 /**
Rhyme 0:d895cd1cd897 54 * LM75B constructor
Rhyme 0:d895cd1cd897 55 *
Rhyme 0:d895cd1cd897 56 * @param i2c pointer to the I2C object
Rhyme 0:d895cd1cd897 57 * @param addr addr of the I2C peripheral
Rhyme 0:d895cd1cd897 58 */
Rhyme 0:d895cd1cd897 59 LM75B(I2C *i2c, int addr);
Rhyme 0:d895cd1cd897 60
Rhyme 0:d895cd1cd897 61 /**
Rhyme 0:d895cd1cd897 62 * LM75B destructor
Rhyme 0:d895cd1cd897 63 */
Rhyme 0:d895cd1cd897 64 ~LM75B();
Rhyme 0:d895cd1cd897 65
Rhyme 0:d895cd1cd897 66 /**
Rhyme 0:d895cd1cd897 67 * get temperature as one byte (signed)
Rhyme 0:d895cd1cd897 68 * @param *temp int8_t returns integer part of the temperature
Rhyme 0:d895cd1cd897 69 * @return 0: success not-0: failure
Rhyme 0:d895cd1cd897 70 */
Rhyme 0:d895cd1cd897 71 int temp(int8_t *temp) ;
Rhyme 0:d895cd1cd897 72
Rhyme 0:d895cd1cd897 73 /**
Rhyme 0:d895cd1cd897 74 * get temperature as 11 bit (float)
Rhyme 0:d895cd1cd897 75 * @param *temp float returns the temperature as float
Rhyme 0:d895cd1cd897 76 * @return 0: success not-0: failure
Rhyme 0:d895cd1cd897 77 */
Rhyme 0:d895cd1cd897 78 int getTemp(float *temp) ;
Rhyme 0:d895cd1cd897 79
Rhyme 0:d895cd1cd897 80 /**
Rhyme 0:d895cd1cd897 81 * get configuration register
Rhyme 0:d895cd1cd897 82 * @param ptr_byte uint8_t pointer value for the register
Rhyme 0:d895cd1cd897 83 * @param *config_data uint8_t value of the config register
Rhyme 0:d895cd1cd897 84 * @return 0: success non-0: failure
Rhyme 0:d895cd1cd897 85 */
Rhyme 0:d895cd1cd897 86 int getConfig(uint8_t ptr_byte, uint8_t *config_data) ;
Rhyme 0:d895cd1cd897 87
Rhyme 0:d895cd1cd897 88 /**
Rhyme 0:d895cd1cd897 89 * set configuration register
Rhyme 0:d895cd1cd897 90 * @param ptr_byte uint8_t pointer value for the register
Rhyme 0:d895cd1cd897 91 * @param config_data uint8_t value to set in the config register
Rhyme 0:d895cd1cd897 92 * @return 0: success non-0: failure
Rhyme 0:d895cd1cd897 93 */
Rhyme 0:d895cd1cd897 94 int setConfig(uint8_t ptr_byte, uint8_t config_data) ;
Rhyme 0:d895cd1cd897 95
Rhyme 0:d895cd1cd897 96 private:
Rhyme 0:d895cd1cd897 97 I2C *p_i2c;
Rhyme 0:d895cd1cd897 98 int m_addr;
Rhyme 0:d895cd1cd897 99 int readRegs(int addr, uint8_t * data, int len);
Rhyme 0:d895cd1cd897 100 int writeRegs(uint8_t * data, int len);
Rhyme 0:d895cd1cd897 101
Rhyme 0:d895cd1cd897 102 };
Rhyme 0:d895cd1cd897 103
Rhyme 0:d895cd1cd897 104 #endif