Dear forum,
I have made good use of some code in the finished section from 'dorfusf' (many thanks for posting), and it works fine with a Sensirion SHT75 sensor connected to pins c.1 and c.2 for clock and data. I have now spent many hours trying to get a second sensor working without success only to find (after taking everything back to basics) that this sensor will only work on c.1 and c.2. If I move the c.2 to c.0 to free up c.2 and c.3 for the new sensor I seem to get bad bytes coming back.
What cold be the difference in these pins function to stop this code from working? I'm not using any of the specific pin functions.
Many thanks in advance, this is a superb forum and full credit to all the regular contibutors. I read with interest everyday.
I have made good use of some code in the finished section from 'dorfusf' (many thanks for posting), and it works fine with a Sensirion SHT75 sensor connected to pins c.1 and c.2 for clock and data. I have now spent many hours trying to get a second sensor working without success only to find (after taking everything back to basics) that this sensor will only work on c.1 and c.2. If I move the c.2 to c.0 to free up c.2 and c.3 for the new sensor I seem to get bad bytes coming back.
What cold be the difference in these pins function to stop this code from working? I'm not using any of the specific pin functions.
Many thanks in advance, this is a superb forum and full credit to all the regular contibutors. I read with interest everyday.
Code:
hsersetup B38400_8, %00
setfreq m8
'====================Constants==================
Symbol TempMeas = %00000011 'Measure Temp command
Symbol HumMeas = %00000101 'Measure Humidity command
Symbol StatRegWrite = %00000110 'Write to Status Register command
Symbol StatRegRead = %00000111 'Read from Status Register command
'Symbol Setup = %00000001 'Status Register write, set precision'
'=====================inputs==================='
Symbol Sensin = pinC.0 'pinc.2 works fine
'====================Outputs===================
Symbol Sensout = C.1 'c.1 is correct for data
Symbol Sensclock = C.0 'c.2 works fine
'====================Varaibles==================
Symbol DataLow = b0 'Working Byte Low 1
Symbol DataHigh = b1 'Working Byte High 1
Symbol DataWord = w0 'Working Word 1 = b0 & b1
Symbol DataLow2 = b2 'Working Byte Low 2
Symbol DataHigh2 = b3 'Working Byte High 2
Symbol DataWord2 = w1 'Working Word 2 = b2 & b3
Symbol counter = b5 'counter
'====================Temp and Hum variables===================
Symbol RH2 = W19
Symbol soRH = W20
Symbol RH1 = W21
Symbol RHlin = W22
Symbol Hum = W23
Symbol HighHum = b44
Symbol LowHum = b45
Symbol TempW = W26
Symbol Temp = W27
'----------------------
'===============================================================
'=======================Initilizing devices=====================
'===============================================================
Main:
hserout 0, ("starting",13,10) 'Write Humidity to dispaly
pause 5000
hserout 0, ("started",13,10) 'Write Humidity to dispaly'
Repeat:
' debug
gosub Tempread ' READ THE TEMP
gosub Humread ' READ THE HUMIDITY
gosub TempHumdisplay ' DISPLAY THE TEMP & HUM'
' hserout 0,("loop",13,10)
goto repeat
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'##########################################SHT 1 SUBROUTINES##################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TempHumDisplay:
DataWord = Temp
if Temp >= 40 then SkipNeg1 'Check negative
pause 10
DataWord = 40 - Temp 'Change because negative
'----------------------------Convert into ASCII for display-------------------------
SkipNeg1:
DataHigh2 = DataWord / 100 + $30
DataLow2 = DataWord // 100
DataHigh = Datalow2 // 10 + $30
Datalow2 = Datalow2 / 10 + $30
pause 10
hserout 0, ("BathroomTemp=+",DataHigh2,DataLow2,".",DataHigh,"C",13,10) 'Write Temperature to LCD
'====================Binary to ascii conversion and then disp on lcd========
Dataword = RHlin
DataHigh2 = DataWord / 100 + $30
DataLow2 = DataWord // 100
DataHigh = Datalow2 // 10 + $30
Datalow2 = Datalow2 / 10 + $30
pause 10
hserout 0, ("BathroomHumd=",DataHigh2,DataLow2,".",datahigh,"%",13,10) 'Write Humidity to dispaly
return
'============================Temperature measurement==============
TempRead:
Datalow = TempMeas 'Load measuring command
gosub shtstart 'Initiate transmission
gosub writedata 'Write CMD to sensor
gosub acklow
pause 500 'Pause
Dataword = 0
gosub readdata 'Read first byte
gosub acklow
Dataword = Dataword * 256 'Shift first MSB byte to MSB pos in Word
gosub readdata 'Read lsb in LSBpos in word
gosub ackhigh
Dataword = Dataword / 10 - 400 'divide by 10 as
Temp = Dataword
return
'=========================Measuring the Humidity===================
HumRead:
DataLow = HumMeas
gosub shtstart 'Transmission start sequences 'Load humidity measure instruction
gosub WriteData 'Write instruction
gosub Acklow 'Provide low acknowledge
pause 500 'Wait for Measurement
RHlin = 0
DataWord = 0 'Clear variable for measurement
gosub readData 'Read first byte, empty
gosub acklow 'Provide low acknowledge
Dataword = Dataword * 256 'Shift first MSB byte to MSB pos in Word
gosub ReadData 'Read second byte
gosub Ackhigh 'Provide high acknowledge
'The next formulas are from Nuts&Volts 91 from parallax.
soRH = dataword 'SHT datasheet formula RH=(soRH*0.0405)-(soRH2*0.0000028)-4
RH2 = soRH ** 26542 'Formula for basic:
RH1 = soRH ** 3468 'RHlin = (soRH ** 26542)
RHlin = RH1 * RH1 + 50 / 100 'RHlin = rhlin - ((sorh**3468)*(sorh**3468) + 50 /100)
RHlin = RH2 - RHlin
RHlin = RHlin - 40
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TransStart ' 'Sensor Transmission Start Sequence, used to begin
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SHTstart:
low sensclock 'START sequence
high sensout
high sensclock
low sensout
low sensclock
high sensclock
high sensout
low sensclock
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WriteData ' 'Write Data byte in DataLow to Sensor '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WriteData:
shiftout sensclock, sensout, 1, (Datalow/8) ' shiftout commands
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' AckHigh ''High Acknowledge to Sensor
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Ackhigh:
high sensout 'Output High
pulsout sensclock,10 'Pulse clk
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' AckLow ' 'Low Acknowledge to Sensor '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Acklow:
low sensout ' output low
pulsout sensclock,10 ' pulse clk
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ReadData 'Read Byte from Sensor into DataLow
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ReadData: 'shift_in routine
input sensout 'Change pin to input to recievedata
for Counter = 1 to 8 'count to 8 for 8 bits
Datalow = Datalow * 2 'move bit 1 pos up
if sensin = 0 then skipMSBpre 'if bit 0 skip
Datalow = Datalow + 1 'if bit 1 add to byte
skipMSBpre:
pulsout sensclock,1 'puls the clock for 1 ms
next Counter
output sensout 'change pin to output for acknowledge.
return