47#define MAXIMUM_EXPECTED_CURRENT 5.0
48#define CURRENT_LSB_MINIMUM (MAXIMUM_EXPECTED_CURRENT / ((float)(1<<15)))
49#define CURRENT_LSB (CURRENT_LSB_MINIMUM * 1.0)
50#define BUS_VOLTAGE_LSB 0.0016
51#define SHUNT_VOLTAGE_81_92mv_LSB 0.0025
52#define SHUNT_VOLTAGE_20_48mv_LSB 0.000625
53#define POWER_LSB (CURRENT_LSB*32)
55#define CONFIGURATION_REGISTER 0x00
56#define SHUNT_VOLTAGE_REGISTER 0x01
57#define BUS_VOLTAGE_REGISTER 0x02
58#define POWER_REGISTER 0x03
59#define CURRENT_REGISTER 0x04
60#define CALIBRATION_REGISTER 0x05
61#define MASK_ENABLE_REGISTER 0x06
62#define ALERT_LIMIT_REGISTER 0x07
63#define MANUFACTURERID_REGISTER 0x3E
64#define DEVICEID_REGISTER 0x3F
135 uint16_t
LEN:1,
APOL:1,
OVF:1,
CVRF:1,
AFF:1,
MemError:1,
RESERVED:4,
CNVR:1,
POL:1,
BUL:1,
BOL:1,
SUL:1,
SOL:1;
NumSamples INA236_getNumberOfADCSamples(INA236 *self)
Get the number of ADC samples to calculate the average.
Definition ina236.c:442
Mode INA236_getMode(INA236 *self)
Set the operating mode.
Definition ina236.c:495
ConvTime INA236_getVShuntConversionTime(INA236 *self)
Get the VShunt convertion period.
Definition ina236.c:478
uint16_t INA236_getDevID(INA236 *self)
Get the device ID.
Definition ina236.c:527
INA236_Status INA236_resetAlert(INA236 *self)
Reset the alert pin. This function is useful when set the alert pin to latch mode.
Definition ina236.c:648
ConvTime INA236_getVBusConversionTime(INA236 *self)
Get the VBus convertion period.
Definition ina236.c:460
Mode
Definition ina236.h:69
@ MODE_SHUTDOWN
Definition ina236.h:69
@ MODE_SHUTDOWN2
Definition ina236.h:69
@ MODE_CONTINUOUS_BUS
Definition ina236.h:69
@ MODE_CONTINUOUS_BOTH_SHUNT_BUS
Definition ina236.h:69
@ MODE_SINGLESHOT_BUS
Definition ina236.h:69
@ MODE_SINGLESHOT_SUNT
Definition ina236.h:69
@ MODE_SINGLESHOT_BOTH_SHUNT_BUS
Definition ina236.h:69
@ MODE_CONTINUOUS_SHUNT
Definition ina236.h:69
INA236_Status INA236_setADCRange(INA236 *self, ADCRange adc_range)
Set the ADC full scale range of INA236.
Definition ina236.c:285
ADCRange INA236_getADCRange(INA236 *self)
Get the ADC full scale range of INA236.
Definition ina236.c:424
INA236_Status __INA236_readTwoBytes(INA236 *self, uint8_t MemAddress)
Read two bytes (a 16bit register) from INA236 and stores in the INA236::_reg::raw_data.
Definition ina236.c:236
float INA236_getCurrent(INA236 *self)
Read the current from INA236.
Definition ina236.c:551
INA236_Status INA236_setNumberOfADCSamples(INA236 *self, NumSamples numer_of_adc_samples)
Set the number of ADC samples to calculate the average.
Definition ina236.c:315
INA236_Status INA236_alert_init(INA236 *self, AlertOn alert_on, AlertPolarity alert_polarity, AlertLatch alert_latch, AlertConvReady alert_conv_ready, float alert_limit)
Initialize the alert functionality of INA236 with the given configurations.
Definition ina236.c:176
float INA236_getPower(INA236 *self)
Read the power from INA236.
Definition ina236.c:587
AlertSource INA236_getAlertSource(INA236 *self)
Get the alert source. This function is usefull when you enabled both of the alert functions and data ...
Definition ina236.c:613
float INA236_getBusVoltage(INA236 *self)
Read the bus voltage from INA236.
Definition ina236.c:563
uint16_t INA236_getManID(INA236 *self)
Get the manufacturer ID.
Definition ina236.c:516
AlertOn
Definition ina236.h:71
@ ALERT_BUS_OVER_LIMIT
Definition ina236.h:71
@ ALERT_POWER_OVER_LIMIT
Definition ina236.h:71
@ ALERT_SHUNT_UNDER_LIMIT
Definition ina236.h:71
@ ALERT_BUS_UNDER_LIMIT
Definition ina236.h:71
@ ALERT_NONE
Definition ina236.h:71
@ ALERT_SHUNT_OVER_LIMIT
Definition ina236.h:71
AlertLatch
Definition ina236.h:73
@ ALERT_TRANSPARENT
Definition ina236.h:73
@ ALERT_LATCHED
Definition ina236.h:73
INA236_Status INA236_setMode(INA236 *self, Mode mode)
Set the operating mode.
Definition ina236.c:404
void INA236_readAll(INA236 *self)
Read all of the measured values: Shunt voltage, bus voltage, power, and current. Then store the value...
Definition ina236.c:538
INA236_Status
Definition ina236.h:70
@ INA236_OK
Definition ina236.h:70
@ INA236_TimeOut
Definition ina236.h:70
uint8_t INA236_isDataReady(INA236 *self)
Check if the conversion is done or not. NOTE: This function will reset the alert pin if it was in the...
Definition ina236.c:600
void INA236_SoftResetAll(INA236 *self)
Send a reset command to all of the INA236s on the bus.
Definition ina236.c:504
INA236_Status __INA236_writeTwoBytes(INA236 *self, uint8_t MemAddress)
Write two bytes (a 16bit register) to INA236 from the INA236::_reg::raw_data.
Definition ina236.c:260
ErrorType
Definition ina236.h:76
@ ERROR_OVF
Definition ina236.h:76
@ ERROR_BOTH_MEMORY_OVF
Definition ina236.h:76
@ ERROR_NONE
Definition ina236.h:76
@ ERROR_MEMORY
Definition ina236.h:76
INA236_Status INA236_setVBusConversionTime(INA236 *self, ConvTime vbus_conversion_time)
Set the VBus convertion period.
Definition ina236.c:345
AlertSource
Definition ina236.h:75
@ ALERT_DATA_READY
Definition ina236.h:75
@ ALERT_LIMIT_REACHED
Definition ina236.h:75
ConvTime
Definition ina236.h:68
@ CTIME_8244us
Definition ina236.h:68
@ CTIME_588us
Definition ina236.h:68
@ CTIME_2116us
Definition ina236.h:68
@ CTIME_4156us
Definition ina236.h:68
@ CTIME_1100us
Definition ina236.h:68
@ CTIME_332us
Definition ina236.h:68
@ CTIME_204us
Definition ina236.h:68
@ CTIME_140us
Definition ina236.h:68
INA236_Status INA236_setVShuntConversionTime(INA236 *self, ConvTime vshunt_conversion_time)
Set the VShunt convertion period.
Definition ina236.c:375
float INA236_getShuntVoltage(INA236 *self)
Read the shunt voltage from INA236.
Definition ina236.c:575
AlertPolarity
Definition ina236.h:72
@ ALERT_ACTIVE_LOW
Definition ina236.h:72
@ ALERT_ACTIVE_HIGH
Definition ina236.h:72
ADCRange
Definition ina236.h:66
@ RANGE_20_48mV
Definition ina236.h:66
@ RANGE_81_92mV
Definition ina236.h:66
NumSamples
Definition ina236.h:67
@ NADC_1024
Definition ina236.h:67
@ NADC_16
Definition ina236.h:67
@ NADC_256
Definition ina236.h:67
@ NADC_1
Definition ina236.h:67
@ NADC_128
Definition ina236.h:67
@ NADC_64
Definition ina236.h:67
@ NADC_4
Definition ina236.h:67
@ NADC_512
Definition ina236.h:67
AlertConvReady
Definition ina236.h:74
@ ALERT_CONV_DISABLE
Definition ina236.h:74
@ ALERT_CONV_ENABLE
Definition ina236.h:74
INA236_Status INA236_init(INA236 *self, uint8_t I2C_ADDR, I2C_HandleTypeDef *hi2c, float ShuntResistor, ADCRange adc_range, NumSamples numer_of_adc_samples, ConvTime vbus_conversion_time, ConvTime vshunt_conversion_time, Mode mode)
Initialize the INA236 with the given config.
Definition ina236.c:101
ErrorType INA236_getErrors(INA236 *self)
Get the error flags of INA236. NOTE: This function will reset the alert pin if it was in the latch mo...
Definition ina236.c:628
int16_t LIMIT
Definition ina236.h:139
uint16_t RESERVED
Definition ina236.h:119
uint16_t VBUS
Definition ina236.h:119
uint16_t SHUNT_CAL
Definition ina236.h:131
uint16_t RESERVED
Definition ina236.h:131
uint16_t VBUSCT
Definition ina236.h:111
uint16_t ACDRANGE
Definition ina236.h:111
uint16_t RESERVED
Definition ina236.h:111
uint16_t VSHCT
Definition ina236.h:111
uint16_t MODE
Definition ina236.h:111
uint16_t RST
Definition ina236.h:111
uint16_t AVG
Definition ina236.h:111
int16_t CURRENT
Definition ina236.h:127
uint16_t DIEID
Definition ina236.h:147
uint16_t RESERVED
Definition ina236.h:147
uint16_t MANUFACTURE_ID
Definition ina236.h:143
uint16_t LEN
Definition ina236.h:135
uint16_t BOL
Definition ina236.h:135
uint16_t APOL
Definition ina236.h:135
uint16_t SOL
Definition ina236.h:135
uint16_t AFF
Definition ina236.h:135
uint16_t MemError
Definition ina236.h:135
uint16_t OVF
Definition ina236.h:135
uint16_t RESERVED
Definition ina236.h:135
uint16_t POL
Definition ina236.h:135
uint16_t CNVR
Definition ina236.h:135
uint16_t BUL
Definition ina236.h:135
uint16_t SUL
Definition ina236.h:135
uint16_t CVRF
Definition ina236.h:135
uint16_t POWER
Definition ina236.h:123
int16_t VSHUNT
Definition ina236.h:115
Class (struct) that stores variables for interacting with INA236.
Definition ina236.h:81
Mode mode
Definition ina236.h:91
AlertLatch alert_latch
Definition ina236.h:97
NumSamples number_of_adc_samples
Definition ina236.h:88
float ShuntResistor
Definition ina236.h:92
AlertConvReady alert_conv_ready
Definition ina236.h:98
float BusVoltage
Definition ina236.h:103
ConvTime vshunt_conversion_time
Definition ina236.h:90
AlertOn alert_on
Definition ina236.h:95
AlertPolarity alert_polarity
Definition ina236.h:96
I2C_HandleTypeDef * hi2c
Definition ina236.h:83
ConvTime vbus_conversion_time
Definition ina236.h:89
float ShuntVoltage
Definition ina236.h:102
uint8_t I2C_ADDR
Definition ina236.h:84
float alert_limit
Definition ina236.h:99
int32_t alert_limit_int
Definition ina236.h:100
float Current
Definition ina236.h:105
float Power
Definition ina236.h:104
ADCRange adc_range
Definition ina236.h:87
struct INA236::_reg::_calibration_register calibration_register
struct INA236::_reg::_mask_enable_register mask_enable_register
struct INA236::_reg::_manufacture_id_register manufacture_id_register
uint8_t raw_data[2]
Definition ina236.h:108
struct INA236::_reg::_config_register config_register
struct INA236::_reg::_devide_id_register devide_id_register
struct INA236::_reg::_current_register current_register
struct INA236::_reg::_bus_voltage_register bus_voltage_register
struct INA236::_reg::_power_register power_register
struct INA236::_reg::_alert_limit_register alert_limit_register
struct INA236::_reg::_shunt_voltage_register shunt_voltage_register