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

Dependents:   SensorsThingSpeak

Committer:
tsoic
Date:
Sun Nov 29 13:40:51 2015 +0000
Revision:
1:6b9f92e99dd7
Parent:
0:cdfbda214bee
Child:
2:94ed6c056d01
Comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsoic 1:6b9f92e99dd7 1 /** Simplified INA219 class, fork of https://developer.mbed.org/users/mazgch/code/INA219/ from Michael Ammann .
tsoic 1:6b9f92e99dd7 2 * 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 3 *
tsoic 1:6b9f92e99dd7 4 * Example:
tsoic 1:6b9f92e99dd7 5 * @code
tsoic 1:6b9f92e99dd7 6 * #include "mbed.h"
tsoic 1:6b9f92e99dd7 7 * #include "INA219.h"
tsoic 1:6b9f92e99dd7 8 * #include "INA219_reg.h"
tsoic 1:6b9f92e99dd7 9 *
tsoic 1:6b9f92e99dd7 10 * INA219 ina();
tsoic 1:6b9f92e99dd7 11 * float rawValue;
tsoic 1:6b9f92e99dd7 12 *
tsoic 1:6b9f92e99dd7 13 * int main() {
tsoic 1:6b9f92e99dd7 14 * rawValue = ina.readRawReg(INA219_POWER);
tsoic 1:6b9f92e99dd7 15 * }
tsoic 1:6b9f92e99dd7 16 * @endcode
tsoic 1:6b9f92e99dd7 17
tsoic 1:6b9f92e99dd7 18 */
tsoic 0:cdfbda214bee 19 #ifndef INA219_H
tsoic 0:cdfbda214bee 20 #define INA219_H
tsoic 0:cdfbda214bee 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