SI7021 - Relative Humidity and Temperature Sensor

Detailed Description

Driver for the Silicon Labs Si7021 I2C Humidity and Temperature Sensor.

Functions

uint32_t SI7021_cmdRead (uint8_t *cmd, size_t cmdLen, uint8_t *result, size_t resultLen)
Sends a command and reads the result byte(s) over the I2C bus.
uint32_t SI7021_cmdWrite (uint8_t *cmd, size_t cmdLen, uint8_t *data, size_t dataLen)
Sends a command and data to the chip over the I2C bus.
void SI7021_deInit (void)
De-initializes the Si7021 chip. Disables the sensor power domain, this also disables other sensors.
uint32_t SI7021_getFwRev (uint8_t *fwRev)
Reads the firmware revision of the Si7021 chip.
uint32_t SI7021_init (void)
Initializes the Si7021 chip.
uint32_t SI7021_measure (uint32_t *rhData, int32_t *tData)
Performs relative humidity and temperature measurements.

Error Codes

#define SI7021_OK 0
#define SI7021_ERROR_I2C_TRANSFER_NACK 0x0001
#define SI7021_ERROR_I2C_TRANSFER_FAILED 0x0002
#define SI7021_ERROR_INVALID_DEVICE_ID 0x0003
#define SI7021_ERROR_TIMEOUT 0x0004

Si7021 Commands

#define SI7021_CMD_MEASURE_RH 0xE5
#define SI7021_CMD_MEASURE_RH_NO_HOLD 0xF5
#define SI7021_CMD_MEASURE_TEMP 0xE3
#define SI7021_CMD_MEASURE_TEMP_NO_HOLD 0xF3
#define SI7021_CMD_READ_TEMP 0xE0
#define SI7021_CMD_RESET 0xFE
#define SI7021_CMD_WRITE_USER_REG1 0xE6
#define SI7021_CMD_READ_USER_REG1 0xE7
#define SI7021_CMD_WRITE_HEATER_CTRL 0x51
#define SI7021_CMD_READ_HEATER_CTRL 0x11
#define SI7021_CMD_READ_ID_BYTE1 { 0xFA, 0x0F }
#define SI7021_CMD_READ_ID_BYTE2 { 0xFC, 0xC9 }
#define SI7021_CMD_READ_FW_REV { 0x84, 0xB8 }

Macro Definition Documentation

#define SI7021_CMD_MEASURE_RH   0xE5

Measure Relative Humidity, Hold Master Mode

Definition at line 62 of file si7021.h .

#define SI7021_CMD_MEASURE_RH_NO_HOLD   0xF5

Measure Relative Humidity, No Hold Master Mode

Definition at line 63 of file si7021.h .

Referenced by SI7021_measure() .

#define SI7021_CMD_MEASURE_TEMP   0xE3

Measure Temperature, Hold Master Mode

Definition at line 64 of file si7021.h .

#define SI7021_CMD_MEASURE_TEMP_NO_HOLD   0xF3

Measure Temperature, No Hold Master Mode

Definition at line 65 of file si7021.h .

#define SI7021_CMD_READ_FW_REV   { 0x84, 0xB8 }

Read Firmware Revision

Definition at line 74 of file si7021.h .

Referenced by SI7021_getFwRev() .

#define SI7021_CMD_READ_HEATER_CTRL   0x11

Read Heater Control Register

Definition at line 71 of file si7021.h .

#define SI7021_CMD_READ_ID_BYTE1   { 0xFA, 0x0F }

Read Electronic ID 1st Byte

Definition at line 72 of file si7021.h .

#define SI7021_CMD_READ_ID_BYTE2   { 0xFC, 0xC9 }

Read Electronic ID 2nd Byte

Definition at line 73 of file si7021.h .

Referenced by SI7021_init() .

#define SI7021_CMD_READ_TEMP   0xE0

Read Temperature Value from Previous RH Measurement

Definition at line 66 of file si7021.h .

Referenced by SI7021_measure() .

#define SI7021_CMD_READ_USER_REG1   0xE7

Read RH/T User Register 1

Definition at line 69 of file si7021.h .

#define SI7021_CMD_RESET   0xFE

Reset

Definition at line 67 of file si7021.h .

#define SI7021_CMD_WRITE_HEATER_CTRL   0x51

Write Heater Control Register

Definition at line 70 of file si7021.h .

Referenced by measureSupplyIR() .

#define SI7021_CMD_WRITE_USER_REG1   0xE6

Write RH/T User Register 1

Definition at line 68 of file si7021.h .

Referenced by measureSupplyIR() .

#define SI7021_ERROR_I2C_TRANSFER_FAILED   0x0002

I2C transaction failed

Definition at line 54 of file si7021.h .

Referenced by SI7021_cmdRead() , and SI7021_cmdWrite() .

#define SI7021_ERROR_I2C_TRANSFER_NACK   0x0001

No acknowledgement received

Definition at line 53 of file si7021.h .

Referenced by SI7021_cmdRead() , SI7021_cmdWrite() , and SI7021_measure() .

#define SI7021_ERROR_INVALID_DEVICE_ID   0x0003

The device ID is invalid

Definition at line 55 of file si7021.h .

Referenced by SI7021_init() .

#define SI7021_ERROR_TIMEOUT   0x0004

Timeout occurred

Definition at line 56 of file si7021.h .

Referenced by SI7021_measure() .

#define SI7021_OK   0

No errors

Definition at line 52 of file si7021.h .

Referenced by SI7021_cmdRead() , SI7021_cmdWrite() , SI7021_init() , and SI7021_measure() .

Function Documentation

uint32_t SI7021_cmdRead ( uint8_t * cmd,
size_t cmdLen,
uint8_t * result,
size_t resultLen
)

Sends a command and reads the result byte(s) over the I2C bus.

Parameters
[in] cmd The command to be sent
[in] cmdLen The length of the command in bytes
[out] result The received bytes sent by the chip
[in] resultLen The number of the bytes to read from the chip
Returns
Returns zero on OK, non-zero otherwise

Definition at line 193 of file si7021.c .

References BOARD_i2cBusSelect() , I2CSPM_Transfer() , SI7021_ERROR_I2C_TRANSFER_FAILED , SI7021_ERROR_I2C_TRANSFER_NACK , and SI7021_OK .

Referenced by SI7021_getFwRev() , SI7021_init() , and SI7021_measure() .

uint32_t SI7021_cmdWrite ( uint8_t * cmd,
size_t cmdLen,
uint8_t * data,
size_t dataLen
)

Sends a command and data to the chip over the I2C bus.

Parameters
[in] cmd The command to be sent
[in] cmdLen The length of the command in bytes
[out] data The data byte(s) to be sent to the chip
[in] dataLen The number of the bytes to be sent to the chip
Returns
Returns zero on OK, non-zero otherwise

Definition at line 246 of file si7021.c .

References BOARD_i2cBusSelect() , I2CSPM_Transfer() , SI7021_ERROR_I2C_TRANSFER_FAILED , SI7021_ERROR_I2C_TRANSFER_NACK , and SI7021_OK .

Referenced by measureSupplyIR() , and SI7021_measure() .

void SI7021_deInit ( void )

De-initializes the Si7021 chip. Disables the sensor power domain, this also disables other sensors.

Returns
None

Definition at line 86 of file si7021.c .

References BOARD_rhtempEnable() .

Referenced by UTIL_supplyProbe() .

uint32_t SI7021_getFwRev ( uint8_t * fwRev )

Reads the firmware revision of the Si7021 chip.

Parameters
[out] fwRev The firmware revision of the chip
Returns
Returns zero on OK, non-zero otherwise

Definition at line 164 of file si7021.c .

References SI7021_CMD_READ_FW_REV , and SI7021_cmdRead() .

uint32_t SI7021_init ( void )

Initializes the Si7021 chip.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 55 of file si7021.c .

References BOARD_rhtempEnable() , SI7021_CMD_READ_ID_BYTE2 , SI7021_cmdRead() , SI7021_DEVICE_ID , SI7021_ERROR_INVALID_DEVICE_ID , SI7021_OK , and UTIL_delay() .

Referenced by UTIL_supplyProbe() .

uint32_t SI7021_measure ( uint32_t * rhData,
int32_t * tData
)

Performs relative humidity and temperature measurements.

Parameters
[out] rhData The measured relative humidity value in milli-percent units
[out] tData The measured temperature value in milli-degree Celsius
Returns
Returns zero on OK, non-zero otherwise

Definition at line 105 of file si7021.c .

References SI7021_CMD_MEASURE_RH_NO_HOLD , SI7021_CMD_READ_TEMP , SI7021_cmdRead() , SI7021_cmdWrite() , SI7021_ERROR_I2C_TRANSFER_NACK , SI7021_ERROR_TIMEOUT , SI7021_OK , and UTIL_delay() .