The ASIC inside does all the A/D conversions and linearizations and can output a 15bit representation of the pressure (only 12 are used). They do make a range of devices that uses the ASIC so I would imagine this code will work with all of them.
This is a link to the info on the ASIC http://www.produktinfo.conrad.com/daten ... ERATUR.pdf
Serial Digital Interface of HYGROSENS ASIC
Big thanks to Dave for the code.
- Code: Select all
// tested on Firewing for PIC24 board R2, compiler Firewing 16
// configure then import module...
#option I2C_SCL = _D2 ' 5v tolerent on PIC24, PIC32
#option I2C_SDA = _D3 ' 5v tolerent on PIC24, PIC32
#option I2C_DELAY_US = 3
imports I2c
// device constants...
private const START_CYC_RAM as byte = &H02
private const CFG_SIF_TO_I2C as byte = &H52
private const START_NOM as byte = &H71
private const I2C_DEVICE_ADDRESS as byte = &H78 << 1
// program entry point...
Sub Main()
// Start measurement cycle including initialization from
// RAM - processing time is 220us
I2C.Start()
I2C.WriteByte(I2C_DEVICE_ADDRESS)
I2C.WriteByte(START_CYC_RAM)
I2C.Stop()
delayms(1)
// Configure SIF to Communication Mode I2C
I2C.Start()
I2C.WriteByte(I2C_DEVICE_ADDRESS)
I2C.WriteByte(CFG_SIF_TO_I2C)
I2C.Stop()
// Start Normal Operation Mode (NOM). In Normal Operation Mode
// the command set is restricted
I2C.Start()
I2C.WriteByte(I2C_DEVICE_ADDRESS)
I2C.WriteByte(START_NOM)
I2C.Stop()
// loop forever...
while true
// read data - high byte, low byte
// The pressure is transferred as 15 bit value (bit 0 – 14). From the 15
// bit measured values, approx. 12 bit are used as resolution, the three
// least significant bits can be ignored.
dim result as ushort
I2C.Start()
I2C.WriteByte(I2C_DEVICE_ADDRESS + 1) ' Address the device and tell it you want to do a read by setting the LSB to 1
result.byte1 = I2C.ReadByte() ' Read in the MSB
I2C.Acknowledge(IsAcknowledge) ' Send an ACK
result.byte0 = I2C.ReadByte() ' Read in the LSB
I2C.Stop() ' Send the stop
result = result >> 3 ' Were interested in only 12 bits
// display result via UART...
Console.Write("value = ", cstr(result),13,10) ' Display the results
delayms(500)
end while
End Sub