EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
si7021.h
Go to the documentation of this file.
1 /***************************************************************************/
16 #ifndef __SI7021_H_
17 #define __SI7021_H_
18 
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include "si7021_config.h"
22 
23 /***************************************************************************/
28 /***************************************************************************/
34 #ifndef SI7021_CONFIG_I2C_DEVICE
35 #define SI7021_CONFIG_I2C_DEVICE (I2C0)
36 #endif
37 
38 #ifndef SI7021_CONFIG_I2C_BUS_ADDRESS
39 #define SI7021_CONFIG_I2C_BUS_ADDRESS 0x40
40 #endif
41 
42 #ifndef SI7021_CONFIG_DEVICE_ID
43 #define SI7021_CONFIG_DEVICE_ID 0x21
44 #endif
45 
46 #define SI7021_I2C_DEVICE SI7021_CONFIG_I2C_DEVICE
47 #define SI7021_I2C_BUS_ADDRESS SI7021_CONFIG_I2C_BUS_ADDRESS
48 #define SI7021_DEVICE_ID SI7021_CONFIG_DEVICE_ID
52 /***************************************************************************/
58 #define SI7021_OK 0
59 #define SI7021_ERROR_I2C_TRANSFER_NACK 0x0001
60 #define SI7021_ERROR_I2C_TRANSFER_FAILED 0x0002
61 #define SI7021_ERROR_INVALID_DEVICE_ID 0x0003
62 #define SI7021_ERROR_TIMEOUT 0x0004
66 /***************************************************************************/
72 #define SI7021_CMD_MEASURE_RH 0xE5
73 #define SI7021_CMD_MEASURE_RH_NO_HOLD 0xF5
74 #define SI7021_CMD_MEASURE_TEMP 0xE3
75 #define SI7021_CMD_MEASURE_TEMP_NO_HOLD 0xF3
76 #define SI7021_CMD_READ_TEMP 0xE0
77 #define SI7021_CMD_RESET 0xFE
78 #define SI7021_CMD_WRITE_USER_REG1 0xE6
79 #define SI7021_CMD_READ_USER_REG1 0xE7
80 #define SI7021_CMD_WRITE_HEATER_CTRL 0x51
81 #define SI7021_CMD_READ_HEATER_CTRL 0x11
82 #define SI7021_CMD_READ_ID_BYTE1 {0xFA, 0x0F}
83 #define SI7021_CMD_READ_ID_BYTE2 {0xFC, 0xC9}
84 #define SI7021_CMD_READ_FW_REV {0x84, 0xB8}
88 /***************************************************************************/
94 uint32_t SI7021_init ( void );
95 void SI7021_deInit ( void );
96 uint32_t SI7021_measure ( uint32_t *rhData, int32_t *tData );
97 uint32_t SI7021_getFwRev ( uint8_t *fwRev );
98 
99 uint32_t SI7021_cmdWrite ( uint8_t *cmd, size_t cmdLen, uint8_t *data, size_t dataLen );
100 uint32_t SI7021_cmdRead ( uint8_t *cmd, size_t cmdLen, uint8_t *result, size_t resultLen );
101 
106 #endif /* __SI7021_H_ */
uint32_t SI7021_getFwRev(uint8_t *fwRev)
Reads the firmware revision of the Si7021 chip.
Definition: si7021.c:157
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.
Definition: si7021.c:247
uint32_t SI7021_measure(uint32_t *rhData, int32_t *tData)
Performs relative humidity and temperature measurements.
Definition: si7021.c:94
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.
Definition: si7021.c:188
void SI7021_deInit(void)
De-initializes the Si7021 chip. Disables the sensor power domain, this also disables other sensors...
Definition: si7021.c:74