Got it working, stupid datasheet....
Address is $88, not $44, as in datasheet.
Found that using
https://www.picbasic.co.uk/forum/sho...C-Ping-program
Then is straight forward
1. Read serial
Code:
SHTAdr=$88
SHTCmd=$89
I2CREAD S_SDA1,S_SCL1,SHTAdr,SHTCmd,[SHTArray[0],SHTArray[1],SHTArray[2],SHTArray[3],SHTArray[4],SHTArray[5]]
0-1 serial 1 word, 2 crc, 3-4 serial 2 word, 5 crc
2.Start conversion
Code:
SHTAdr=$88
SHTCmd=$FD
I2CWRITE S_SDA1,S_SCL1,SHTAdr,SHTCmd,SensorFailNoAck
3. Read Temp and RH data after 20mS
Code:
SHTAdr=$88
I2CREAD S_SDA1,S_SCL1,SHTAdr,[SHTArray[0],SHTArray[1],SHTArray[2],SHTArray[3],SHTArray[4],SHTArray[5]]
0-1 hold temp, 2 hold crc, 3-4 hold humidity, 5 hold crc.
If I add SensorFailNoAck, then it trigers every time, not sure why... I'll use crc to check for correct communication.
CRC8 routine:
Code:
CalcCRC:
crc=$ff
for byteCtr = 0 to 1
TmpB=CRCArray[byteCtr]
crc = crc ^ TmpB
for i = 0 to 7
if crc.7=1 then
crc = (crc << 1)
crc = crc ^ $31
else
crc =crc << 1
endif
next i
next byteCtr
Need to check calculation from ticks to T[°C] and RH[%].
And to try to understand heater... How and why to use it.
Bookmarks