TACHYON V4 IFDEF SHT31 @rest org FORGET SHT31 } pub SHT31 ." SHT31 2017/07/14 9:29:40 " ; @org W@ == @rest --- remember { SHT31module Propeller Vcc ------- 3.3V Addr SCL ------- P28 SDA ------- P29 GND ------- GND } \ =========================================================================== \ Constants \ =========================================================================== \ Slave addres h45 for SHT31 \ slaveAddr+wr = $8A $8A == SHT31 { command code for single shot index:0 Repeatability:High ClockStreching enabled index:1 Repeatability:Medium ClockStreching enabled index:2 Repeatability:Low ClockStreching enabled index:3 Repeatability:High ClockStreching disabled index:4 Repeatability:Medium ClockStreching disabled index:5 Repeatability:Low ClockStreching disabled } TABLE SingleShot $2C06 || $2C0D || $2C10 || \ ClockStrech valid $2400 || $240B || $2416 || \ ClockStrech invalid { command code for Periodic Data Acquisition Mode index:0 Repeatability:High 0.5mps index:1 Repeatability:Medium 0.5mps index:2 Repeatability:Low 0.5mps index:3 Repeatability:High 1mps index:4 Repeatability:Medium 1mps index:5 Repeatability:Low 1mps index:3 Repeatability:High 2mps index:4 Repeatability:Medium 2mps index:5 Repeatability:Low 2mps index:3 Repeatability:High 4mps index:4 Repeatability:Medium 4mps index:5 Repeatability:Low 4mps index:3 Repeatability:High 10mps index:4 Repeatability:Medium 10mps index:5 Repeatability:Low 10mps } TABLE Periodic $2032 || $2024 || $202F || \ 0.5mps $2130 || $2126 || $212D || \ 1mps $2236 || $2220 || $222B || \ 2mps $2334 || $2322 || $2329 || \ 4mps $2737 || $2721 || $272A || \ 10mps \ =========================================================================== \ Variables \ =========================================================================== \ =========================================================================== \ Main \ =========================================================================== \ Scan list for i2c-line \ ( -- ) : i2cScan 6 SPACES ." 0 1 2 3 4 5 6 7 8 9 A B C D E F" CR 0 #16 BY 8 FOR I .BYTE 3 SPACES #16 FOR SWAP $78 < AND \ Count up device (eliminate reserve number) IF 1+ ENDIF ENDIF SPACE NEXT CR NEXT ." I2C devices:" . CR ; \ Calculate Temperature \ ( n1 -- ) n1:16bit value : calcTemp #17500 * \ T = -45 + 175 * St / (2^16-1) #65535 / #4500 - #100 U/MOD . $2E EMIT . ." degreeC" CR ; \ Calculate Humidity \ ( n1 -- ) n1:16bit value : calcHumidity #10000 * \ RH = 100 * Srh / (2^16-1) #65535 / #100 U/MOD . $2E EMIT . $25 EMIT ; \ SoftReset \ ( -- ) : SoftReset ; \ GeneralCall Reset \ ( -- ) : GCreset ; \ Single Shot measurement \ ( n1 -- ) n1:index for single shot command table : 1shot DUP \ ( n1 n1 ) 2* SingleShot + W@ \ Get command ( n1 command) DUP 8 SHR \ ( n1 commndL commandH ) ; END