text export
Dependencies: X_NUCLEO_IKS01A3
INA237.h
00001 /* 00002 * ======== INA237.h ======== 00003 * INA237 Interface 00004 */ 00005 #ifndef ti_sensors_INA237__include 00006 #define ti_sensors_INA237__include 1 00007 00008 #include <stdint.h> 00009 00010 /* support C++ sources */ 00011 #ifdef __cplusplus 00012 extern "C" { 00013 #endif 00014 00015 #define INA237_config_register 0x00U 00016 #define INA237_config_register_rst_NormalOperation 0x0000U 00017 #define INA237_config_register_rst_SystemReset 0x8000U 00018 #define INA237_config_register_reserved0_ENABLE 0x4000U 00019 #define INA237_config_register_reserved0_DISABLE 0x0000U 00020 #define INA237_config_register_tempcomp_Shunttemperaturecompensationdisabled 0x0000U 00021 #define INA237_config_register_tempcomp_Shunttemperaturecompensationenabled 0x0020U 00022 #define INA237_config_register_adcrange_16384mV 0x0000U 00023 #define INA237_config_register_adcrange_4096mV 0x0010U 00024 #define INA237_adc_config_register 0x01U 00025 #define INA237_adc_config_register_mode_Shutdown0 0x0000U 00026 #define INA237_adc_config_register_mode_Busvoltagetriggeredsingleshot 0x1000U 00027 #define INA237_adc_config_register_mode_Shuntvoltagetriggeredsingleshot 0x2000U 00028 #define INA237_adc_config_register_mode_Shuntvoltageandbusvoltagetriggeredsingleshot 0x3000U 00029 #define INA237_adc_config_register_mode_Temperaturemeasurementtriggeredsingleshot 0x4000U 00030 #define INA237_adc_config_register_mode_Temperatureandbusvoltagemeasurementtriggeredsingleshot 0x5000U 00031 #define INA237_adc_config_register_mode_Temperatureandshuntvoltagemeasurementtriggeredsingeshot 0x6000U 00032 #define INA237_adc_config_register_mode_Busvoltageshuntvoltageandtemperaturemeasurementtriggeredsingleshot 0x7000U 00033 #define INA237_adc_config_register_mode_Shutdown1 0x8000U 00034 #define INA237_adc_config_register_mode_Continuousbusvoltageonly 0x9000U 00035 #define INA237_adc_config_register_mode_Continuousshuntvoltageonly 0xA000U 00036 #define INA237_adc_config_register_mode_Continuousshuntandbusvoltage 0xB000U 00037 #define INA237_adc_config_register_mode_Continuoustemperatureonly 0xC000U 00038 #define INA237_adc_config_register_mode_Continuousbusvoltageandtemperature 0xD000U 00039 #define INA237_adc_config_register_mode_Continuoustemperatureandshuntvoltage 0xE000U 00040 #define INA237_adc_config_register_mode_Continuousbusvoltageshuntvoltageandtemperature 0xF000U 00041 #define INA237_adc_config_register_vbusct_50us 0x0000U 00042 #define INA237_adc_config_register_vbusct_84us 0x0200U 00043 #define INA237_adc_config_register_vbusct_150us 0x0400U 00044 #define INA237_adc_config_register_vbusct_280us 0x0600U 00045 #define INA237_adc_config_register_vbusct_540us 0x0800U 00046 #define INA237_adc_config_register_vbusct_1052us 0x0A00U 00047 #define INA237_adc_config_register_vbusct_2074us 0x0C00U 00048 #define INA237_adc_config_register_vbusct_4120us 0x0E00U 00049 #define INA237_adc_config_register_vshct_50us 0x0000U 00050 #define INA237_adc_config_register_vshct_84us 0x0040U 00051 #define INA237_adc_config_register_vshct_150us 0x0080U 00052 #define INA237_adc_config_register_vshct_280us 0x00C0U 00053 #define INA237_adc_config_register_vshct_540us 0x0100U 00054 #define INA237_adc_config_register_vshct_1052us 0x0140U 00055 #define INA237_adc_config_register_vshct_2074us 0x0180U 00056 #define INA237_adc_config_register_vshct_4120us 0x01C0U 00057 #define INA237_adc_config_register_vtct_50us 0x0000U 00058 #define INA237_adc_config_register_vtct_84us 0x0008U 00059 #define INA237_adc_config_register_vtct_150us 0x0010U 00060 #define INA237_adc_config_register_vtct_280us 0x0018U 00061 #define INA237_adc_config_register_vtct_540us 0x0020U 00062 #define INA237_adc_config_register_vtct_1052us 0x0028U 00063 #define INA237_adc_config_register_vtct_2074us 0x0030U 00064 #define INA237_adc_config_register_vtct_4120us 0x0038U 00065 #define INA237_adc_config_register_avg_1 0x0000U 00066 #define INA237_adc_config_register_avg_4 0x0001U 00067 #define INA237_adc_config_register_avg_16 0x0002U 00068 #define INA237_adc_config_register_avg_64 0x0003U 00069 #define INA237_adc_config_register_avg_128 0x0004U 00070 #define INA237_adc_config_register_avg_256 0x0005U 00071 #define INA237_adc_config_register_avg_512 0x0006U 00072 #define INA237_adc_config_register_avg_1024 0x0007U 00073 #define INA237_shunt_cal_register 0x02U 00074 #define INA237_shunt_cal_register_reserved0_ENABLE 0x8000U 00075 #define INA237_shunt_cal_register_reserved0_DISABLE 0x0000U 00076 #define INA237_vshunt_register 0x04U 00077 #define INA237_vbus_register 0x05U 00078 #define INA237_dietemp_register 0x06U 00079 #define INA237_current_register 0x07U 00080 #define INA237_power_register 0x08U 00081 #define INA237_diag_alrt_register 0x0BU 00082 #define INA237_diag_alrt_register_alrlen_Transparent 0x0000U 00083 #define INA237_diag_alrt_register_alrlen_LatchedAlertpin 0x8000U 00084 #define INA237_diag_alrt_register_cnvr_DisableconversionreadyflagonALERTpin 0x0000U 00085 #define INA237_diag_alrt_register_cnvr_EnablesconversionreadyflagonALERTpin 0x4000U 00086 #define INA237_diag_alrt_register_slwalrt_ALERTcomparisononnonaveragedADCvalue 0x0000U 00087 #define INA237_diag_alrt_register_slwalrt_ALERTcomparisononaveragedvalue 0x2000U 00088 #define INA237_diag_alrt_register_apol_Normalactivelowopendrain 0x0000U 00089 #define INA237_diag_alrt_register_apol_Invertedactivehighopendrain 0x1000U 00090 #define INA237_diag_alrt_register_enrgof_ENABLE 0x0800U 00091 #define INA237_diag_alrt_register_enrgof_DISABLE 0x0000U 00092 #define INA237_diag_alrt_register_chrof_ENABLE 0x0400U 00093 #define INA237_diag_alrt_register_chrof_DISABLE 0x0000U 00094 #define INA237_diag_alrt_register_movf_ENABLE 0x0200U 00095 #define INA237_diag_alrt_register_movf_DISABLE 0x0000U 00096 #define INA237_diag_alrt_register_reserved0_ENABLE 0x0100U 00097 #define INA237_diag_alrt_register_reserved0_DISABLE 0x0000U 00098 #define INA237_diag_alrt_register_tmpol_ENABLE 0x0080U 00099 #define INA237_diag_alrt_register_tmpol_DISABLE 0x0000U 00100 #define INA237_diag_alrt_register_shntol_ENABLE 0x0040U 00101 #define INA237_diag_alrt_register_shntol_DISABLE 0x0000U 00102 #define INA237_diag_alrt_register_shntul_ENABLE 0x0020U 00103 #define INA237_diag_alrt_register_shntul_DISABLE 0x0000U 00104 #define INA237_diag_alrt_register_busol_ENABLE 0x0010U 00105 #define INA237_diag_alrt_register_busol_DISABLE 0x0000U 00106 #define INA237_diag_alrt_register_busul_ENABLE 0x0008U 00107 #define INA237_diag_alrt_register_busul_DISABLE 0x0000U 00108 #define INA237_diag_alrt_register_pol_ENABLE 0x0004U 00109 #define INA237_diag_alrt_register_pol_DISABLE 0x0000U 00110 #define INA237_diag_alrt_register_chvrf_ENABLE 0x0002U 00111 #define INA237_diag_alrt_register_chvrf_DISABLE 0x0000U 00112 #define INA237_diag_alrt_register_memstat_ENABLE 0x0001U 00113 #define INA237_diag_alrt_register_memstat_DISABLE 0x0000U 00114 #define INA237_sovl_register 0x0CU 00115 #define INA237_suvl_register 0x0DU 00116 #define INA237_bovl_register 0x0EU 00117 #define INA237_buvl_register 0x0FU 00118 #define INA237_temp_limit_register 0x10U 00119 #define INA237_pwr_limit_register 0x11U 00120 #define INA237_manufacture_id_register 0x3EU 00121 00122 00123 /* 00124 * ======== INA237_State ======== 00125 * Initial configuration state for a INA237 sensor 00126 */ 00127 typedef struct INA237_State { 00128 uint16_t config; //config_register 00129 uint16_t adcconfig; //adc_config_register 00130 uint16_t shuntcal; //shunt_cal_register 00131 uint16_t diagalrt; //diag_alrt_register 00132 uint16_t sovl; //sovl_register 00133 uint16_t suvl; //suvl_registerx 00134 uint16_t bovl; //bovl_register 00135 uint16_t buvl; //buvl_register 00136 uint16_t templimit; //temp_limit_register 00137 uint16_t pwrlimit; //pwr_limit_register 00138 00139 uint16_t adcrange; //config_register_adcrange 00140 float currentlsb; //current lsb value 00141 00142 uint8_t busId; /* I2C bus id */ 00143 uint8_t devAddr; /* Sensor's I2C address on the bus */ 00144 00145 uint16_t osWait; /* One shot conversion time (in ms) */ 00146 } INA237_State; 00147 00148 /* 00149 * ======== INA237_Handle ======== 00150 * First argument to all INA237 methods 00151 */ 00152 typedef INA237_State *INA237_Handle; 00153 00154 /* 00155 * ======== INA237_writeReg ======== 00156 * Write register 00157 */ 00158 extern void INA237_writeReg(INA237_Handle sensor, uint8_t regAddr, uint16_t value); 00159 00160 /* 00161 * ======== INA237_config ======== 00162 * Configure device with current settings 00163 */ 00164 extern void INA237_config(INA237_Handle sensor); 00165 00166 /* 00167 * ======== INA237_setCURRENT_LSB ======== 00168 * Set the CURRENT_LSB value used for calculations 00169 */ 00170 extern void INA237_setCURRENT_LSB(INA237_Handle sensor, float CURRENT_LSB); 00171 00172 /* 00173 * ======== INA237_readReg ======== 00174 * Read register 00175 */ 00176 extern uint64_t INA237_readReg(INA237_Handle sensor, uint8_t regAddr); 00177 00178 /* 00179 * ======== INA237_getVSHUNT_mV ======== 00180 * Get VSHUNT value (mV) 00181 */ 00182 extern float INA237_getVSHUNT_mV(INA237_Handle sensor); 00183 00184 /* 00185 * ======== INA237_getVBUS_V ======== 00186 * Get VBUS value (V) 00187 */ 00188 extern float INA237_getVBUS_V(INA237_Handle sensor); 00189 00190 /* 00191 * ======== INA237_getDIETEMP_C ======== 00192 * Get DIETMEP value (C) 00193 */ 00194 extern float INA237_getDIETEMP_C(INA237_Handle sensor); 00195 00196 /* 00197 * ======== INA237_getDIETEMP_F ======== 00198 * Get DIETMEP value (F) 00199 */ 00200 extern float INA237_getDIETEMP_F(INA237_Handle sensor); 00201 00202 /* 00203 * ======== INA237_getCURRENT_signedLSB ======== 00204 * Get CURRENT value (signed value in LSBs) 00205 */ 00206 extern float INA237_getCURRENT_signedLSB(INA237_Handle sensor); 00207 00208 /* 00209 * ======== INA237_getCURRENT_A ======== 00210 * Get CURRENT value (A) 00211 */ 00212 extern float INA237_getCURRENT_A(INA237_Handle sensor); 00213 00214 /* 00215 * ======== INA237_getPOWER_signedLSB ======== 00216 * Get POWER value (signed value in LSBs) 00217 */ 00218 extern float INA237_getPOWER_signedLSB(INA237_Handle sensor); 00219 00220 /* 00221 * ======== INA237_getPOWER_W ======== 00222 * Get POWER value (W) 00223 */ 00224 extern float INA237_getPOWER_W(INA237_Handle sensor); 00225 00226 /* support C++ sources */ 00227 #ifdef __cplusplus 00228 } 00229 #endif 00230 00231 #endif
Generated on Fri Jul 15 2022 07:01:47 by
1.7.2