Basic INA219, with set calibaration and functions for reading raw register and write to register

Dependents:   SensorsThingSpeak

Committer:
tsoic
Date:
Mon Nov 30 07:14:52 2015 +0000
Revision:
2:94ed6c056d01
Parent:
1:6b9f92e99dd7
Child:
3:fc2a11f942fd

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsoic 2:94ed6c056d01 1
tsoic 2:94ed6c056d01 2 #ifndef INA219_H
tsoic 2:94ed6c056d01 3 #define INA219_H
tsoic 1:6b9f92e99dd7 4 /** Simplified INA219 class, fork of https://developer.mbed.org/users/mazgch/code/INA219/ from Michael Ammann .
tsoic 1:6b9f92e99dd7 5 * This class is using I2CR class https://developer.mbed.org/users/ShockSoc/code/I2CR/ which is set to pins p9 (SDA) and p10 (SCL)
tsoic 1:6b9f92e99dd7 6 *
tsoic 1:6b9f92e99dd7 7 * Example:
tsoic 1:6b9f92e99dd7 8 * @code
tsoic 1:6b9f92e99dd7 9 * #include "mbed.h"
tsoic 1:6b9f92e99dd7 10 * #include "INA219.h"
tsoic 1:6b9f92e99dd7 11 * #include "INA219_reg.h"
tsoic 1:6b9f92e99dd7 12 *
tsoic 1:6b9f92e99dd7 13 * INA219 ina();
tsoic 1:6b9f92e99dd7 14 * float rawValue;
tsoic 1:6b9f92e99dd7 15 *
tsoic 1:6b9f92e99dd7 16 * int main() {
tsoic 1:6b9f92e99dd7 17 * rawValue = ina.readRawReg(INA219_POWER);
tsoic 1:6b9f92e99dd7 18 * }
tsoic 1:6b9f92e99dd7 19 * @endcode
tsoic 1:6b9f92e99dd7 20
tsoic 1:6b9f92e99dd7 21 */
tsoic 0:cdfbda214bee 22 #include "mbed.h"
tsoic 0:cdfbda214bee 23 #include "I2CR.h"
tsoic 0:cdfbda214bee 24
tsoic 1:6b9f92e99dd7 25 class INA219
tsoic 1:6b9f92e99dd7 26 {
tsoic 1:6b9f92e99dd7 27 public:
tsoic 1:6b9f92e99dd7 28
tsoic 0:cdfbda214bee 29 INA219();
tsoic 1:6b9f92e99dd7 30 /** Read raw value from register
tsoic 1:6b9f92e99dd7 31 * @param reg adress of register definicions in INA219_reg.h
tsoic 1:6b9f92e99dd7 32 * @returns raw float value
tsoic 1:6b9f92e99dd7 33 */
tsoic 1:6b9f92e99dd7 34
tsoic 1:6b9f92e99dd7 35 uint16_t readRawReg(uint8_t reg);
tsoic 1:6b9f92e99dd7 36
tsoic 1:6b9f92e99dd7 37 /**
tsoic 1:6b9f92e99dd7 38 * Read raw value from register
tsoic 1:6b9f92e99dd7 39 * @param reg adress of register defined in INA219_reg.h
tsoic 1:6b9f92e99dd7 40 * @param data data that you want to sent
tsoic 1:6b9f92e99dd7 41 */
tsoic 1:6b9f92e99dd7 42 void write_reg(uint8_t reg, uint8_t data);
tsoic 1:6b9f92e99dd7 43
tsoic 1:6b9f92e99dd7 44 private:
tsoic 1:6b9f92e99dd7 45
tsoic 0:cdfbda214bee 46 I2CR i2cr;
tsoic 1:6b9f92e99dd7 47
tsoic 0:cdfbda214bee 48 uint8_t dt[4];
tsoic 1:6b9f92e99dd7 49 /**
tsoic 1:6b9f92e99dd7 50 * Should be public with changable calibration values.
tsoic 1:6b9f92e99dd7 51 * Calibration settings set to :
tsoic 1:6b9f92e99dd7 52 * A0 i A1 to GND (adress for I2C communication 0x40)
tsoic 1:6b9f92e99dd7 53 * - 320 mv range
tsoic 1:6b9f92e99dd7 54 * - 16 V bus voltage
tsoic 1:6b9f92e99dd7 55 * - 12 bit 128 samples current and bus voltage ADC resolution
tsoic 1:6b9f92e99dd7 56 * - Shunt and bus voltage conntinious
tsoic 1:6b9f92e99dd7 57 * - Calibration : 5400
tsoic 1:6b9f92e99dd7 58 */
tsoic 1:6b9f92e99dd7 59 void calibration();
tsoic 0:cdfbda214bee 60 };
tsoic 0:cdfbda214bee 61
tsoic 1:6b9f92e99dd7 62 #endif