naoto tanaka
/
LTC6803_Eval
BMS I/Fプログラム
Revision 6:517848b32b0f, committed 2016-10-16
- Comitter:
- NT32
- Date:
- Sun Oct 16 13:42:05 2016 +0000
- Parent:
- 5:8076127d0690
- Commit message:
- BMS I/F?????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8076127d0690 -r 517848b32b0f main.cpp --- a/main.cpp Sun Oct 16 06:40:13 2016 +0000 +++ b/main.cpp Sun Oct 16 13:42:05 2016 +0000 @@ -6,16 +6,22 @@ SPI spi(dp2, dp1, dp6); // mosi, miso, sclk DigitalOut cs(dp4); -Serial pc(dp16, dp15); +Serial pc(dp16, dp15); //制御基板とのシリアル接続 unsigned char CalcCRCLTC6803(unsigned char * dat, unsigned char numdat); +//----------------------------------------- +// グローバル変数 +//----------------------------------------- +// CRC演算用変数 static unsigned char crc8_table[256]; // 8-bit table for PEC calc static int made_table = 0; // table made flag unsigned char packet[18]={0}; // used for PEC calc unsigned char PECbyte; // PEC of a byte unsigned char PECpacket; // PEC of packet unsigned char PECpacketREAD; // value that PECpacket should be as read from 6803 +// 制御基板との通信確率フラグ +static unsigned char comFlag = 0; static void init_crc8(); void setPECbyte(unsigned char m); @@ -72,6 +78,17 @@ return pec; } +//----------------------------------------- +// 制御基板からの受信割り込みサービスルーチン +//----------------------------------------- +void pcRxISR() { + if(pc.getc() == 's'){ + comFlag = 1; + myled = 1; + }else{ + comFlag = 0; + } +} int main() { @@ -79,12 +96,12 @@ unsigned char dat[16], getdat[18][BMS_NUM]; // float cellvol[4]; int cellvol[12][BMS_NUM]; - int cellallvol; + int cellallvol, cellMinVol, cellMaxVol; char str[32]; cs = 1; spi.format(8,3); spi.frequency(500000); - pc.baud(460800); + pc.baud(115200); cs = 0; cmd = WRCFG; @@ -119,9 +136,9 @@ cs = 1; wait(0.001); cs = 0; - pc.printf("\033[2J"); - pc.printf("\033[%d;%dH" , 0, 0); cellallvol = 0; + cellMinVol = getdat[0][0]; + cellMaxVol = getdat[0][0]; for(int bms = 0; bms < BMS_NUM; bms++){ cellvol[0][bms] = (((getdat[1][bms] & 0x0f) << 8) | getdat[0][bms]); cellvol[1][bms] = ((getdat[2][bms] << 4) | ((getdat[1][bms] & 0xf0) >> 4)); @@ -136,19 +153,41 @@ cellvol[10][bms] = (((getdat[16][bms] & 0x0f) << 8) | getdat[15][bms]); cellvol[11][bms] = ((getdat[17][bms] << 4) | ((getdat[16][bms] & 0xf0) >> 4)); for(int loop = 0;loop < (12); loop++){ - //表示する数値は(cellvol[loop] - 512)*1.5mV - pc.printf("Cell%2d = %5dmV\n", (loop) + (bms * 12) + 1, ((cellvol[loop][bms] - 512)+((cellvol[loop][bms] - 512)/2))); cellallvol += cellvol[loop][bms]; + // セル最低電圧 最高電圧判定 + if (cellMinVol > cellvol[loop][bms]) + { + cellMinVol = cellvol[loop][bms]; + } + if (cellMaxVol < cellvol[loop][bms]) + { + cellMaxVol = cellvol[loop][bms]; + } } } - pc.printf("CellALL = %5dmV\n", ((cellallvol - 512*(12 * BMS_NUM))+((cellallvol - 512*(12 * BMS_NUM))/2))); + //====================================================================== + // 制御基板との通信確立時に制御基板へ計測データを送信する + //====================================================================== + if( 1 == comFlag ){ + wait(0.05); + for (uint8_t bms = 0; bms < BMS_NUM; ++bms) + { + for(uint8_t cellNumForLoop = 0; cellNumForLoop < 12; cellNumForLoop++){ + pc.printf("%d\n", cellvol[cellNumForLoop][bms]); + } + } + pc.printf("%d\n", cellMinVol); + pc.printf("%d\n", cellMaxVol); + pc.printf("%d\n", cellallvol / ( BMS_NUM * 12 ) ); + comFlag = 0; + myled = 0; + } cmd = STCVADALL; spi.write(cmd); spi.write(CalcCRCLTC6803(&cmd, 1)); cs = 1; - myled = !myled; wait(0.4); } }