26 #define SHT21_TRIGGER_T_MEAS 0xF3
27 #define SHT21_TRIGGER_RH_MEAS 0xF5
32 #define SHT21_T_MEAS 0xE3
33 #define SHT21_RH_MEAS 0xE5
42 data = SHT21_TRIGGER_T_MEAS;
47 static int convToC(uint8_t * data) {
52 myval = (data[0] << 8) + data[1];
66 if (!
i2cRead(dev, addr, myansw,
sizeof(myansw))){
71 *answer = convToC(myansw);
88 if(!
i2cRead(dev, addr, myansw,
sizeof(myansw))){
94 *answer = convToC(myansw);
105 data = SHT21_TRIGGER_RH_MEAS;
110 static int convToHum(uint8_t * data) {
116 myval = (data[0] << 8) + data[1];
130 if (!
i2cRead(dev, addr, myansw,
sizeof(myansw))){
134 *answer = convToHum(myansw);
145 data = SHT21_RH_MEAS;
147 if (!
i2cWrite(dev, addr, &data, 1)){
151 if (!
i2cRead(dev, addr, myansw,
sizeof(myansw))){
155 *answer = convToHum(myansw);
bool i2cWrite(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Writes to the I2C device.
bool sht21Humi(I2C_Device *dev, uint8_t addr, int *answer)
Starts and reads the relative humidity from SHT21 at I2C address 'addr' (hold master mode); puts the ...
Structure defines OpenCores I2C Device.
bool sht21Temp(I2C_Device *dev, uint8_t addr, int *answer)
Starts and reads the temperatures from SHT21 at I2C address 'addr' (hold master mode); puts the resul...
bool sht21ReadTemp(I2C_Device *dev, uint8_t addr, int *answer)
Reads the temperatures from SHT21 at I2C address 'addr'; puts the result in answer.
static bool errCondRebase(bool err, const char *name)
Transparent conditional error rebase.
bool sht21ReadHumid(I2C_Device *dev, uint8_t addr, int *answer)
Reads the relative humidity from SHT21 at I2C address 'addr'; puts the result in answer.
Manages the global system error.
This driver is to read the SHT21 I2C temperature and humidity sensor.
bool i2cRead(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Reads from the I2C device.
static bool errRebase(const char *name)
Rebases the cause of the error message.
bool sht21StartTempMeas(I2C_Device *dev, uint8_t addr)
Starts the temperature measurement in the SHT21 module at I2C address 'addr'.
bool sht21StartHumidMeas(I2C_Device *dev, uint8_t addr)
Starts the relative humidity measurement in the SHT21 module at I2C address 'addr'.
OpenCores I2C device driver.