Okay I found my stupid mistake, temp & humidity mixed up.
HIH6130_6131_Install_50061154-3-EN_Final_24Oct11.pdf details what's going on with protection this part.
Here is my code, it gives the same results as Paul's. not sure which generates less code or is more eff. etc.
It is written for the xmega.
[code:1:b17404a0eb]'--Honeywell HIH6130-6131 Humidty & Temp Sensor
Const Hih6130_w = &H4E '0b0100_1110,Hih6130 Write Address
Const Hih6130_r = &H4F '0b0100_1111,Hih6130 Read Address
Dim Hih6130_humidity As Word
'Hih6130_humidity = 8192 'should display 50%RH
Dim Hih6130_humidity_l As Byte At Hih6130_humidity Overlay
Dim Hih6130_humidity_h As Byte At Hih6130_humidity + 1 Overlay
'Hih6130_humidity = &B0010_0000_0000_0000 'test humidity data for 50%RH display
Dim Hih6130_temp As Word
'Hih6130_temp = 7500 'should display 35.5C
Dim Hih6130_temp_l As Byte At Hih6130_temp Overlay
Dim Hih6130_temp_h As Byte At Hih6130_temp + 1 Overlay
'Hih6130_temp = &B0111_0101_0010_0000 'test temp data for 35.5C display
Dim Hih6130_status As Byte
Dim Hih6130_humidity_single As Single
'Hih6130_humidity_single = 50.0
Dim Hih6130_temp_single As Single
'Hih6130_temp_single = 35.5
Sub Hih6130_write() 'starts mesurement cycle
'test data Hih6130_temp = 00 10_0000_0000_0000
I2cstart #10
I2cwbyte Hih6130_w , #10
I2cstop #10
End Sub
Sub Hih6130_read()
'test data Hih6130_temp = 00 10_0000_0000_0000
I2cstart #10
I2cwbyte Hih6130_r , #10
I2crbyte Hih6130_humidity_h , Ack , #10
I2crbyte Hih6130_humidity_l , Ack , #10
I2crbyte Hih6130_temp_h, Ack , #10
I2crbyte Hih6130_temp_l, Nack , #10
I2cstop #10
'Hih6130_humidity = &B0010_0000_0000_0000 'test humidity data for 50%RH display
'Hih6130_temp = &B0111_0101_0010_0000 'test temp data for 35.5C display
Hih6130_status = Hih6130_humidity_h And &B1100_0000 'extract status bits
Hih6130_humidity_h = Hih6130_humidity_h And &B0011_1111 'mask out status bits
'If Hih6130_status = 0 Then 'normal operation: valid data that has
'not been fetched since the last measurement cycle
'Shift Hih6130_status , Right , 6 'not necessary
Shift Hih6130_temp , Right , 2
'X1 = 2 ^ 14 'Humidity(RH%)= (Hih6130_humidity/(2^14 -1)) * 100%
'X1 = X1 - 1
'Hih6130_humidity_single = Hih6130_humidity X1 '16383
Hih6130_humidity_single = Hih6130_humidity 16383
Hih6130_humidity_single = Hih6130_humidity_single * 100
'Hih6130_temp_single = Hih6130_temp X1 'Temperature(C)= (Hih6130_temp/(2^14 -1)) * 165 - 40
Hih6130_temp_single = Hih6130_temp 16383
Hih6130_temp_single = Hih6130_temp_single * 165
Hih6130_temp_single = Hih6130_temp_single - 40
'End If
End Sub[/code:1:b17404a0eb]
↧