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

Dependents:   SensorsThingSpeak

Committer:
tsoic
Date:
Mon Nov 30 07:17:53 2015 +0000
Revision:
3:fc2a11f942fd
Parent:
2:94ed6c056d01

        

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 3:fc2a11f942fd 28 /**
tsoic 3:fc2a11f942fd 29 * Calling the INA219 calibrates the sensor registers
tsoic 3:fc2a11f942fd 30 */
tsoic 0:cdfbda214bee 31 INA219();
tsoic 1:6b9f92e99dd7 32 /** Read raw value from register
tsoic 1:6b9f92e99dd7 33 * @param reg adress of register definicions in INA219_reg.h
tsoic 1:6b9f92e99dd7 34 * @returns raw float value
tsoic 1:6b9f92e99dd7 35 */
tsoic 1:6b9f92e99dd7 36
tsoic 1:6b9f92e99dd7 37 uint16_t readRawReg(uint8_t reg);
tsoic 1:6b9f92e99dd7 38
tsoic 1:6b9f92e99dd7 39 /**
tsoic 1:6b9f92e99dd7 40 * Read raw value from register
tsoic 1:6b9f92e99dd7 41 * @param reg adress of register defined in INA219_reg.h
tsoic 1:6b9f92e99dd7 42 * @param data data that you want to sent
tsoic 1:6b9f92e99dd7 43 */
tsoic 1:6b9f92e99dd7 44 void write_reg(uint8_t reg, uint8_t data);
tsoic 1:6b9f92e99dd7 45
tsoic 1:6b9f92e99dd7 46 private:
tsoic 1:6b9f92e99dd7 47
tsoic 0:cdfbda214bee 48 I2CR i2cr;
tsoic 1:6b9f92e99dd7 49
tsoic 0:cdfbda214bee 50 uint8_t dt[4];
tsoic 1:6b9f92e99dd7 51 /**
tsoic 1:6b9f92e99dd7 52 * Should be public with changable calibration values.
tsoic 1:6b9f92e99dd7 53 * Calibration settings set to :
tsoic 1:6b9f92e99dd7 54 * A0 i A1 to GND (adress for I2C communication 0x40)
tsoic 1:6b9f92e99dd7 55 * - 320 mv range
tsoic 1:6b9f92e99dd7 56 * - 16 V bus voltage
tsoic 1:6b9f92e99dd7 57 * - 12 bit 128 samples current and bus voltage ADC resolution
tsoic 1:6b9f92e99dd7 58 * - Shunt and bus voltage conntinious
tsoic 1:6b9f92e99dd7 59 * - Calibration : 5400
tsoic 1:6b9f92e99dd7 60 */
tsoic 1:6b9f92e99dd7 61 void calibration();
tsoic 0:cdfbda214bee 62 };
tsoic 0:cdfbda214bee 63
tsoic 1:6b9f92e99dd7 64 #endif