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/PSE530.cpp@0:d895cd1cd897, 2018-04-03 (annotated)
- Committer:
- Rhyme
- Date:
- Tue Apr 03 08:30:29 2018 +0000
- Revision:
- 0:d895cd1cd897
- Child:
- 2:de22987be9ba
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 "PSE530.h" |
Rhyme | 0:d895cd1cd897 | 3 | |
Rhyme | 0:d895cd1cd897 | 4 | /** |
Rhyme | 0:d895cd1cd897 | 5 | * SMC PSE530 pressure sensor |
Rhyme | 0:d895cd1cd897 | 6 | * analog output 1.0V - 5.0V |
Rhyme | 0:d895cd1cd897 | 7 | * 1.0V : 0 |
Rhyme | 0:d895cd1cd897 | 8 | * 5.0V : 1MPa |
Rhyme | 0:d895cd1cd897 | 9 | * (at 0.6V : -0.1MPa) |
Rhyme | 0:d895cd1cd897 | 10 | * Our sensor I/F converts 0-5V to 0-3V |
Rhyme | 0:d895cd1cd897 | 11 | * So we suppose V = Analog Float Value : Pressure |
Rhyme | 0:d895cd1cd897 | 12 | * 0.6V = 0.2 : 0 |
Rhyme | 0:d895cd1cd897 | 13 | * 3.0V = 1.0 : 1MPa |
Rhyme | 0:d895cd1cd897 | 14 | */ |
Rhyme | 0:d895cd1cd897 | 15 | |
Rhyme | 0:d895cd1cd897 | 16 | /** |
Rhyme | 0:d895cd1cd897 | 17 | * conversion from Pa to kgf/cm2 |
Rhyme | 0:d895cd1cd897 | 18 | * 98,066.5 Pa = 1 kgf/cm2 |
Rhyme | 0:d895cd1cd897 | 19 | * 1 Pa = 1 / 98066.6 kgf/cm2 |
Rhyme | 0:d895cd1cd897 | 20 | */ |
Rhyme | 0:d895cd1cd897 | 21 | |
Rhyme | 0:d895cd1cd897 | 22 | PSE530::PSE530(AnalogIn *ain) |
Rhyme | 0:d895cd1cd897 | 23 | { |
Rhyme | 0:d895cd1cd897 | 24 | _ain = ain ; |
Rhyme | 0:d895cd1cd897 | 25 | } |
Rhyme | 0:d895cd1cd897 | 26 | |
Rhyme | 0:d895cd1cd897 | 27 | PSE530::~PSE530(void) |
Rhyme | 0:d895cd1cd897 | 28 | { |
Rhyme | 0:d895cd1cd897 | 29 | if (_ain) { |
Rhyme | 0:d895cd1cd897 | 30 | delete _ain ; |
Rhyme | 0:d895cd1cd897 | 31 | } |
Rhyme | 0:d895cd1cd897 | 32 | } |
Rhyme | 0:d895cd1cd897 | 33 | |
Rhyme | 0:d895cd1cd897 | 34 | /** |
Rhyme | 0:d895cd1cd897 | 35 | * On FRDM-KL25Z ADC's AREF is about 3.28V |
Rhyme | 0:d895cd1cd897 | 36 | * Where the converted pressure output is 0 to 3.21V |
Rhyme | 0:d895cd1cd897 | 37 | * So we must map ADC output 0 to 3.21/3.28 as full scale |
Rhyme | 0:d895cd1cd897 | 38 | * |
Rhyme | 0:d895cd1cd897 | 39 | * Then according to the datasheet of PSE530 |
Rhyme | 0:d895cd1cd897 | 40 | * when full range is 0V to 5V |
Rhyme | 0:d895cd1cd897 | 41 | * 1V is 0 and 5V is 1MPa which is converted to |
Rhyme | 0:d895cd1cd897 | 42 | * 0.642/3.28 to 3.21/3.28 ~ 0.195731 to 0.9786585. |
Rhyme | 0:d895cd1cd897 | 43 | * The linear equation of |
Rhyme | 0:d895cd1cd897 | 44 | * y = a x + b |
Rhyme | 0:d895cd1cd897 | 45 | * 0 = a * 0.195731 + b |
Rhyme | 0:d895cd1cd897 | 46 | * 1 = a * 0.978658 + b |
Rhyme | 0:d895cd1cd897 | 47 | * results a = 1.277, b = -0.250 |
Rhyme | 0:d895cd1cd897 | 48 | */ |
Rhyme | 0:d895cd1cd897 | 49 | float PSE530::getPressure(void) |
Rhyme | 0:d895cd1cd897 | 50 | { |
Rhyme | 0:d895cd1cd897 | 51 | float coef_A = 1.277 ; |
Rhyme | 0:d895cd1cd897 | 52 | float coef_B = -0.250 ; |
Rhyme | 0:d895cd1cd897 | 53 | float av = 0.0 ; |
Rhyme | 0:d895cd1cd897 | 54 | float value = 0.0 ; |
Rhyme | 0:d895cd1cd897 | 55 | av = coef_A * _ain->read() + coef_B ; |
Rhyme | 0:d895cd1cd897 | 56 | // printf("Pressure ADC = %.4f\n", av) ; |
Rhyme | 0:d895cd1cd897 | 57 | value = 1000000 * av ; /* 1MPa at 1.0 */ |
Rhyme | 0:d895cd1cd897 | 58 | value = value / 98066.5 ; /* Pa -> kgf/cm2 */ |
Rhyme | 0:d895cd1cd897 | 59 | return( value ) ; |
Rhyme | 0:d895cd1cd897 | 60 | } |