29 #define SI7013_READ_TEMP 0xE0
32 #define SI7013_READ_RH 0xE5
34 #define SI7013_READ_RH_NH 0xF5
36 #define SI7013_READ_VIN 0xEE
38 #define SI7013_READ_ID1_1 0xFA
39 #define SI7013_READ_ID1_2 0x0F
40 #define SI7013_READ_ID2_1 0xFc
41 #define SI7013_READ_ID2_2 0xc9
43 #define SI7013_READ_FWREV_1 0x84
44 #define SI7013_READ_FWREV_2 0xB8
69 static int32_t Si7013_Measure(
I2C_TypeDef *i2c, uint8_t addr, uint32_t *data,
74 uint8_t i2c_read_data[2];
75 uint8_t i2c_write_data[1];
80 i2c_write_data[0] = command;
81 seq.
buf[0].
data = i2c_write_data;
84 seq.
buf[1].
data = i2c_read_data;
95 *data = ((uint32_t) i2c_read_data[0] << 8) + (i2c_read_data[1] & 0xfc);
115 static int32_t Si7013_StartNoHoldMeasure(
I2C_TypeDef *i2c, uint8_t addr, uint8_t command)
120 uint8_t i2c_read_data[2];
121 uint8_t i2c_write_data[1];
126 i2c_write_data[0] = command;
127 seq.
buf[0].
data = i2c_write_data;
130 seq.
buf[1].
data = i2c_read_data;
161 uint8_t i2c_write_data[2];
162 uint8_t i2c_read_data[1];
167 i2c_write_data[0] = SI7013_READ_FWREV_1;
168 i2c_write_data[1] = SI7013_READ_FWREV_2;
169 seq.
buf[0].
data = i2c_write_data;
172 seq.
buf[1].
data = i2c_read_data;
180 return (uint32_t) ret;
182 *fwRev = i2c_read_data[0];
199 int ret = Si7013_StartNoHoldMeasure(i2c, addr, SI7013_READ_RH_NH);
218 static int32_t Si7013_ReadNoHoldData(
I2C_TypeDef *i2c, uint8_t addr, uint32_t *data)
222 uint8_t i2c_read_data[2];
227 seq.
buf[0].
data = i2c_read_data;
230 seq.
buf[1].
data = i2c_read_data;
241 *data = ((uint32_t) i2c_read_data[0] << 8) + (i2c_read_data[1] & 0xfc);
264 int ret = Si7013_ReadNoHoldData(i2c, addr, rhData);
269 *rhData = (((*rhData) * 15625L) >> 13) - 6000;
276 ret = Si7013_Measure(i2c, addr, (uint32_t *) tData, SI7013_READ_TEMP);
280 *tData = (((*tData) * 21965L) >> 13) - 46850;
307 int ret = Si7013_Measure(i2c, addr, rhData, SI7013_READ_RH);
312 *rhData = (((*rhData) * 15625L) >> 13) - 6000;
319 ret = Si7013_Measure(i2c, addr, (uint32_t *) tData, SI7013_READ_TEMP);
323 *tData = (((*tData) * 21965L) >> 13) - 46850;
334 static int32_t Si7013_WriteUserReg2(
I2C_TypeDef *i2c, uint8_t addr, int8_t data)
338 uint8_t i2c_read_data[2];
339 uint8_t i2c_write_data[2];
344 i2c_write_data[0] = 0x50;
345 i2c_write_data[1] = data;
346 seq.
buf[0].
data = i2c_write_data;
349 seq.
buf[1].
data = i2c_read_data;
379 Si7013_WriteUserReg2(i2c, addr, 0x0e);
380 ret = Si7013_Measure(i2c, addr, (uint32_t *) vData, SI7013_READ_VIN);
381 Si7013_WriteUserReg2(i2c, addr, 0x09);
411 uint8_t i2c_read_data[8];
412 uint8_t i2c_write_data[2];
417 i2c_write_data[0] = SI7013_READ_ID2_1;
418 i2c_write_data[1] = SI7013_READ_ID2_2;
419 seq.
buf[0].
data = i2c_write_data;
422 seq.
buf[1].
data = i2c_read_data;
430 if (NULL != deviceId)
432 *deviceId = i2c_read_data[0];
Driver for the Si7013 Temperature / Humidity sensor.
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Perform I2C transfer.
int32_t Si7013_MeasureV(I2C_TypeDef *i2c, uint8_t addr, int32_t *vData)
Reads relative humidity and temperature from a Si7013 sensor.
#define I2C_FLAG_READ
Indicate plain read sequence: S+ADDR(R)+DATA0+P.
bool Si7013_Detect(I2C_TypeDef *i2c, uint8_t addr, uint8_t *deviceId)
Checks if a Si7013 is present on the I2C bus or not.
#define I2C_FLAG_WRITE
Indicate plain write sequence: S+ADDR(W)+DATA0+P.
I2C_TransferReturn_TypeDef
int32_t Si7013_ReadNoHoldRHAndTemp(I2C_TypeDef *i2c, uint8_t addr, uint32_t *rhData, int32_t *tData)
Reads relative humidity and temperature from a Si7013 sensor.
int32_t Si7013_StartNoHoldMeasureRHAndTemp(I2C_TypeDef *i2c, uint8_t addr)
Starts no hold measurement of relative humidity and temperature from a Si7013 sensor.
int32_t Si7013_GetFirmwareRevision(I2C_TypeDef *i2c, uint8_t addr, uint8_t *fwRev)
Reads Firmware Revision from a Si7013 sensor.
I2C simple poll-based master mode driver for the DK/STK.
struct I2C_TransferSeq_TypeDef::@0 buf[2]
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
#define I2C_FLAG_WRITE_READ
Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
int32_t Si7013_MeasureRHAndTemp(I2C_TypeDef *i2c, uint8_t addr, uint32_t *rhData, int32_t *tData)
Reads relative humidity and temperature from a Si7013 sensor.
uint16_t addr
Address to use after (repeated) start.