89 lines
1.7 KiB
C
89 lines
1.7 KiB
C
// Îļþ±àÂë: GB18030
|
|
/*
|
|
* ina226.h
|
|
*
|
|
* Created on: 2025Äê10ÔÂ16ÈÕ
|
|
* Author: LHYe200
|
|
*/
|
|
|
|
#ifndef CODE_INA226_H_
|
|
#define CODE_INA226_H_
|
|
|
|
#include "zf_common_typedef.h"
|
|
|
|
#define INA226_NUM 2
|
|
|
|
#define INA226_ALT_PIN {P15_2, P15_3}
|
|
#define INA226_ADDR {0x45, 0x40}
|
|
#define INA226_DEF_MODE {0x44, 0x4F}
|
|
#define INA226_DEF_CAL {0x0D, 0x1B}
|
|
|
|
#define INA226_VOT_FIX_K {0.998996f, 0.998996f}
|
|
#define INA226_AMP_FIX_K {1.158f, 1.137f}
|
|
|
|
|
|
#define INA226_READ_TIME_MS 1
|
|
|
|
|
|
#define INA226_SOFT_WAIT_TIME 0
|
|
|
|
#define INA226_SDA_PIN P15_1
|
|
#define INA226_SCL_PIN P15_0
|
|
|
|
|
|
#define INA226_CONFIG_REG 0x00
|
|
#define INA226_SHUNTVOT_REG 0x01
|
|
#define INA226_BUSVOT_REG 0x02
|
|
#define INA226_POWER_REG 0x03
|
|
#define INA226_CURRENT_REG 0x04
|
|
#define INA226_CALIBRATION_REG 0x05
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint8 addr;
|
|
float max_current_A;
|
|
float rshunt_mOhm;
|
|
float vot_fix_k;
|
|
float amp_fix_k;
|
|
uint8 mode[2];
|
|
} INA226_Config;
|
|
|
|
typedef struct
|
|
{
|
|
float c_lsb_mA;
|
|
uint8 cal[2];
|
|
} INA226_Calibration;
|
|
|
|
typedef struct
|
|
{
|
|
float voltage_V;
|
|
float current_A;
|
|
float power_W;
|
|
float shunt_voltage_mV;
|
|
float energy_J;
|
|
float quantity_C;
|
|
uint8 alert_flag;
|
|
uint8 org_reg[4][2];
|
|
float past_voltage_V[10];
|
|
float past_current_A[10];
|
|
} INA226_Result;
|
|
|
|
typedef struct
|
|
{
|
|
INA226_Config config;
|
|
INA226_Calibration calibration;
|
|
INA226_Result result;
|
|
} INA226_t;
|
|
|
|
extern INA226_t ina226[INA226_NUM];
|
|
|
|
void INA226_Init(void);
|
|
void INA226_Single_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_current_A, float rshunt_mOhm, float amp_fix_k, float vot_fix_k);
|
|
void INA226_Single_Read(INA226_t *ina226);
|
|
void INA226_Read(void);
|
|
|
|
#endif /* CODE_INA226_H_ */
|