Texas Instruments INA230 hi/lo side, bi-directional current and voltage monitor with I2C. Code hacked and enhanced from the INA219 driver from TI

Fork of INA219 by Kenji Arai

Committer:
kenjiArai
Date:
Sun Mar 15 11:07:54 2015 +0000
Revision:
0:a3b41ab8433b
Child:
1:fea983b0385b
INA219 High-Side Measurement,Bi-Directional CURRENT/POWER MONITOR by T.I.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:a3b41ab8433b 1 /*
kenjiArai 0:a3b41ab8433b 2 * mbed library program
kenjiArai 0:a3b41ab8433b 3 * High-Side Measurement,Bi-Directional CURRENT/POWER MONITOR with I2C Interface
kenjiArai 0:a3b41ab8433b 4 * by Texas Instruments
kenjiArai 0:a3b41ab8433b 5 *
kenjiArai 0:a3b41ab8433b 6 * Copyright (c) 2015 Kenji Arai / JH1PJL
kenjiArai 0:a3b41ab8433b 7 * http://www.page.sannet.ne.jp/kenjia/index.html
kenjiArai 0:a3b41ab8433b 8 * http://mbed.org/users/kenjiArai/
kenjiArai 0:a3b41ab8433b 9 * Created: January 25th, 2015
kenjiArai 0:a3b41ab8433b 10 * Revised: March 15th, 2015
kenjiArai 0:a3b41ab8433b 11 *
kenjiArai 0:a3b41ab8433b 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
kenjiArai 0:a3b41ab8433b 13 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
kenjiArai 0:a3b41ab8433b 14 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kenjiArai 0:a3b41ab8433b 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenjiArai 0:a3b41ab8433b 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kenjiArai 0:a3b41ab8433b 17 */
kenjiArai 0:a3b41ab8433b 18 /*
kenjiArai 0:a3b41ab8433b 19 *---------------- REFERENCE ----------------------------------------------------------------------
kenjiArai 0:a3b41ab8433b 20 * Original Information
kenjiArai 0:a3b41ab8433b 21 * http://www.ti.com/product/INA219/description
kenjiArai 0:a3b41ab8433b 22 * http://www.ti.com/lit/ds/sbos448f/sbos448f.pdf
kenjiArai 0:a3b41ab8433b 23 * Device kit
kenjiArai 0:a3b41ab8433b 24 * https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout/overview
kenjiArai 0:a3b41ab8433b 25 * http://akizukidenshi.com/catalog/g/gM-08221/
kenjiArai 0:a3b41ab8433b 26 */
kenjiArai 0:a3b41ab8433b 27
kenjiArai 0:a3b41ab8433b 28 #ifndef MBED_INA219
kenjiArai 0:a3b41ab8433b 29 #define MBED_INA219
kenjiArai 0:a3b41ab8433b 30
kenjiArai 0:a3b41ab8433b 31 /////////// ADDRESS /////////////////////////////
kenjiArai 0:a3b41ab8433b 32 // 7bit address = 0b1000000(0x40)
kenjiArai 0:a3b41ab8433b 33 // G=GND, V=VS+, A=SDA, L=SCL
kenjiArai 0:a3b41ab8433b 34 // e.g. _GG: A1=GND, A0=GND
kenjiArai 0:a3b41ab8433b 35 // -> Please make sure your H/W configuration
kenjiArai 0:a3b41ab8433b 36 // Set data into "addr"
kenjiArai 0:a3b41ab8433b 37 #define INA219_ADDR_GG (0x40 << 1)
kenjiArai 0:a3b41ab8433b 38 #define INA219_ADDR_GV (0x41 << 1)
kenjiArai 0:a3b41ab8433b 39 #define INA219_ADDR_GA (0x42 << 1)
kenjiArai 0:a3b41ab8433b 40 #define INA219_ADDR_GL (0x43 << 1)
kenjiArai 0:a3b41ab8433b 41 #define INA219_ADDR_VG (0x44 << 1)
kenjiArai 0:a3b41ab8433b 42 #define INA219_ADDR_VV (0x45 << 1)
kenjiArai 0:a3b41ab8433b 43 #define INA219_ADDR_VA (0x46 << 1)
kenjiArai 0:a3b41ab8433b 44 #define INA219_ADDR_VL (0x47 << 1)
kenjiArai 0:a3b41ab8433b 45 #define INA219_ADDR_AG (0x48 << 1)
kenjiArai 0:a3b41ab8433b 46 #define INA219_ADDR_AV (0x49 << 1)
kenjiArai 0:a3b41ab8433b 47 #define INA219_ADDR_AA (0x4a << 1)
kenjiArai 0:a3b41ab8433b 48 #define INA219_ADDR_AL (0x4b << 1)
kenjiArai 0:a3b41ab8433b 49 #define INA219_ADDR_LG (0x4c << 1)
kenjiArai 0:a3b41ab8433b 50 #define INA219_ADDR_LV (0x4d << 1)
kenjiArai 0:a3b41ab8433b 51 #define INA219_ADDR_LA (0x4e << 1)
kenjiArai 0:a3b41ab8433b 52 #define INA219_ADDR_LL (0x4f << 1)
kenjiArai 0:a3b41ab8433b 53
kenjiArai 0:a3b41ab8433b 54 /////////// REGISTER DEFINITION /////////////////
kenjiArai 0:a3b41ab8433b 55 #define INA219_CONFIG 0x00
kenjiArai 0:a3b41ab8433b 56 #define INA219_SHUNT_V 0x01
kenjiArai 0:a3b41ab8433b 57 #define INA219_BUS_VOLT 0x02
kenjiArai 0:a3b41ab8433b 58 #define INA219_POWER 0x03
kenjiArai 0:a3b41ab8433b 59 #define INA219_CURRENT 0x04
kenjiArai 0:a3b41ab8433b 60 #define INA219_CALBLATION 0x05
kenjiArai 0:a3b41ab8433b 61
kenjiArai 0:a3b41ab8433b 62 /////////// PARAMETER SETTING ///////////////////
kenjiArai 0:a3b41ab8433b 63 // Set data into "shunt_register"
kenjiArai 0:a3b41ab8433b 64 #define INA219_PAR_R_100MOHM 100
kenjiArai 0:a3b41ab8433b 65 #define INA219_PAR_R_200MORM 200
kenjiArai 0:a3b41ab8433b 66 #define INA219_PAR_R_MORM(x) (x)
kenjiArai 0:a3b41ab8433b 67 // Set data into "v_max"
kenjiArai 0:a3b41ab8433b 68 #define INA219_PAR_V_16V 0
kenjiArai 0:a3b41ab8433b 69 #define INA219_PAR_V_32V 1
kenjiArai 0:a3b41ab8433b 70 // Set data into "gain"
kenjiArai 0:a3b41ab8433b 71 #define INA219_PAR_G_40MV 0 // 400[mA] max if R=0.1[Ohm]
kenjiArai 0:a3b41ab8433b 72 #define INA219_PAR_G_80MV 1
kenjiArai 0:a3b41ab8433b 73 #define INA219_PAR_G_160MV 2
kenjiArai 0:a3b41ab8433b 74 #define INA219_PAR_G_320MV 3
kenjiArai 0:a3b41ab8433b 75 // Set data into "adc_resolution"
kenjiArai 0:a3b41ab8433b 76 #define INA219_PAR_S_9B_X1_84US 0x0
kenjiArai 0:a3b41ab8433b 77 #define INA219_PAR_S_10B_X1_148US 0x1
kenjiArai 0:a3b41ab8433b 78 #define INA219_PAR_S_11B_X1_276US 0x2
kenjiArai 0:a3b41ab8433b 79 #define INA219_PAR_S_12B_X1_5328US 0x3
kenjiArai 0:a3b41ab8433b 80 #define INA219_PAR_S_12B_X2_1R06MS 0x9
kenjiArai 0:a3b41ab8433b 81 #define INA219_PAR_S_12B_X4_2R13MS 0xa
kenjiArai 0:a3b41ab8433b 82 #define INA219_PAR_S_12B_X8_4R26MS 0xb
kenjiArai 0:a3b41ab8433b 83 #define INA219_PAR_S_12B_X16_8MS 0xc
kenjiArai 0:a3b41ab8433b 84 #define INA219_PAR_S_12B_X32_17MS 0xd
kenjiArai 0:a3b41ab8433b 85 #define INA219_PAR_S_12B_X64_34MS 0xe
kenjiArai 0:a3b41ab8433b 86 #define INA219_PAR_S_12B_X128_68MS 0xf
kenjiArai 0:a3b41ab8433b 87 // Set data into "mode"
kenjiArai 0:a3b41ab8433b 88 #define INA219_PAR_M_PDWN 0
kenjiArai 0:a3b41ab8433b 89 #define INA219_PAR_M_SHNT_TRG 1
kenjiArai 0:a3b41ab8433b 90 #define INA219_PAR_M_BUS_TRG 2
kenjiArai 0:a3b41ab8433b 91 #define INA219_PAR_M_SHNTBUS_TRG 3
kenjiArai 0:a3b41ab8433b 92 #define INA219_PAR_M_ADC_OFF 4
kenjiArai 0:a3b41ab8433b 93 #define INA219_PAR_M_SHNT_CONT 5
kenjiArai 0:a3b41ab8433b 94 #define INA219_PAR_M_BUS_CONT 6
kenjiArai 0:a3b41ab8433b 95 #define INA219_PAR_M_SHNTBUS_CONT 7
kenjiArai 0:a3b41ab8433b 96
kenjiArai 0:a3b41ab8433b 97 /////////// BIT DEFINITION (Internal use) ///////
kenjiArai 0:a3b41ab8433b 98 #define INA219_CFG_RESET (1UL << 15)
kenjiArai 0:a3b41ab8433b 99
kenjiArai 0:a3b41ab8433b 100 #define INA219_CFG_B32V (1UL << 13)
kenjiArai 0:a3b41ab8433b 101 #define INA219_CFG_B16V (0UL << 13)
kenjiArai 0:a3b41ab8433b 102
kenjiArai 0:a3b41ab8433b 103 #define INA219_CFG_PGA_DIV_1 (0UL << 11)
kenjiArai 0:a3b41ab8433b 104 #define INA219_CFG_PGA_DIV_2 (1UL << 11)
kenjiArai 0:a3b41ab8433b 105 #define INA219_CFG_PGA_DIV_4 (2UL << 11)
kenjiArai 0:a3b41ab8433b 106 #define INA219_CFG_PGA_DIV_8 (3UL << 11)
kenjiArai 0:a3b41ab8433b 107
kenjiArai 0:a3b41ab8433b 108 #define INA219_CFG_BADC (0xf << 7)
kenjiArai 0:a3b41ab8433b 109
kenjiArai 0:a3b41ab8433b 110 #define INA219_CFG_SADC_9B_84U (0x0 << 3)
kenjiArai 0:a3b41ab8433b 111 #define INA219_CFG_SADC_10B_148U (0x1 << 3)
kenjiArai 0:a3b41ab8433b 112 #define INA219_CFG_SADC_11B_276U (0x2 << 3)
kenjiArai 0:a3b41ab8433b 113 #define INA219_CFG_SADC_12B_532U (0x3 << 3)
kenjiArai 0:a3b41ab8433b 114 #define INA219_CFG_SADC_2S_1R06M (0x9 << 3)
kenjiArai 0:a3b41ab8433b 115 #define INA219_CFG_SADC_4S_2R13M (0xa << 3)
kenjiArai 0:a3b41ab8433b 116 #define INA219_CFG_SADC_8S_4R26M (0xb << 3)
kenjiArai 0:a3b41ab8433b 117 #define INA219_CFG_SADC_16S_8R51M (0xc << 3)
kenjiArai 0:a3b41ab8433b 118 #define INA219_CFG_SADC_32S_17M (0xd << 3)
kenjiArai 0:a3b41ab8433b 119 #define INA219_CFG_SADC_64S_34M (0xe << 3)
kenjiArai 0:a3b41ab8433b 120 #define INA219_CFG_SADC_128S_68M (0xf << 3)
kenjiArai 0:a3b41ab8433b 121
kenjiArai 0:a3b41ab8433b 122 #define INA219_CFG_MODE_PDWN (0UL << 0)
kenjiArai 0:a3b41ab8433b 123 #define INA219_CFG_MODE_SHNTTRG (1UL << 0)
kenjiArai 0:a3b41ab8433b 124 #define INA219_CFG_MODE_BUSTRG (2UL << 0)
kenjiArai 0:a3b41ab8433b 125 #define INA219_CFG_MODE_SBTRG (3UL << 0)
kenjiArai 0:a3b41ab8433b 126 #define INA219_CFG_MODE_ADC_OFF (4UL << 0)
kenjiArai 0:a3b41ab8433b 127 #define INA219_CFG_MODE_SHNT_CONT (5UL << 0)
kenjiArai 0:a3b41ab8433b 128 #define INA219_CFG_MODE_BUS_CONT (6UL << 0)
kenjiArai 0:a3b41ab8433b 129 #define INA219_CFG_MODE_SB_CONT (7UL << 0)
kenjiArai 0:a3b41ab8433b 130
kenjiArai 0:a3b41ab8433b 131 ////////////// DATA TYPE DEFINITION ///////////////////////
kenjiArai 0:a3b41ab8433b 132 typedef struct {
kenjiArai 0:a3b41ab8433b 133 uint8_t addr;
kenjiArai 0:a3b41ab8433b 134 uint8_t shunt_register;
kenjiArai 0:a3b41ab8433b 135 uint8_t v_max;
kenjiArai 0:a3b41ab8433b 136 uint8_t gain;
kenjiArai 0:a3b41ab8433b 137 uint8_t adc_resolution;
kenjiArai 0:a3b41ab8433b 138 uint8_t mode;
kenjiArai 0:a3b41ab8433b 139 uint16_t calibration_data;
kenjiArai 0:a3b41ab8433b 140 } INA219_TypeDef;
kenjiArai 0:a3b41ab8433b 141
kenjiArai 0:a3b41ab8433b 142 ////////////// DEFAULT SETTING ////////////////////////////
kenjiArai 0:a3b41ab8433b 143 // Standard parameter for easy set-up
kenjiArai 0:a3b41ab8433b 144 const INA219_TypeDef ina219_std_paramtr = {
kenjiArai 0:a3b41ab8433b 145 INA219_ADDR_GG, // I2C Address, Acc & Magn
kenjiArai 0:a3b41ab8433b 146 INA219_PAR_R_100MOHM, // 100 milli-ohm
kenjiArai 0:a3b41ab8433b 147 INA219_CFG_B16V, // 16V max
kenjiArai 0:a3b41ab8433b 148 INA219_PAR_G_40MV, // Gain x1 (40mV -> 400mA max with 100 milliOhm)
kenjiArai 0:a3b41ab8433b 149 INA219_PAR_S_12B_X1_5328US, // resolution 12bit & one time convertion
kenjiArai 0:a3b41ab8433b 150 INA219_PAR_M_SHNTBUS_CONT, // Measure continuously both Shunt voltage and Bus voltage
kenjiArai 0:a3b41ab8433b 151 16384 // Calibration data is nothing
kenjiArai 0:a3b41ab8433b 152 };
kenjiArai 0:a3b41ab8433b 153
kenjiArai 0:a3b41ab8433b 154 /** INA219 High-Side Measurement,Bi-Directional CURRENT/POWER MONITOR with I2C Interface
kenjiArai 0:a3b41ab8433b 155 *
kenjiArai 0:a3b41ab8433b 156 * @code
kenjiArai 0:a3b41ab8433b 157 * //--------- Default setting -----------------
kenjiArai 0:a3b41ab8433b 158 * #include "mbed.h"
kenjiArai 0:a3b41ab8433b 159 * #include "INA219.h"
kenjiArai 0:a3b41ab8433b 160 *
kenjiArai 0:a3b41ab8433b 161 * // I2C Communication
kenjiArai 0:a3b41ab8433b 162 * INA219 current(dp5, dp27, INA219_ADDR_GG);
kenjiArai 0:a3b41ab8433b 163 * // If you connected I2C line not only this device but also other devices,
kenjiArai 0:a3b41ab8433b 164 * // you need to declare following method.
kenjiArai 0:a3b41ab8433b 165 * I2C i2c(dp5, dp27);
kenjiArai 0:a3b41ab8433b 166 * INA219 current(I2C& p_i2c, INA219_ADDR_GG);
kenjiArai 0:a3b41ab8433b 167 *
kenjiArai 0:a3b41ab8433b 168 * int main() {
kenjiArai 0:a3b41ab8433b 169 * while(1){
kenjiArai 0:a3b41ab8433b 170 * printf("I=%+6.3f [mA]\r\n", current.read_current());
kenjiArai 0:a3b41ab8433b 171 * wait(1.0):
kenjiArai 0:a3b41ab8433b 172 * }
kenjiArai 0:a3b41ab8433b 173 * }
kenjiArai 0:a3b41ab8433b 174 * //--------- Detail setting -----------------
kenjiArai 0:a3b41ab8433b 175 * #include "mbed.h"
kenjiArai 0:a3b41ab8433b 176 *
kenjiArai 0:a3b41ab8433b 177 * const INA219_TypeDef ina219_my_paramtr = {
kenjiArai 0:a3b41ab8433b 178 * INA219_ADDR_GG, // I2C Address, Acc & Magn
kenjiArai 0:a3b41ab8433b 179 * INA219_PAR_R_100MOHM, // 100 milli-ohm
kenjiArai 0:a3b41ab8433b 180 * INA219_CFG_B16V, // 16V max
kenjiArai 0:a3b41ab8433b 181 * INA219_PAR_G_40MV, // Gain x1
kenjiArai 0:a3b41ab8433b 182 * INA219_PAR_M_SHNTBUS_CONT, // Measure continuously
kenjiArai 0:a3b41ab8433b 183 * 0 // Calibration data is nothing
kenjiArai 0:a3b41ab8433b 184 * };
kenjiArai 0:a3b41ab8433b 185 *
kenjiArai 0:a3b41ab8433b 186 * I2C i2c(dp5,dp27);
kenjiArai 0:a3b41ab8433b 187 * INA219 current(I2C& p_i2c, &ina219_my_paramtr);
kenjiArai 0:a3b41ab8433b 188 *
kenjiArai 0:a3b41ab8433b 189 * int main() {
kenjiArai 0:a3b41ab8433b 190 * while(1){
kenjiArai 0:a3b41ab8433b 191 * printf("I=%+6.3f [mA]\r\n", current.read_current());
kenjiArai 0:a3b41ab8433b 192 * wait(1.0):
kenjiArai 0:a3b41ab8433b 193 * }
kenjiArai 0:a3b41ab8433b 194 * }
kenjiArai 0:a3b41ab8433b 195 * @endcode
kenjiArai 0:a3b41ab8433b 196 */
kenjiArai 0:a3b41ab8433b 197
kenjiArai 0:a3b41ab8433b 198 class INA219
kenjiArai 0:a3b41ab8433b 199 {
kenjiArai 0:a3b41ab8433b 200 public:
kenjiArai 0:a3b41ab8433b 201 /** Configure data pin
kenjiArai 0:a3b41ab8433b 202 * @param data SDA and SCL pins
kenjiArai 0:a3b41ab8433b 203 * @param parameter address chip (INA219_TypeDef)
kenjiArai 0:a3b41ab8433b 204 * @param or just set address or just port
kenjiArai 0:a3b41ab8433b 205 */
kenjiArai 0:a3b41ab8433b 206 INA219(PinName p_sda, PinName p_scl, const INA219_TypeDef *ina219_parameter);
kenjiArai 0:a3b41ab8433b 207 INA219(PinName p_sda, PinName p_scl, uint8_t addr);
kenjiArai 0:a3b41ab8433b 208 INA219(PinName p_sda, PinName p_scl);
kenjiArai 0:a3b41ab8433b 209
kenjiArai 0:a3b41ab8433b 210 /** Configure data pin (with other devices on I2C line)
kenjiArai 0:a3b41ab8433b 211 * @param I2C previous definition
kenjiArai 0:a3b41ab8433b 212 * @param parameter address chip (INA219_TypeDef)
kenjiArai 0:a3b41ab8433b 213 * @param or just set address or just port
kenjiArai 0:a3b41ab8433b 214 */
kenjiArai 0:a3b41ab8433b 215 INA219(I2C& p_i2c, const INA219_TypeDef *ina219_parameter);
kenjiArai 0:a3b41ab8433b 216 INA219(I2C& p_i2c, uint8_t addr);
kenjiArai 0:a3b41ab8433b 217 INA219(I2C& p_i2c);
kenjiArai 0:a3b41ab8433b 218
kenjiArai 0:a3b41ab8433b 219 /** Read Current data
kenjiArai 0:a3b41ab8433b 220 * @param none
kenjiArai 0:a3b41ab8433b 221 * @return current [mA]
kenjiArai 0:a3b41ab8433b 222 */
kenjiArai 0:a3b41ab8433b 223 float read_current(void);
kenjiArai 0:a3b41ab8433b 224 float read_current_by_shuntvolt(void);
kenjiArai 0:a3b41ab8433b 225
kenjiArai 0:a3b41ab8433b 226 /** Read Power data
kenjiArai 0:a3b41ab8433b 227 * @param none
kenjiArai 0:a3b41ab8433b 228 * @return power [w]
kenjiArai 0:a3b41ab8433b 229 */
kenjiArai 0:a3b41ab8433b 230 float read_power(void);
kenjiArai 0:a3b41ab8433b 231
kenjiArai 0:a3b41ab8433b 232 /** Read Bus voltage
kenjiArai 0:a3b41ab8433b 233 * @param none
kenjiArai 0:a3b41ab8433b 234 * @return voltage [v]
kenjiArai 0:a3b41ab8433b 235 */
kenjiArai 0:a3b41ab8433b 236 float read_bus_voltage(void);
kenjiArai 0:a3b41ab8433b 237
kenjiArai 0:a3b41ab8433b 238 /** Read Shunt voltage data
kenjiArai 0:a3b41ab8433b 239 * @param none
kenjiArai 0:a3b41ab8433b 240 * @return voltage [v]
kenjiArai 0:a3b41ab8433b 241 */
kenjiArai 0:a3b41ab8433b 242 float read_shunt_voltage(void);
kenjiArai 0:a3b41ab8433b 243
kenjiArai 0:a3b41ab8433b 244 /** Read configration reg.
kenjiArai 0:a3b41ab8433b 245 * @param none
kenjiArai 0:a3b41ab8433b 246 * @return configrartion register value
kenjiArai 0:a3b41ab8433b 247 */
kenjiArai 0:a3b41ab8433b 248 uint16_t read_config(void);
kenjiArai 0:a3b41ab8433b 249
kenjiArai 0:a3b41ab8433b 250 /** Set configration reg.
kenjiArai 0:a3b41ab8433b 251 * @param
kenjiArai 0:a3b41ab8433b 252 * @return configrartion register value
kenjiArai 0:a3b41ab8433b 253 */
kenjiArai 0:a3b41ab8433b 254 uint16_t set_config(uint16_t cfg);
kenjiArai 0:a3b41ab8433b 255
kenjiArai 0:a3b41ab8433b 256 /** Read calibration reg.
kenjiArai 0:a3b41ab8433b 257 * @param none
kenjiArai 0:a3b41ab8433b 258 * @return calibration register value
kenjiArai 0:a3b41ab8433b 259 */
kenjiArai 0:a3b41ab8433b 260 uint16_t read_calb(void);
kenjiArai 0:a3b41ab8433b 261
kenjiArai 0:a3b41ab8433b 262 /** Set calibration reg.
kenjiArai 0:a3b41ab8433b 263 * @param
kenjiArai 0:a3b41ab8433b 264 * @return calibration register value
kenjiArai 0:a3b41ab8433b 265 */
kenjiArai 0:a3b41ab8433b 266 uint16_t set_calb(uint16_t clb);
kenjiArai 0:a3b41ab8433b 267
kenjiArai 0:a3b41ab8433b 268 /** Set I2C clock frequency
kenjiArai 0:a3b41ab8433b 269 * @param freq.
kenjiArai 0:a3b41ab8433b 270 * @return none
kenjiArai 0:a3b41ab8433b 271 */
kenjiArai 0:a3b41ab8433b 272 void frequency(int hz);
kenjiArai 0:a3b41ab8433b 273
kenjiArai 0:a3b41ab8433b 274 /** Read register (general purpose)
kenjiArai 0:a3b41ab8433b 275 * @param register's address
kenjiArai 0:a3b41ab8433b 276 * @return register data
kenjiArai 0:a3b41ab8433b 277 */
kenjiArai 0:a3b41ab8433b 278 uint8_t read_reg(uint8_t addr);
kenjiArai 0:a3b41ab8433b 279
kenjiArai 0:a3b41ab8433b 280 /** Write register (general purpose)
kenjiArai 0:a3b41ab8433b 281 * @param register's address
kenjiArai 0:a3b41ab8433b 282 * @param data
kenjiArai 0:a3b41ab8433b 283 * @return register data
kenjiArai 0:a3b41ab8433b 284 */
kenjiArai 0:a3b41ab8433b 285 uint8_t write_reg(uint8_t addr, uint8_t data);
kenjiArai 0:a3b41ab8433b 286
kenjiArai 0:a3b41ab8433b 287 protected:
kenjiArai 0:a3b41ab8433b 288 I2C _i2c;
kenjiArai 0:a3b41ab8433b 289
kenjiArai 0:a3b41ab8433b 290 void initialize(void);
kenjiArai 0:a3b41ab8433b 291
kenjiArai 0:a3b41ab8433b 292 private:
kenjiArai 0:a3b41ab8433b 293 INA219_TypeDef ina219_set_data;
kenjiArai 0:a3b41ab8433b 294 int32_t scale_factor;
kenjiArai 0:a3b41ab8433b 295 uint8_t dt[4];
kenjiArai 0:a3b41ab8433b 296
kenjiArai 0:a3b41ab8433b 297 };
kenjiArai 0:a3b41ab8433b 298
kenjiArai 0:a3b41ab8433b 299 #endif // MBED_INA219