![](/media/cache/group/1711.jpg.50x50_q85.jpg)
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) 反転させることにより、疑似リセットクロックを生成します。
その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。
Diff: sensors/SMTC502AT.cpp
- Revision:
- 0:d895cd1cd897
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensors/SMTC502AT.cpp Tue Apr 03 08:30:29 2018 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" +#include "SMTC502AT.h" + +SMTC502AT::SMTC502AT(AnalogIn *ain, float R0, float R1, float B, float T0) +{ + _ain = ain ; + _r0 = R0 ; + _r1 = R1 ; + _b = B ; + _t0 = T0 ; +} + +SMTC502AT::~SMTC502AT(void) +{ + if (_ain) { + delete _ain ; + } +} + +/** + * getTemp returns the temperature + * operational temperature is -50C to +105C + */ +float SMTC502AT::getTemp(void) +{ + float result = 0.0 ; + float f, raw, rr1, t ; + if (_ain) { + f = _ain->read() ; +#if 0 + if (f < 0.087) { /* +105C */ + printf("Temp is Too high or the sensor is absent\n") ; + f = 0.087 ; + } + if (f > 0.978) { /* -50C */ + printf("Temp is Too low or the sensor encountered a problem\n") ; + f = 0.978 ; + } +#endif + raw = f * 3.3 ; + rr1 = _r1 * raw / (3.3 - raw) ; + t = 1.0 / (log(rr1 / _r0) / _b + (1/_t0)) ; + result = t - 273.15 ; + } + return( result ) ; +} + \ No newline at end of file