Basic INA219, with set calibaration and functions for reading raw register and write to register
INA219_reg.h@0:cdfbda214bee, 2015-11-20 (annotated)
- Committer:
- tsoic
- Date:
- Fri Nov 20 08:24:43 2015 +0000
- Revision:
- 0:cdfbda214bee
Fork of INA219 library , just basic functions, read raw registar and write registar, calibration is changable only in library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsoic | 0:cdfbda214bee | 1 | #define INA219_ADDR_GG (0x40 << 1) |
tsoic | 0:cdfbda214bee | 2 | #define INA219_ADDR_GV (0x41 << 1) |
tsoic | 0:cdfbda214bee | 3 | #define INA219_ADDR_GA (0x42 << 1) |
tsoic | 0:cdfbda214bee | 4 | #define INA219_ADDR_GL (0x43 << 1) |
tsoic | 0:cdfbda214bee | 5 | #define INA219_ADDR_VG (0x44 << 1) |
tsoic | 0:cdfbda214bee | 6 | #define INA219_ADDR_VV (0x45 << 1) |
tsoic | 0:cdfbda214bee | 7 | #define INA219_ADDR_VA (0x46 << 1) |
tsoic | 0:cdfbda214bee | 8 | #define INA219_ADDR_VL (0x47 << 1) |
tsoic | 0:cdfbda214bee | 9 | #define INA219_ADDR_AG (0x48 << 1) |
tsoic | 0:cdfbda214bee | 10 | #define INA219_ADDR_AV (0x49 << 1) |
tsoic | 0:cdfbda214bee | 11 | #define INA219_ADDR_AA (0x4a << 1) |
tsoic | 0:cdfbda214bee | 12 | #define INA219_ADDR_AL (0x4b << 1) |
tsoic | 0:cdfbda214bee | 13 | #define INA219_ADDR_LG (0x4c << 1) |
tsoic | 0:cdfbda214bee | 14 | #define INA219_ADDR_LV (0x4d << 1) |
tsoic | 0:cdfbda214bee | 15 | #define INA219_ADDR_LA (0x4e << 1) |
tsoic | 0:cdfbda214bee | 16 | #define INA219_ADDR_LL (0x4f << 1) |
tsoic | 0:cdfbda214bee | 17 | |
tsoic | 0:cdfbda214bee | 18 | /////////// REGISTER DEFINITION ///////////////// |
tsoic | 0:cdfbda214bee | 19 | #define INA219_CONFIG 0x00 |
tsoic | 0:cdfbda214bee | 20 | #define INA219_SHUNT_V 0x01 |
tsoic | 0:cdfbda214bee | 21 | #define INA219_BUS_VOLT 0x02 |
tsoic | 0:cdfbda214bee | 22 | #define INA219_POWER 0x03 |
tsoic | 0:cdfbda214bee | 23 | #define INA219_CURRENT 0x04 |
tsoic | 0:cdfbda214bee | 24 | #define INA219_CALBLATION 0x05 |
tsoic | 0:cdfbda214bee | 25 | |
tsoic | 0:cdfbda214bee | 26 | /////////// PARAMETER SETTING /////////////////// |
tsoic | 0:cdfbda214bee | 27 | // Set data into "shunt_register" |
tsoic | 0:cdfbda214bee | 28 | #define INA219_PAR_R_100MOHM 100 |
tsoic | 0:cdfbda214bee | 29 | #define INA219_PAR_R_50MOHM 50 |
tsoic | 0:cdfbda214bee | 30 | #define INA219_PAR_R_20MOHM 20 |
tsoic | 0:cdfbda214bee | 31 | #define INA219_PAR_R_100MOHM 100 |
tsoic | 0:cdfbda214bee | 32 | #define INA219_PAR_R_200MORM 200 |
tsoic | 0:cdfbda214bee | 33 | #define INA219_PAR_R_MORM(x) (x) |
tsoic | 0:cdfbda214bee | 34 | // Set data into "v_max" |
tsoic | 0:cdfbda214bee | 35 | #define INA219_PAR_V_16V 0 |
tsoic | 0:cdfbda214bee | 36 | #define INA219_PAR_V_32V 1 // Default |
tsoic | 0:cdfbda214bee | 37 | // Set data into "gain" |
tsoic | 0:cdfbda214bee | 38 | #define INA219_PAR_G_40MV 0 // 400[mA] max if R=0.1[Ohm] |
tsoic | 0:cdfbda214bee | 39 | #define INA219_PAR_G_80MV 1 |
tsoic | 0:cdfbda214bee | 40 | #define INA219_PAR_G_160MV 2 |
tsoic | 0:cdfbda214bee | 41 | #define INA219_PAR_G_320MV 3 // Default |
tsoic | 0:cdfbda214bee | 42 | // Set data into "bus_adc_resolution" |
tsoic | 0:cdfbda214bee | 43 | #define INA219_PAR_B_9B_X1_84US 0x0 |
tsoic | 0:cdfbda214bee | 44 | #define INA219_PAR_B_10B_X1_148US 0x1 |
tsoic | 0:cdfbda214bee | 45 | #define INA219_PAR_B_11B_X1_276US 0x2 |
tsoic | 0:cdfbda214bee | 46 | #define INA219_PAR_B_12B_X1_532US 0x3 // Default |
tsoic | 0:cdfbda214bee | 47 | #define INA219_PAR_B_12B_X2_1R06MS 0x9 |
tsoic | 0:cdfbda214bee | 48 | #define INA219_PAR_B_12B_X4_2R13MS 0xa |
tsoic | 0:cdfbda214bee | 49 | #define INA219_PAR_B_12B_X8_4R26MS 0xb |
tsoic | 0:cdfbda214bee | 50 | #define INA219_PAR_B_12B_X16_8MS 0xc |
tsoic | 0:cdfbda214bee | 51 | #define INA219_PAR_B_12B_X32_17MS 0xd |
tsoic | 0:cdfbda214bee | 52 | #define INA219_PAR_B_12B_X64_34MS 0xe |
tsoic | 0:cdfbda214bee | 53 | #define INA219_PAR_B_12B_X128_68MS 0xf |
tsoic | 0:cdfbda214bee | 54 | // Set data into "shunt_adc_resolution" |
tsoic | 0:cdfbda214bee | 55 | #define INA219_PAR_S_9B_X1_84US 0x0 |
tsoic | 0:cdfbda214bee | 56 | #define INA219_PAR_S_10B_X1_148US 0x1 |
tsoic | 0:cdfbda214bee | 57 | #define INA219_PAR_S_11B_X1_276US 0x2 |
tsoic | 0:cdfbda214bee | 58 | #define INA219_PAR_S_12B_X1_532US 0x3 // Default |
tsoic | 0:cdfbda214bee | 59 | #define INA219_PAR_S_12B_X2_1R06MS 0x9 |
tsoic | 0:cdfbda214bee | 60 | #define INA219_PAR_S_12B_X4_2R13MS 0xa |
tsoic | 0:cdfbda214bee | 61 | #define INA219_PAR_S_12B_X8_4R26MS 0xb |
tsoic | 0:cdfbda214bee | 62 | #define INA219_PAR_S_12B_X16_8MS 0xc |
tsoic | 0:cdfbda214bee | 63 | #define INA219_PAR_S_12B_X32_17MS 0xd |
tsoic | 0:cdfbda214bee | 64 | #define INA219_PAR_S_12B_X64_34MS 0xe |
tsoic | 0:cdfbda214bee | 65 | #define INA219_PAR_S_12B_X128_68MS 0xf |
tsoic | 0:cdfbda214bee | 66 | // Set data into "mode" |
tsoic | 0:cdfbda214bee | 67 | #define INA219_PAR_M_PDWN 0 |
tsoic | 0:cdfbda214bee | 68 | #define INA219_PAR_M_SHNT_TRG 1 |
tsoic | 0:cdfbda214bee | 69 | #define INA219_PAR_M_BUS_TRG 2 |
tsoic | 0:cdfbda214bee | 70 | #define INA219_PAR_M_SHNTBUS_TRG 3 |
tsoic | 0:cdfbda214bee | 71 | #define INA219_PAR_M_ADC_OFF 4 |
tsoic | 0:cdfbda214bee | 72 | #define INA219_PAR_M_SHNT_CONT 5 |
tsoic | 0:cdfbda214bee | 73 | #define INA219_PAR_M_BUS_CONT 6 |
tsoic | 0:cdfbda214bee | 74 | #define INA219_PAR_M_SHNTBUS_CONT 7 |
tsoic | 0:cdfbda214bee | 75 | |
tsoic | 0:cdfbda214bee | 76 | #define INA219_CFG_RESET (1UL << 15) |
tsoic | 0:cdfbda214bee | 77 | |
tsoic | 0:cdfbda214bee | 78 | #define INA219_CFG_B32V (1UL << 13) |
tsoic | 0:cdfbda214bee | 79 | #define INA219_CFG_B16V (0UL << 13) |
tsoic | 0:cdfbda214bee | 80 | |
tsoic | 0:cdfbda214bee | 81 | #define INA219_CFG_PGA_DIV_1 (0UL << 11) |
tsoic | 0:cdfbda214bee | 82 | #define INA219_CFG_PGA_DIV_2 (1UL << 11) |
tsoic | 0:cdfbda214bee | 83 | #define INA219_CFG_PGA_DIV_4 (2UL << 11) |
tsoic | 0:cdfbda214bee | 84 | #define INA219_CFG_PGA_DIV_8 (3UL << 11) |
tsoic | 0:cdfbda214bee | 85 | |
tsoic | 0:cdfbda214bee | 86 | #define INA219_CFG_BADC (0xf << 7) |
tsoic | 0:cdfbda214bee | 87 | |
tsoic | 0:cdfbda214bee | 88 | #define INA219_CFG_SADC_9B_84U (0x0 << 3) |
tsoic | 0:cdfbda214bee | 89 | #define INA219_CFG_SADC_10B_148U (0x1 << 3) |
tsoic | 0:cdfbda214bee | 90 | #define INA219_CFG_SADC_11B_276U (0x2 << 3) |
tsoic | 0:cdfbda214bee | 91 | #define INA219_CFG_SADC_12B_532U (0x3 << 3) |
tsoic | 0:cdfbda214bee | 92 | #define INA219_CFG_SADC_2S_1R06M (0x9 << 3) |
tsoic | 0:cdfbda214bee | 93 | #define INA219_CFG_SADC_4S_2R13M (0xa << 3) |
tsoic | 0:cdfbda214bee | 94 | #define INA219_CFG_SADC_8S_4R26M (0xb << 3) |
tsoic | 0:cdfbda214bee | 95 | #define INA219_CFG_SADC_16S_8R51M (0xc << 3) |
tsoic | 0:cdfbda214bee | 96 | #define INA219_CFG_SADC_32S_17M (0xd << 3) |
tsoic | 0:cdfbda214bee | 97 | #define INA219_CFG_SADC_64S_34M (0xe << 3) |
tsoic | 0:cdfbda214bee | 98 | #define INA219_CFG_SADC_128S_68M (0xf << 3) |
tsoic | 0:cdfbda214bee | 99 | |
tsoic | 0:cdfbda214bee | 100 | #define INA219_CFG_MODE_PDWN (0UL << 0) |
tsoic | 0:cdfbda214bee | 101 | #define INA219_CFG_MODE_SHNTTRG (1UL << 0) |
tsoic | 0:cdfbda214bee | 102 | #define INA219_CFG_MODE_BUSTRG (2UL << 0) |
tsoic | 0:cdfbda214bee | 103 | #define INA219_CFG_MODE_SBTRG (3UL << 0) |
tsoic | 0:cdfbda214bee | 104 | #define INA219_CFG_MODE_ADC_OFF (4UL << 0) |
tsoic | 0:cdfbda214bee | 105 | #define INA219_CFG_MODE_SHNT_CONT (5UL << 0) |
tsoic | 0:cdfbda214bee | 106 | #define INA219_CFG_MODE_BUS_CONT (6UL << 0) |
tsoic | 0:cdfbda214bee | 107 | #define INA219_CFG_MODE_SB_CONT (7UL << 0) |
tsoic | 0:cdfbda214bee | 108 | |
tsoic | 0:cdfbda214bee | 109 | #define INA219_PAR_M_ADC_OFF 4 |
tsoic | 0:cdfbda214bee | 110 | #define INA219_PAR_M_SHNT_CONT 5 |
tsoic | 0:cdfbda214bee | 111 | #define INA219_PAR_M_BUS_CONT 6 |
tsoic | 0:cdfbda214bee | 112 | #define INA219_PAR_M_SHNTBUS_CONT 7 // Default |