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) 反転させることにより、疑似リセットクロックを生成します。
その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。
sensors/SMTC502AT.cpp@0:d895cd1cd897, 2018-04-03 (annotated)
- Committer:
- Rhyme
- Date:
- Tue Apr 03 08:30:29 2018 +0000
- Revision:
- 0:d895cd1cd897
Initial I2C Pin force reset function added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:d895cd1cd897 | 1 | #include "mbed.h" |
Rhyme | 0:d895cd1cd897 | 2 | #include "SMTC502AT.h" |
Rhyme | 0:d895cd1cd897 | 3 | |
Rhyme | 0:d895cd1cd897 | 4 | SMTC502AT::SMTC502AT(AnalogIn *ain, float R0, float R1, float B, float T0) |
Rhyme | 0:d895cd1cd897 | 5 | { |
Rhyme | 0:d895cd1cd897 | 6 | _ain = ain ; |
Rhyme | 0:d895cd1cd897 | 7 | _r0 = R0 ; |
Rhyme | 0:d895cd1cd897 | 8 | _r1 = R1 ; |
Rhyme | 0:d895cd1cd897 | 9 | _b = B ; |
Rhyme | 0:d895cd1cd897 | 10 | _t0 = T0 ; |
Rhyme | 0:d895cd1cd897 | 11 | } |
Rhyme | 0:d895cd1cd897 | 12 | |
Rhyme | 0:d895cd1cd897 | 13 | SMTC502AT::~SMTC502AT(void) |
Rhyme | 0:d895cd1cd897 | 14 | { |
Rhyme | 0:d895cd1cd897 | 15 | if (_ain) { |
Rhyme | 0:d895cd1cd897 | 16 | delete _ain ; |
Rhyme | 0:d895cd1cd897 | 17 | } |
Rhyme | 0:d895cd1cd897 | 18 | } |
Rhyme | 0:d895cd1cd897 | 19 | |
Rhyme | 0:d895cd1cd897 | 20 | /** |
Rhyme | 0:d895cd1cd897 | 21 | * getTemp returns the temperature |
Rhyme | 0:d895cd1cd897 | 22 | * operational temperature is -50C to +105C |
Rhyme | 0:d895cd1cd897 | 23 | */ |
Rhyme | 0:d895cd1cd897 | 24 | float SMTC502AT::getTemp(void) |
Rhyme | 0:d895cd1cd897 | 25 | { |
Rhyme | 0:d895cd1cd897 | 26 | float result = 0.0 ; |
Rhyme | 0:d895cd1cd897 | 27 | float f, raw, rr1, t ; |
Rhyme | 0:d895cd1cd897 | 28 | if (_ain) { |
Rhyme | 0:d895cd1cd897 | 29 | f = _ain->read() ; |
Rhyme | 0:d895cd1cd897 | 30 | #if 0 |
Rhyme | 0:d895cd1cd897 | 31 | if (f < 0.087) { /* +105C */ |
Rhyme | 0:d895cd1cd897 | 32 | printf("Temp is Too high or the sensor is absent\n") ; |
Rhyme | 0:d895cd1cd897 | 33 | f = 0.087 ; |
Rhyme | 0:d895cd1cd897 | 34 | } |
Rhyme | 0:d895cd1cd897 | 35 | if (f > 0.978) { /* -50C */ |
Rhyme | 0:d895cd1cd897 | 36 | printf("Temp is Too low or the sensor encountered a problem\n") ; |
Rhyme | 0:d895cd1cd897 | 37 | f = 0.978 ; |
Rhyme | 0:d895cd1cd897 | 38 | } |
Rhyme | 0:d895cd1cd897 | 39 | #endif |
Rhyme | 0:d895cd1cd897 | 40 | raw = f * 3.3 ; |
Rhyme | 0:d895cd1cd897 | 41 | rr1 = _r1 * raw / (3.3 - raw) ; |
Rhyme | 0:d895cd1cd897 | 42 | t = 1.0 / (log(rr1 / _r0) / _b + (1/_t0)) ; |
Rhyme | 0:d895cd1cd897 | 43 | result = t - 273.15 ; |
Rhyme | 0:d895cd1cd897 | 44 | } |
Rhyme | 0:d895cd1cd897 | 45 | return( result ) ; |
Rhyme | 0:d895cd1cd897 | 46 | } |
Rhyme | 0:d895cd1cd897 | 47 |