nrf_ina226.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _NRF_INA226_H
  2. #define _NRF_INA226_H
  3. #include "define.h"
  4. #include "nrf_drv_gpiote.h"
  5. #define CFG_REG 0x00 //
  6. #define SV_REG 0x01 //分流电压, 此处分流电阻为 0.1欧
  7. #define BV_REG 0x02 //总线电压
  8. #define PWR_REG 0x03 //电源功率
  9. #define CUR_REG 0x04 //电流
  10. #define CAL_REG 0x05 //校准,设定满量程范围以及电流和功率测数的
  11. #define ONFF_REG 0x06 //屏蔽 使能 警报配置和转换准备就绪
  12. #define AL_REG 0x07 //包含与所选警报功能相比较的限定值
  13. #define INA226_GET_ADDR 0xFF //包含唯一的芯片标识号
  14. //#define INA226_ADDR1 0x80
  15. #define INA226_RST 0xC000 //reset
  16. typedef void (*ina226_work_finish_func)(void);
  17. typedef enum
  18. {
  19. INA226_QUEUE_TIME=0,
  20. INA226_QUEUE_INT=1,
  21. }INA226_QUEUE_TYPE;
  22. typedef enum
  23. {
  24. INA226_AVG_1=0x00,
  25. INA226_AVG_4=0x01,
  26. INA226_AVG_16=0x02,
  27. INA226_AVG_64=0x03,
  28. INA226_AVG_128=0x04,
  29. INA226_AVG_256=0x05,
  30. INA226_AVG_512=0x06,
  31. INA226_AVG_1024=0x07,
  32. }ina226_averaging_mode_e;
  33. typedef enum
  34. {
  35. INA226_CONVERSION_140US=0x00,
  36. INA226_CONVERSION_204US=0x01,
  37. INA226_CONVERSION_332US=0x02,
  38. INA226_CONVERSION_588US=0x03,
  39. INA226_CONVERSION_1100US=0x04,
  40. INA226_CONVERSION_2116US=0x05,
  41. INA226_CONVERSION_4156US=0x06,
  42. INA226_CONVERSION_8244US=0x07,
  43. }ina226_conversion_time_e;
  44. typedef enum
  45. {
  46. INA226_OPERATION_SHUTDOWN=0x04,
  47. INA226_OPERATION_SHUNT_TRIG=0x05,
  48. INA226_OPERATION_BUS_TRIG=0x06,
  49. INA226_OPERATION_SHUNT_BUS_TRIG=0x07,
  50. }ina226_operating_mode_s;
  51. typedef struct
  52. {
  53. uint8_t idx; //下标
  54. uint8_t ina226_addr; //i2c地址
  55. ina226_averaging_mode_e avg_mode; //采样平均次数
  56. ina226_conversion_time_e bus_conversion_time; //单次总线电压采样间隔
  57. ina226_conversion_time_e shunt_conversion_time; //单次分流电压采样间隔
  58. ina226_operating_mode_s operation_mode; //工作模式
  59. double current_lsb; //电流分辨率
  60. double shunt_res; //分流电阻阻值
  61. float voltageVal; //mV
  62. float Shunt_voltage; //uV
  63. float Shunt_Current; //mA
  64. float powerVal;
  65. }ina226_struct;
  66. void ina226_timers_init(void);
  67. void ina226_alert_init(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_handler_t evt_handler);
  68. void Set_Ina226_Queue(INA226_QUEUE_TYPE type);
  69. void INA226_Init_Idx(ina226_struct *ina226);
  70. void INA226_Init(ina226_struct *ina226);
  71. void INA226_Uinit(ina226_struct *ina226);
  72. void ina226_set_work_finish_func(ina226_work_finish_func func);
  73. void ina226_start(void);
  74. void ina226_stop(void);
  75. #endif //_NRF_INA226_H