Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ina226.cpp
- Revision:
- 0:4318f664a8e1
- Child:
- 1:5dc94660e311
diff -r 000000000000 -r 4318f664a8e1 ina226.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ina226.cpp Wed Dec 02 18:01:38 2015 +0000
@@ -0,0 +1,39 @@
+#include "ina226.h"
+
+INA226::INA226(I2C* theI2C, char address)
+{
+ //set up config register //256 averages //continuous shunt voltage conversion
+ short write_byte = CONF_DEFAULT |_BV(AVG2) | _BV(AVG0) | _BV(MODE3) | _BV(MODE1);
+
+ write(REG_CONF, write_byte);
+ //set up calibration (full range ~1.6A)
+ write(REG_CAL, 0x0800);
+}
+
+void INA226::write(INA226REG reg, short value)
+{
+ shortToChar stc;
+ char cmd[3];
+ stc.u16 = value;
+
+ cmd[0] = reg;
+ cmd[1] = stc.u8[1];
+ cmd[2] = stc.u8[0];
+
+ i2c->write(i2cAddress,cmd,3);
+}
+
+short INA226::read(INA226REG reg)
+{
+ shortToChar stc;
+
+ char cmd[2];
+ cmd[0] = reg;
+ i2c->write(i2cAddress,cmd,1);
+
+ i2c->read(i2cAddress, cmd, 2);
+ stc.u8[1] = cmd[0];
+ stc.u8[0] = cmd[1];
+
+ return (stc.u16);
+}
\ No newline at end of file