Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ECE4180FinalProjectFall22
ens160_i2c_regs.h@5:a0c26b45ad20, 2022-12-08 (annotated)
- Committer:
- krishnamvs
- Date:
- Thu Dec 08 16:50:54 2022 +0000
- Revision:
- 5:a0c26b45ad20
- Parent:
- 3:63ff52373e71
Removed mbed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krishnamvs | 3:63ff52373e71 | 1 | #include "mbed.h" |
krishnamvs | 3:63ff52373e71 | 2 | #include <stdint.h> |
krishnamvs | 3:63ff52373e71 | 3 | |
krishnamvs | 3:63ff52373e71 | 4 | #define SFE_ENS160_PART_ID 0x00 |
krishnamvs | 3:63ff52373e71 | 5 | |
krishnamvs | 3:63ff52373e71 | 6 | typedef struct |
krishnamvs | 3:63ff52373e71 | 7 | { |
krishnamvs | 3:63ff52373e71 | 8 | uint8_t part_id_msb : 8; // Value = 0x01 |
krishnamvs | 3:63ff52373e71 | 9 | uint8_t part_id_lsb : 8; // Value = 0x60 |
krishnamvs | 3:63ff52373e71 | 10 | } sfe_ens160_part_id_t; |
krishnamvs | 3:63ff52373e71 | 11 | |
krishnamvs | 3:63ff52373e71 | 12 | #define SFE_ENS160_OP_MODE 0x10 |
krishnamvs | 3:63ff52373e71 | 13 | // Possible Operating Mode defines: |
krishnamvs | 3:63ff52373e71 | 14 | #define SFE_ENS160_DEEP_SLEEP 0x00 |
krishnamvs | 3:63ff52373e71 | 15 | #define SFE_ENS160_IDLE 0x01 |
krishnamvs | 3:63ff52373e71 | 16 | #define SFE_ENS160_STANDARD 0x02 |
krishnamvs | 3:63ff52373e71 | 17 | #define SFE_ENS160_RESET 0xF0 |
krishnamvs | 3:63ff52373e71 | 18 | typedef struct |
krishnamvs | 3:63ff52373e71 | 19 | { |
krishnamvs | 3:63ff52373e71 | 20 | uint8_t op_mode : 8; |
krishnamvs | 3:63ff52373e71 | 21 | } sfe_ens160_op_mode_t; |
krishnamvs | 3:63ff52373e71 | 22 | |
krishnamvs | 3:63ff52373e71 | 23 | #define SFE_ENS160_CONFIG 0x11 |
krishnamvs | 3:63ff52373e71 | 24 | typedef struct |
krishnamvs | 3:63ff52373e71 | 25 | { |
krishnamvs | 3:63ff52373e71 | 26 | uint8_t reserved_three : 1; |
krishnamvs | 3:63ff52373e71 | 27 | uint8_t int_pol : 1; |
krishnamvs | 3:63ff52373e71 | 28 | uint8_t int_cfg : 1; |
krishnamvs | 3:63ff52373e71 | 29 | uint8_t reserved_two : 1; |
krishnamvs | 3:63ff52373e71 | 30 | uint8_t int_gpr : 1; |
krishnamvs | 3:63ff52373e71 | 31 | uint8_t reserved_one : 1; |
krishnamvs | 3:63ff52373e71 | 32 | uint8_t int_dat : 1; |
krishnamvs | 3:63ff52373e71 | 33 | uint8_t int_en : 1; |
krishnamvs | 3:63ff52373e71 | 34 | } sfe_ens160_config_t; |
krishnamvs | 3:63ff52373e71 | 35 | |
krishnamvs | 3:63ff52373e71 | 36 | #define SFE_ENS160_COMMAND 0x12 |
krishnamvs | 3:63ff52373e71 | 37 | // All commands must be issued when device is idle. |
krishnamvs | 3:63ff52373e71 | 38 | #define SFE_ENS160_COMMAND_NOP 0x00 |
krishnamvs | 3:63ff52373e71 | 39 | // Get Firwmware App Version - version is placed in General Purpose Read Registers as follows: |
krishnamvs | 3:63ff52373e71 | 40 | // GPR_READ04 - Version (Major) |
krishnamvs | 3:63ff52373e71 | 41 | // GPR_READ05 - Version (Minor) |
krishnamvs | 3:63ff52373e71 | 42 | // GPR_READ06 - Version (Release) |
krishnamvs | 3:63ff52373e71 | 43 | #define SFE_ENS160_COMMAND_GET_APPVER 0x0E |
krishnamvs | 3:63ff52373e71 | 44 | // Clear General Purpose Read Register |
krishnamvs | 3:63ff52373e71 | 45 | #define SFE_ENS160_COMMAND_CLRGPR 0xCC |
krishnamvs | 3:63ff52373e71 | 46 | typedef struct |
krishnamvs | 3:63ff52373e71 | 47 | { |
krishnamvs | 3:63ff52373e71 | 48 | uint8_t command : 8; |
krishnamvs | 3:63ff52373e71 | 49 | } sfe_ens160_command_t; |
krishnamvs | 3:63ff52373e71 | 50 | |
krishnamvs | 3:63ff52373e71 | 51 | #define SFE_ENS160_TEMP_IN 0x13 |
krishnamvs | 3:63ff52373e71 | 52 | // Temperature compensation can be given to the sensor for more accurate |
krishnamvs | 3:63ff52373e71 | 53 | // readings. |
krishnamvs | 3:63ff52373e71 | 54 | // Temperature should be given in Kelvin in the following format: |
krishnamvs | 3:63ff52373e71 | 55 | // Value: Temperature in Kelvin * 64 |
krishnamvs | 3:63ff52373e71 | 56 | // Converting Celsius to Kelvin = Temp + 273.15 |
krishnamvs | 3:63ff52373e71 | 57 | // Ergo: (Temp + 273.15) * 64 |
krishnamvs | 3:63ff52373e71 | 58 | typedef struct |
krishnamvs | 3:63ff52373e71 | 59 | { |
krishnamvs | 3:63ff52373e71 | 60 | uint8_t temp_in_msb : 8; //0x14 -- Integer Part |
krishnamvs | 3:63ff52373e71 | 61 | uint8_t temp_in_lsb : 8; //0x13 -- Fractions Part |
krishnamvs | 3:63ff52373e71 | 62 | } sfe_ens160_temp_in_t; |
krishnamvs | 3:63ff52373e71 | 63 | |
krishnamvs | 3:63ff52373e71 | 64 | #define SFE_ENS160_RH_IN 0x15 |
krishnamvs | 3:63ff52373e71 | 65 | // Relative Humidity compensation can be given to the sensor for more accurate |
krishnamvs | 3:63ff52373e71 | 66 | // readings. |
krishnamvs | 3:63ff52373e71 | 67 | // RH should be given in %rH * 512 |
krishnamvs | 3:63ff52373e71 | 68 | typedef struct |
krishnamvs | 3:63ff52373e71 | 69 | { |
krishnamvs | 3:63ff52373e71 | 70 | uint8_t rh_in_msb : 8; //0x16 -- Integer Part |
krishnamvs | 3:63ff52373e71 | 71 | uint8_t rh_in_lsb : 8; //0x15 -- Fraction Part |
krishnamvs | 3:63ff52373e71 | 72 | } sfe_ens160_rh_in_t; |
krishnamvs | 3:63ff52373e71 | 73 | |
krishnamvs | 3:63ff52373e71 | 74 | #define SFE_ENS160_DEVICE_STATUS 0x20 |
krishnamvs | 3:63ff52373e71 | 75 | typedef struct |
krishnamvs | 3:63ff52373e71 | 76 | { |
krishnamvs | 3:63ff52373e71 | 77 | uint8_t stat_as : 1; |
krishnamvs | 3:63ff52373e71 | 78 | uint8_t stat_er : 1; |
krishnamvs | 3:63ff52373e71 | 79 | uint8_t reserved_two : 1; |
krishnamvs | 3:63ff52373e71 | 80 | uint8_t reserved_one : 1; |
krishnamvs | 3:63ff52373e71 | 81 | uint8_t validity_flag : 2; |
krishnamvs | 3:63ff52373e71 | 82 | uint8_t new_dat : 1; |
krishnamvs | 3:63ff52373e71 | 83 | uint8_t new_gpr : 1; |
krishnamvs | 3:63ff52373e71 | 84 | } sfe_ens160_device_status_t; |
krishnamvs | 3:63ff52373e71 | 85 | |
krishnamvs | 3:63ff52373e71 | 86 | #define SFE_ENS160_DATA_AQI 0x21 |
krishnamvs | 3:63ff52373e71 | 87 | typedef struct |
krishnamvs | 3:63ff52373e71 | 88 | { |
krishnamvs | 3:63ff52373e71 | 89 | uint8_t reserved_one : 6; |
krishnamvs | 3:63ff52373e71 | 90 | uint8_t aqi_uba : 2; |
krishnamvs | 3:63ff52373e71 | 91 | } sfe_ens160_data_aqi_t; |
krishnamvs | 3:63ff52373e71 | 92 | |
krishnamvs | 3:63ff52373e71 | 93 | #define SFE_ENS160_DATA_TVOC 0x22 |
krishnamvs | 3:63ff52373e71 | 94 | // TVOC Data - shares register with ethanol data |
krishnamvs | 3:63ff52373e71 | 95 | typedef struct |
krishnamvs | 3:63ff52373e71 | 96 | { |
krishnamvs | 3:63ff52373e71 | 97 | uint8_t tvoc_msb : 8; |
krishnamvs | 3:63ff52373e71 | 98 | uint8_t tvoc_lsb : 8; |
krishnamvs | 3:63ff52373e71 | 99 | } sfe_ens160_data_tvoc_t; |
krishnamvs | 3:63ff52373e71 | 100 | |
krishnamvs | 3:63ff52373e71 | 101 | #define SFE_ENS160_DATA_ETOH 0x22 |
krishnamvs | 3:63ff52373e71 | 102 | // Ethanol Data - shares register with TVOC data |
krishnamvs | 3:63ff52373e71 | 103 | typedef struct |
krishnamvs | 3:63ff52373e71 | 104 | { |
krishnamvs | 3:63ff52373e71 | 105 | uint8_t etoh_msb : 8; |
krishnamvs | 3:63ff52373e71 | 106 | uint8_t etoh_lsb : 8; |
krishnamvs | 3:63ff52373e71 | 107 | } sfe_ens160_data_etho_t; |
krishnamvs | 3:63ff52373e71 | 108 | |
krishnamvs | 3:63ff52373e71 | 109 | #define SFE_ENS160_DATA_ECO2 0x24 |
krishnamvs | 3:63ff52373e71 | 110 | // CO2 Data |
krishnamvs | 3:63ff52373e71 | 111 | typedef struct |
krishnamvs | 3:63ff52373e71 | 112 | { |
krishnamvs | 3:63ff52373e71 | 113 | uint8_t eco2_msb : 8; |
krishnamvs | 3:63ff52373e71 | 114 | uint8_t eco2_lsb : 8; |
krishnamvs | 3:63ff52373e71 | 115 | } sfe_ens160_data_eco2_t; |
krishnamvs | 3:63ff52373e71 | 116 | |
krishnamvs | 3:63ff52373e71 | 117 | #define SFE_ENS160_DATA_T 0x30 |
krishnamvs | 3:63ff52373e71 | 118 | // Reports the temperature data given to TEMP_IN in the following manner: |
krishnamvs | 3:63ff52373e71 | 119 | // Temperature in Kelvin: Register Value / 64 |
krishnamvs | 3:63ff52373e71 | 120 | // Converting Kelvin to Celsius = Temperature in Kelvin - 273.15 |
krishnamvs | 3:63ff52373e71 | 121 | // Ergo: (Register Value / 64) - 273.15 |
krishnamvs | 3:63ff52373e71 | 122 | typedef struct |
krishnamvs | 3:63ff52373e71 | 123 | { |
krishnamvs | 3:63ff52373e71 | 124 | uint8_t data_t_msb : 8; // Fractions -- 0x31 |
krishnamvs | 3:63ff52373e71 | 125 | uint8_t data_t_lsb : 8; // Integer -- 0x30 |
krishnamvs | 3:63ff52373e71 | 126 | } sfe_ens160_data_t_t; |
krishnamvs | 3:63ff52373e71 | 127 | |
krishnamvs | 3:63ff52373e71 | 128 | #define SFE_ENS160_DATA_RH 0x32 |
krishnamvs | 3:63ff52373e71 | 129 | // Reports the Relative Humidity compensation given to RH_IN in the following manner |
krishnamvs | 3:63ff52373e71 | 130 | // RH = Register Value / 512 |
krishnamvs | 3:63ff52373e71 | 131 | typedef struct |
krishnamvs | 3:63ff52373e71 | 132 | { |
krishnamvs | 3:63ff52373e71 | 133 | uint8_t data_rh_msb : 8; // Fractions -- 0x33 |
krishnamvs | 3:63ff52373e71 | 134 | uint8_t data_rh_lsb : 8; // Integer -- 0x32 |
krishnamvs | 3:63ff52373e71 | 135 | } sfe_ens160_data_rh_t; |
krishnamvs | 3:63ff52373e71 | 136 | |
krishnamvs | 3:63ff52373e71 | 137 | #define SFE_ENS160_DATA_MISR 0x38 |
krishnamvs | 3:63ff52373e71 | 138 | #define POLY 0x1D |
krishnamvs | 3:63ff52373e71 | 139 | // Gives calculated checksum of "DATA_" registers |
krishnamvs | 3:63ff52373e71 | 140 | typedef struct |
krishnamvs | 3:63ff52373e71 | 141 | { |
krishnamvs | 3:63ff52373e71 | 142 | uint8_t data_misr : 8; |
krishnamvs | 3:63ff52373e71 | 143 | } sfe_ens160_data_misr_t; |
krishnamvs | 3:63ff52373e71 | 144 | |
krishnamvs | 3:63ff52373e71 | 145 | // General Purpose Write registers |
krishnamvs | 3:63ff52373e71 | 146 | #define SFE_ENS160_GPR_WRITE0 0x40 |
krishnamvs | 3:63ff52373e71 | 147 | #define SFE_ENS160_GPR_WRITE1 0x41 |
krishnamvs | 3:63ff52373e71 | 148 | #define SFE_ENS160_GPR_WRITE2 0x42 |
krishnamvs | 3:63ff52373e71 | 149 | #define SFE_ENS160_GPR_WRITE3 0x43 |
krishnamvs | 3:63ff52373e71 | 150 | #define SFE_ENS160_GPR_WRITE4 0x44 |
krishnamvs | 3:63ff52373e71 | 151 | #define SFE_ENS160_GPR_WRITE5 0x45 |
krishnamvs | 3:63ff52373e71 | 152 | #define SFE_ENS160_GPR_WRITE6 0x46 |
krishnamvs | 3:63ff52373e71 | 153 | #define SFE_ENS160_GPR_WRITE7 0x47 |
krishnamvs | 3:63ff52373e71 | 154 | |
krishnamvs | 3:63ff52373e71 | 155 | // General Purpose Read registers |
krishnamvs | 3:63ff52373e71 | 156 | #define SFE_ENS160_GPR_READ0 0x48 |
krishnamvs | 3:63ff52373e71 | 157 | #define SFE_ENS160_GPR_READ1 0x49 |
krishnamvs | 3:63ff52373e71 | 158 | #define SFE_ENS160_GPR_READ2 0x4A |
krishnamvs | 3:63ff52373e71 | 159 | #define SFE_ENS160_GPR_READ3 0x4B |
krishnamvs | 3:63ff52373e71 | 160 | #define SFE_ENS160_GPR_READ4 0x4C |
krishnamvs | 3:63ff52373e71 | 161 | #define SFE_ENS160_GPR_READ5 0x4D |
krishnamvs | 3:63ff52373e71 | 162 | #define SFE_ENS160_GPR_READ6 0x4E |
krishnamvs | 3:63ff52373e71 | 163 | #define SFE_ENS160_GPR_READ7 0x4F |