![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BMS I/Fプログラム
Diff: main.cpp
- Revision:
- 2:c7ea42f45ff5
- Parent:
- 1:5690684e5460
- Child:
- 3:8607d7ab7f25
diff -r 5690684e5460 -r c7ea42f45ff5 main.cpp --- a/main.cpp Sun May 17 02:21:27 2015 +0000 +++ b/main.cpp Fri Apr 29 08:13:52 2016 +0000 @@ -2,10 +2,10 @@ #include "LTC6803.h" DigitalOut myled(LED1); -SPI spi(p11, p12, p13); // mosi, miso, sclk -DigitalOut cs(p15); +SPI spi(dp2, dp1, dp6); // mosi, miso, sclk +DigitalOut cs(dp4); -Serial pc(USBTX, USBRX); +Serial pc(dp16, dp15); unsigned char CalcCRCLTC6803(unsigned char * dat, unsigned char numdat); @@ -75,13 +75,14 @@ int main() { unsigned char cmd, tmp, datnum; - unsigned char dat[16], getdat[16]; + unsigned char dat[16], getdat[18]; // float cellvol[4]; - int cellvol[4]; + int cellvol[12]; + int cellallvol; char str[32]; cs = 1; spi.format(8,3); - spi.frequency(8000000); + spi.frequency(500000); pc.baud(460800); cs = 0; @@ -89,7 +90,7 @@ spi.write(cmd); spi.write(CalcCRCLTC6803(&cmd, 1)); dat[0] = 0x02; - dat[1] = 0x0f; + dat[1] = 0x00; dat[2] = 0x00; dat[3] = 0xff; dat[4] = 42; @@ -103,10 +104,10 @@ wait(0.001); while(1) { cs = 0; - cmd = RDCVA; + cmd = RDCV; spi.write(cmd); spi.write(CalcCRCLTC6803(&cmd, 1)); - for(int loop = 0;loop < 6; loop++){ + for(int loop = 0;loop < 18; loop++){ getdat[loop] = spi.write(0); } cs = 1; @@ -118,10 +119,22 @@ cellvol[1] = ((getdat[2] << 4) | ((getdat[1] & 0xf0) >> 4)); cellvol[2] = (((getdat[4] & 0x0f) << 8) | getdat[3]); cellvol[3] = ((getdat[5] << 4) | ((getdat[4] & 0xf0) >> 4)); + cellvol[4] = (((getdat[7] & 0x0f) << 8) | getdat[6]); + cellvol[5] = ((getdat[8] << 4) | ((getdat[7] & 0xf0) >> 4)); + cellvol[6] = (((getdat[10] & 0x0f) << 8) | getdat[9]); + cellvol[7] = ((getdat[11] << 4) | ((getdat[10] & 0xf0) >> 4)); + cellvol[8] = (((getdat[13] & 0x0f) << 8) | getdat[12]); + cellvol[9] = ((getdat[14] << 4) | ((getdat[13] & 0xf0) >> 4)); + cellvol[10] = (((getdat[16] & 0x0f) << 8) | getdat[15]); + cellvol[11] = ((getdat[17] << 4) | ((getdat[16] & 0xf0) >> 4)); + cellallvol = 0; - for(int loop = 0;loop < 4; loop++){ - pc.printf("Cell%d = %6d\n", loop, cellvol[loop]); + for(int loop = 0;loop < 12; loop++){ + //表示する数値は(cellvol[loop] - 512)*1.5mV + pc.printf("Cell%3d = %5dmV\n", loop, ((cellvol[loop] - 512)+((cellvol[loop] - 512)/2))); + cellallvol += cellvol[loop]; } + pc.printf("CellALL = %5dmV\n", ((cellallvol - 512*12)+((cellallvol - 512*12)/2))); cmd = STCVADALL;