![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
text export
Dependencies: X_NUCLEO_IKS01A3
INA237/INA237.h@9:8c7774aca512, 2021-05-19 (annotated)
- Committer:
- gpmbed
- Date:
- Wed May 19 15:54:08 2021 +0000
- Revision:
- 9:8c7774aca512
test export
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gpmbed | 9:8c7774aca512 | 1 | /* |
gpmbed | 9:8c7774aca512 | 2 | * ======== INA237.h ======== |
gpmbed | 9:8c7774aca512 | 3 | * INA237 Interface |
gpmbed | 9:8c7774aca512 | 4 | */ |
gpmbed | 9:8c7774aca512 | 5 | #ifndef ti_sensors_INA237__include |
gpmbed | 9:8c7774aca512 | 6 | #define ti_sensors_INA237__include 1 |
gpmbed | 9:8c7774aca512 | 7 | |
gpmbed | 9:8c7774aca512 | 8 | #include <stdint.h> |
gpmbed | 9:8c7774aca512 | 9 | |
gpmbed | 9:8c7774aca512 | 10 | /* support C++ sources */ |
gpmbed | 9:8c7774aca512 | 11 | #ifdef __cplusplus |
gpmbed | 9:8c7774aca512 | 12 | extern "C" { |
gpmbed | 9:8c7774aca512 | 13 | #endif |
gpmbed | 9:8c7774aca512 | 14 | |
gpmbed | 9:8c7774aca512 | 15 | #define INA237_config_register 0x00U |
gpmbed | 9:8c7774aca512 | 16 | #define INA237_config_register_rst_NormalOperation 0x0000U |
gpmbed | 9:8c7774aca512 | 17 | #define INA237_config_register_rst_SystemReset 0x8000U |
gpmbed | 9:8c7774aca512 | 18 | #define INA237_config_register_reserved0_ENABLE 0x4000U |
gpmbed | 9:8c7774aca512 | 19 | #define INA237_config_register_reserved0_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 20 | #define INA237_config_register_tempcomp_Shunttemperaturecompensationdisabled 0x0000U |
gpmbed | 9:8c7774aca512 | 21 | #define INA237_config_register_tempcomp_Shunttemperaturecompensationenabled 0x0020U |
gpmbed | 9:8c7774aca512 | 22 | #define INA237_config_register_adcrange_16384mV 0x0000U |
gpmbed | 9:8c7774aca512 | 23 | #define INA237_config_register_adcrange_4096mV 0x0010U |
gpmbed | 9:8c7774aca512 | 24 | #define INA237_adc_config_register 0x01U |
gpmbed | 9:8c7774aca512 | 25 | #define INA237_adc_config_register_mode_Shutdown0 0x0000U |
gpmbed | 9:8c7774aca512 | 26 | #define INA237_adc_config_register_mode_Busvoltagetriggeredsingleshot 0x1000U |
gpmbed | 9:8c7774aca512 | 27 | #define INA237_adc_config_register_mode_Shuntvoltagetriggeredsingleshot 0x2000U |
gpmbed | 9:8c7774aca512 | 28 | #define INA237_adc_config_register_mode_Shuntvoltageandbusvoltagetriggeredsingleshot 0x3000U |
gpmbed | 9:8c7774aca512 | 29 | #define INA237_adc_config_register_mode_Temperaturemeasurementtriggeredsingleshot 0x4000U |
gpmbed | 9:8c7774aca512 | 30 | #define INA237_adc_config_register_mode_Temperatureandbusvoltagemeasurementtriggeredsingleshot 0x5000U |
gpmbed | 9:8c7774aca512 | 31 | #define INA237_adc_config_register_mode_Temperatureandshuntvoltagemeasurementtriggeredsingeshot 0x6000U |
gpmbed | 9:8c7774aca512 | 32 | #define INA237_adc_config_register_mode_Busvoltageshuntvoltageandtemperaturemeasurementtriggeredsingleshot 0x7000U |
gpmbed | 9:8c7774aca512 | 33 | #define INA237_adc_config_register_mode_Shutdown1 0x8000U |
gpmbed | 9:8c7774aca512 | 34 | #define INA237_adc_config_register_mode_Continuousbusvoltageonly 0x9000U |
gpmbed | 9:8c7774aca512 | 35 | #define INA237_adc_config_register_mode_Continuousshuntvoltageonly 0xA000U |
gpmbed | 9:8c7774aca512 | 36 | #define INA237_adc_config_register_mode_Continuousshuntandbusvoltage 0xB000U |
gpmbed | 9:8c7774aca512 | 37 | #define INA237_adc_config_register_mode_Continuoustemperatureonly 0xC000U |
gpmbed | 9:8c7774aca512 | 38 | #define INA237_adc_config_register_mode_Continuousbusvoltageandtemperature 0xD000U |
gpmbed | 9:8c7774aca512 | 39 | #define INA237_adc_config_register_mode_Continuoustemperatureandshuntvoltage 0xE000U |
gpmbed | 9:8c7774aca512 | 40 | #define INA237_adc_config_register_mode_Continuousbusvoltageshuntvoltageandtemperature 0xF000U |
gpmbed | 9:8c7774aca512 | 41 | #define INA237_adc_config_register_vbusct_50us 0x0000U |
gpmbed | 9:8c7774aca512 | 42 | #define INA237_adc_config_register_vbusct_84us 0x0200U |
gpmbed | 9:8c7774aca512 | 43 | #define INA237_adc_config_register_vbusct_150us 0x0400U |
gpmbed | 9:8c7774aca512 | 44 | #define INA237_adc_config_register_vbusct_280us 0x0600U |
gpmbed | 9:8c7774aca512 | 45 | #define INA237_adc_config_register_vbusct_540us 0x0800U |
gpmbed | 9:8c7774aca512 | 46 | #define INA237_adc_config_register_vbusct_1052us 0x0A00U |
gpmbed | 9:8c7774aca512 | 47 | #define INA237_adc_config_register_vbusct_2074us 0x0C00U |
gpmbed | 9:8c7774aca512 | 48 | #define INA237_adc_config_register_vbusct_4120us 0x0E00U |
gpmbed | 9:8c7774aca512 | 49 | #define INA237_adc_config_register_vshct_50us 0x0000U |
gpmbed | 9:8c7774aca512 | 50 | #define INA237_adc_config_register_vshct_84us 0x0040U |
gpmbed | 9:8c7774aca512 | 51 | #define INA237_adc_config_register_vshct_150us 0x0080U |
gpmbed | 9:8c7774aca512 | 52 | #define INA237_adc_config_register_vshct_280us 0x00C0U |
gpmbed | 9:8c7774aca512 | 53 | #define INA237_adc_config_register_vshct_540us 0x0100U |
gpmbed | 9:8c7774aca512 | 54 | #define INA237_adc_config_register_vshct_1052us 0x0140U |
gpmbed | 9:8c7774aca512 | 55 | #define INA237_adc_config_register_vshct_2074us 0x0180U |
gpmbed | 9:8c7774aca512 | 56 | #define INA237_adc_config_register_vshct_4120us 0x01C0U |
gpmbed | 9:8c7774aca512 | 57 | #define INA237_adc_config_register_vtct_50us 0x0000U |
gpmbed | 9:8c7774aca512 | 58 | #define INA237_adc_config_register_vtct_84us 0x0008U |
gpmbed | 9:8c7774aca512 | 59 | #define INA237_adc_config_register_vtct_150us 0x0010U |
gpmbed | 9:8c7774aca512 | 60 | #define INA237_adc_config_register_vtct_280us 0x0018U |
gpmbed | 9:8c7774aca512 | 61 | #define INA237_adc_config_register_vtct_540us 0x0020U |
gpmbed | 9:8c7774aca512 | 62 | #define INA237_adc_config_register_vtct_1052us 0x0028U |
gpmbed | 9:8c7774aca512 | 63 | #define INA237_adc_config_register_vtct_2074us 0x0030U |
gpmbed | 9:8c7774aca512 | 64 | #define INA237_adc_config_register_vtct_4120us 0x0038U |
gpmbed | 9:8c7774aca512 | 65 | #define INA237_adc_config_register_avg_1 0x0000U |
gpmbed | 9:8c7774aca512 | 66 | #define INA237_adc_config_register_avg_4 0x0001U |
gpmbed | 9:8c7774aca512 | 67 | #define INA237_adc_config_register_avg_16 0x0002U |
gpmbed | 9:8c7774aca512 | 68 | #define INA237_adc_config_register_avg_64 0x0003U |
gpmbed | 9:8c7774aca512 | 69 | #define INA237_adc_config_register_avg_128 0x0004U |
gpmbed | 9:8c7774aca512 | 70 | #define INA237_adc_config_register_avg_256 0x0005U |
gpmbed | 9:8c7774aca512 | 71 | #define INA237_adc_config_register_avg_512 0x0006U |
gpmbed | 9:8c7774aca512 | 72 | #define INA237_adc_config_register_avg_1024 0x0007U |
gpmbed | 9:8c7774aca512 | 73 | #define INA237_shunt_cal_register 0x02U |
gpmbed | 9:8c7774aca512 | 74 | #define INA237_shunt_cal_register_reserved0_ENABLE 0x8000U |
gpmbed | 9:8c7774aca512 | 75 | #define INA237_shunt_cal_register_reserved0_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 76 | #define INA237_vshunt_register 0x04U |
gpmbed | 9:8c7774aca512 | 77 | #define INA237_vbus_register 0x05U |
gpmbed | 9:8c7774aca512 | 78 | #define INA237_dietemp_register 0x06U |
gpmbed | 9:8c7774aca512 | 79 | #define INA237_current_register 0x07U |
gpmbed | 9:8c7774aca512 | 80 | #define INA237_power_register 0x08U |
gpmbed | 9:8c7774aca512 | 81 | #define INA237_diag_alrt_register 0x0BU |
gpmbed | 9:8c7774aca512 | 82 | #define INA237_diag_alrt_register_alrlen_Transparent 0x0000U |
gpmbed | 9:8c7774aca512 | 83 | #define INA237_diag_alrt_register_alrlen_LatchedAlertpin 0x8000U |
gpmbed | 9:8c7774aca512 | 84 | #define INA237_diag_alrt_register_cnvr_DisableconversionreadyflagonALERTpin 0x0000U |
gpmbed | 9:8c7774aca512 | 85 | #define INA237_diag_alrt_register_cnvr_EnablesconversionreadyflagonALERTpin 0x4000U |
gpmbed | 9:8c7774aca512 | 86 | #define INA237_diag_alrt_register_slwalrt_ALERTcomparisononnonaveragedADCvalue 0x0000U |
gpmbed | 9:8c7774aca512 | 87 | #define INA237_diag_alrt_register_slwalrt_ALERTcomparisononaveragedvalue 0x2000U |
gpmbed | 9:8c7774aca512 | 88 | #define INA237_diag_alrt_register_apol_Normalactivelowopendrain 0x0000U |
gpmbed | 9:8c7774aca512 | 89 | #define INA237_diag_alrt_register_apol_Invertedactivehighopendrain 0x1000U |
gpmbed | 9:8c7774aca512 | 90 | #define INA237_diag_alrt_register_enrgof_ENABLE 0x0800U |
gpmbed | 9:8c7774aca512 | 91 | #define INA237_diag_alrt_register_enrgof_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 92 | #define INA237_diag_alrt_register_chrof_ENABLE 0x0400U |
gpmbed | 9:8c7774aca512 | 93 | #define INA237_diag_alrt_register_chrof_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 94 | #define INA237_diag_alrt_register_movf_ENABLE 0x0200U |
gpmbed | 9:8c7774aca512 | 95 | #define INA237_diag_alrt_register_movf_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 96 | #define INA237_diag_alrt_register_reserved0_ENABLE 0x0100U |
gpmbed | 9:8c7774aca512 | 97 | #define INA237_diag_alrt_register_reserved0_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 98 | #define INA237_diag_alrt_register_tmpol_ENABLE 0x0080U |
gpmbed | 9:8c7774aca512 | 99 | #define INA237_diag_alrt_register_tmpol_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 100 | #define INA237_diag_alrt_register_shntol_ENABLE 0x0040U |
gpmbed | 9:8c7774aca512 | 101 | #define INA237_diag_alrt_register_shntol_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 102 | #define INA237_diag_alrt_register_shntul_ENABLE 0x0020U |
gpmbed | 9:8c7774aca512 | 103 | #define INA237_diag_alrt_register_shntul_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 104 | #define INA237_diag_alrt_register_busol_ENABLE 0x0010U |
gpmbed | 9:8c7774aca512 | 105 | #define INA237_diag_alrt_register_busol_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 106 | #define INA237_diag_alrt_register_busul_ENABLE 0x0008U |
gpmbed | 9:8c7774aca512 | 107 | #define INA237_diag_alrt_register_busul_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 108 | #define INA237_diag_alrt_register_pol_ENABLE 0x0004U |
gpmbed | 9:8c7774aca512 | 109 | #define INA237_diag_alrt_register_pol_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 110 | #define INA237_diag_alrt_register_chvrf_ENABLE 0x0002U |
gpmbed | 9:8c7774aca512 | 111 | #define INA237_diag_alrt_register_chvrf_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 112 | #define INA237_diag_alrt_register_memstat_ENABLE 0x0001U |
gpmbed | 9:8c7774aca512 | 113 | #define INA237_diag_alrt_register_memstat_DISABLE 0x0000U |
gpmbed | 9:8c7774aca512 | 114 | #define INA237_sovl_register 0x0CU |
gpmbed | 9:8c7774aca512 | 115 | #define INA237_suvl_register 0x0DU |
gpmbed | 9:8c7774aca512 | 116 | #define INA237_bovl_register 0x0EU |
gpmbed | 9:8c7774aca512 | 117 | #define INA237_buvl_register 0x0FU |
gpmbed | 9:8c7774aca512 | 118 | #define INA237_temp_limit_register 0x10U |
gpmbed | 9:8c7774aca512 | 119 | #define INA237_pwr_limit_register 0x11U |
gpmbed | 9:8c7774aca512 | 120 | #define INA237_manufacture_id_register 0x3EU |
gpmbed | 9:8c7774aca512 | 121 | |
gpmbed | 9:8c7774aca512 | 122 | |
gpmbed | 9:8c7774aca512 | 123 | /* |
gpmbed | 9:8c7774aca512 | 124 | * ======== INA237_State ======== |
gpmbed | 9:8c7774aca512 | 125 | * Initial configuration state for a INA237 sensor |
gpmbed | 9:8c7774aca512 | 126 | */ |
gpmbed | 9:8c7774aca512 | 127 | typedef struct INA237_State { |
gpmbed | 9:8c7774aca512 | 128 | uint16_t config; //config_register |
gpmbed | 9:8c7774aca512 | 129 | uint16_t adcconfig; //adc_config_register |
gpmbed | 9:8c7774aca512 | 130 | uint16_t shuntcal; //shunt_cal_register |
gpmbed | 9:8c7774aca512 | 131 | uint16_t diagalrt; //diag_alrt_register |
gpmbed | 9:8c7774aca512 | 132 | uint16_t sovl; //sovl_register |
gpmbed | 9:8c7774aca512 | 133 | uint16_t suvl; //suvl_registerx |
gpmbed | 9:8c7774aca512 | 134 | uint16_t bovl; //bovl_register |
gpmbed | 9:8c7774aca512 | 135 | uint16_t buvl; //buvl_register |
gpmbed | 9:8c7774aca512 | 136 | uint16_t templimit; //temp_limit_register |
gpmbed | 9:8c7774aca512 | 137 | uint16_t pwrlimit; //pwr_limit_register |
gpmbed | 9:8c7774aca512 | 138 | |
gpmbed | 9:8c7774aca512 | 139 | uint16_t adcrange; //config_register_adcrange |
gpmbed | 9:8c7774aca512 | 140 | float currentlsb; //current lsb value |
gpmbed | 9:8c7774aca512 | 141 | |
gpmbed | 9:8c7774aca512 | 142 | uint8_t busId; /* I2C bus id */ |
gpmbed | 9:8c7774aca512 | 143 | uint8_t devAddr; /* Sensor's I2C address on the bus */ |
gpmbed | 9:8c7774aca512 | 144 | |
gpmbed | 9:8c7774aca512 | 145 | uint16_t osWait; /* One shot conversion time (in ms) */ |
gpmbed | 9:8c7774aca512 | 146 | } INA237_State; |
gpmbed | 9:8c7774aca512 | 147 | |
gpmbed | 9:8c7774aca512 | 148 | /* |
gpmbed | 9:8c7774aca512 | 149 | * ======== INA237_Handle ======== |
gpmbed | 9:8c7774aca512 | 150 | * First argument to all INA237 methods |
gpmbed | 9:8c7774aca512 | 151 | */ |
gpmbed | 9:8c7774aca512 | 152 | typedef INA237_State *INA237_Handle; |
gpmbed | 9:8c7774aca512 | 153 | |
gpmbed | 9:8c7774aca512 | 154 | /* |
gpmbed | 9:8c7774aca512 | 155 | * ======== INA237_writeReg ======== |
gpmbed | 9:8c7774aca512 | 156 | * Write register |
gpmbed | 9:8c7774aca512 | 157 | */ |
gpmbed | 9:8c7774aca512 | 158 | extern void INA237_writeReg(INA237_Handle sensor, uint8_t regAddr, uint16_t value); |
gpmbed | 9:8c7774aca512 | 159 | |
gpmbed | 9:8c7774aca512 | 160 | /* |
gpmbed | 9:8c7774aca512 | 161 | * ======== INA237_config ======== |
gpmbed | 9:8c7774aca512 | 162 | * Configure device with current settings |
gpmbed | 9:8c7774aca512 | 163 | */ |
gpmbed | 9:8c7774aca512 | 164 | extern void INA237_config(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 165 | |
gpmbed | 9:8c7774aca512 | 166 | /* |
gpmbed | 9:8c7774aca512 | 167 | * ======== INA237_setCURRENT_LSB ======== |
gpmbed | 9:8c7774aca512 | 168 | * Set the CURRENT_LSB value used for calculations |
gpmbed | 9:8c7774aca512 | 169 | */ |
gpmbed | 9:8c7774aca512 | 170 | extern void INA237_setCURRENT_LSB(INA237_Handle sensor, float CURRENT_LSB); |
gpmbed | 9:8c7774aca512 | 171 | |
gpmbed | 9:8c7774aca512 | 172 | /* |
gpmbed | 9:8c7774aca512 | 173 | * ======== INA237_readReg ======== |
gpmbed | 9:8c7774aca512 | 174 | * Read register |
gpmbed | 9:8c7774aca512 | 175 | */ |
gpmbed | 9:8c7774aca512 | 176 | extern uint64_t INA237_readReg(INA237_Handle sensor, uint8_t regAddr); |
gpmbed | 9:8c7774aca512 | 177 | |
gpmbed | 9:8c7774aca512 | 178 | /* |
gpmbed | 9:8c7774aca512 | 179 | * ======== INA237_getVSHUNT_mV ======== |
gpmbed | 9:8c7774aca512 | 180 | * Get VSHUNT value (mV) |
gpmbed | 9:8c7774aca512 | 181 | */ |
gpmbed | 9:8c7774aca512 | 182 | extern float INA237_getVSHUNT_mV(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 183 | |
gpmbed | 9:8c7774aca512 | 184 | /* |
gpmbed | 9:8c7774aca512 | 185 | * ======== INA237_getVBUS_V ======== |
gpmbed | 9:8c7774aca512 | 186 | * Get VBUS value (V) |
gpmbed | 9:8c7774aca512 | 187 | */ |
gpmbed | 9:8c7774aca512 | 188 | extern float INA237_getVBUS_V(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 189 | |
gpmbed | 9:8c7774aca512 | 190 | /* |
gpmbed | 9:8c7774aca512 | 191 | * ======== INA237_getDIETEMP_C ======== |
gpmbed | 9:8c7774aca512 | 192 | * Get DIETMEP value (C) |
gpmbed | 9:8c7774aca512 | 193 | */ |
gpmbed | 9:8c7774aca512 | 194 | extern float INA237_getDIETEMP_C(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 195 | |
gpmbed | 9:8c7774aca512 | 196 | /* |
gpmbed | 9:8c7774aca512 | 197 | * ======== INA237_getDIETEMP_F ======== |
gpmbed | 9:8c7774aca512 | 198 | * Get DIETMEP value (F) |
gpmbed | 9:8c7774aca512 | 199 | */ |
gpmbed | 9:8c7774aca512 | 200 | extern float INA237_getDIETEMP_F(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 201 | |
gpmbed | 9:8c7774aca512 | 202 | /* |
gpmbed | 9:8c7774aca512 | 203 | * ======== INA237_getCURRENT_signedLSB ======== |
gpmbed | 9:8c7774aca512 | 204 | * Get CURRENT value (signed value in LSBs) |
gpmbed | 9:8c7774aca512 | 205 | */ |
gpmbed | 9:8c7774aca512 | 206 | extern float INA237_getCURRENT_signedLSB(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 207 | |
gpmbed | 9:8c7774aca512 | 208 | /* |
gpmbed | 9:8c7774aca512 | 209 | * ======== INA237_getCURRENT_A ======== |
gpmbed | 9:8c7774aca512 | 210 | * Get CURRENT value (A) |
gpmbed | 9:8c7774aca512 | 211 | */ |
gpmbed | 9:8c7774aca512 | 212 | extern float INA237_getCURRENT_A(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 213 | |
gpmbed | 9:8c7774aca512 | 214 | /* |
gpmbed | 9:8c7774aca512 | 215 | * ======== INA237_getPOWER_signedLSB ======== |
gpmbed | 9:8c7774aca512 | 216 | * Get POWER value (signed value in LSBs) |
gpmbed | 9:8c7774aca512 | 217 | */ |
gpmbed | 9:8c7774aca512 | 218 | extern float INA237_getPOWER_signedLSB(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 219 | |
gpmbed | 9:8c7774aca512 | 220 | /* |
gpmbed | 9:8c7774aca512 | 221 | * ======== INA237_getPOWER_W ======== |
gpmbed | 9:8c7774aca512 | 222 | * Get POWER value (W) |
gpmbed | 9:8c7774aca512 | 223 | */ |
gpmbed | 9:8c7774aca512 | 224 | extern float INA237_getPOWER_W(INA237_Handle sensor); |
gpmbed | 9:8c7774aca512 | 225 | |
gpmbed | 9:8c7774aca512 | 226 | /* support C++ sources */ |
gpmbed | 9:8c7774aca512 | 227 | #ifdef __cplusplus |
gpmbed | 9:8c7774aca512 | 228 | } |
gpmbed | 9:8c7774aca512 | 229 | #endif |
gpmbed | 9:8c7774aca512 | 230 | |
gpmbed | 9:8c7774aca512 | 231 | #endif |