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.
Dependencies: INA226_ver1 mbed
Fork of INA226TEST by
main.cpp@2:86728e672228, 2016-01-15 (annotated)
- Committer:
- taurin
- Date:
- Fri Jan 15 17:04:51 2016 +0000
- Revision:
- 2:86728e672228
- Parent:
- 0:b20f8673a7fa
- Child:
- 3:e37fd18c08e6
INA 1/16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 0:b20f8673a7fa | 1 | /* |
tosihisa | 0:b20f8673a7fa | 2 | * Copyright (c) 2011 Toshihisa T |
tosihisa | 0:b20f8673a7fa | 3 | * Released under the MIT License: http://mbed.org/license/mit |
tosihisa | 0:b20f8673a7fa | 4 | */ |
tosihisa | 0:b20f8673a7fa | 5 | |
tosihisa | 0:b20f8673a7fa | 6 | #include "mbed.h" |
tosihisa | 0:b20f8673a7fa | 7 | #include "INA226.hpp" |
tosihisa | 0:b20f8673a7fa | 8 | |
tosihisa | 0:b20f8673a7fa | 9 | Serial debug(USBTX,USBRX); |
tosihisa | 0:b20f8673a7fa | 10 | DigitalOut myled(LED1); |
tosihisa | 0:b20f8673a7fa | 11 | I2C i2c(p28,p27); |
tosihisa | 0:b20f8673a7fa | 12 | INA226 VCmonitor(i2c); |
tosihisa | 0:b20f8673a7fa | 13 | |
tosihisa | 0:b20f8673a7fa | 14 | int main() { |
tosihisa | 0:b20f8673a7fa | 15 | unsigned short val; |
tosihisa | 0:b20f8673a7fa | 16 | double V,C; |
tosihisa | 0:b20f8673a7fa | 17 | int count = 1; |
tosihisa | 0:b20f8673a7fa | 18 | |
tosihisa | 0:b20f8673a7fa | 19 | debug.format(8,ParityNone,1); |
taurin | 2:86728e672228 | 20 | debug.baud(9600); |
tosihisa | 0:b20f8673a7fa | 21 | debug.printf("VCmonitor INA226 TEST Program. (BUILD:[" __DATE__ "/" __TIME__ "])\n"); |
tosihisa | 0:b20f8673a7fa | 22 | |
tosihisa | 0:b20f8673a7fa | 23 | if(!VCmonitor.isExist()){ |
tosihisa | 0:b20f8673a7fa | 24 | debug.printf("VCmonitor NOT FOUND\n"); |
tosihisa | 0:b20f8673a7fa | 25 | while(1){} |
tosihisa | 0:b20f8673a7fa | 26 | } |
tosihisa | 0:b20f8673a7fa | 27 | debug.printf("VCmonitor FOUND\n"); |
tosihisa | 0:b20f8673a7fa | 28 | |
tosihisa | 0:b20f8673a7fa | 29 | val = 0; |
tosihisa | 0:b20f8673a7fa | 30 | if(VCmonitor.rawRead(0x00,&val) != 0){ |
tosihisa | 0:b20f8673a7fa | 31 | debug.printf("VCmonitor READ ERROR\n"); |
tosihisa | 0:b20f8673a7fa | 32 | while(1){} |
tosihisa | 0:b20f8673a7fa | 33 | } |
tosihisa | 0:b20f8673a7fa | 34 | debug.printf("VCmonitor Reg 0x00 : 0x%04x\n",val); |
tosihisa | 0:b20f8673a7fa | 35 | |
tosihisa | 0:b20f8673a7fa | 36 | VCmonitor.setCurrentCalibration(); |
tosihisa | 0:b20f8673a7fa | 37 | |
tosihisa | 0:b20f8673a7fa | 38 | while(1) { |
tosihisa | 0:b20f8673a7fa | 39 | if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){ |
tosihisa | 0:b20f8673a7fa | 40 | debug.printf("%d,V,%f,C,%f\n",count,V,C); |
tosihisa | 0:b20f8673a7fa | 41 | } |
tosihisa | 0:b20f8673a7fa | 42 | myled = 1; |
tosihisa | 0:b20f8673a7fa | 43 | wait(0.5); |
tosihisa | 0:b20f8673a7fa | 44 | myled = 0; |
tosihisa | 0:b20f8673a7fa | 45 | wait(0.5); |
tosihisa | 0:b20f8673a7fa | 46 | count++; |
tosihisa | 0:b20f8673a7fa | 47 | } |
tosihisa | 0:b20f8673a7fa | 48 | } |