Dragica Stoiljkovic / Mbed 2 deprecated BMS_LV

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
dragica
Date:
Fri Mar 20 23:40:18 2020 +0000
Parent:
0:f49f58e4b0c9
Commit message:
21.03.2020.(2)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 20 23:15:36 2020 +0000
+++ b/main.cpp	Fri Mar 20 23:40:18 2020 +0000
@@ -225,7 +225,7 @@
     return WriteFrame(bID, wAddr, &bReturn, 1, FRMWRT_SGL_R);
 }
 // eg: ReadReg(nDev_ID,0x0207,bFrame,12, 0, FRMWRT_SGL_R)
-int ReadReg(BYTE DevID, uint16_t wAddr, void * bufferData, BYTE numDATAb, uint32_t dwTimeOut, BYTE FRMWRT_SGL_R)
+int ReadReg (BYTE DevID, uint16_t wAddr, void * bufferData, BYTE numDATAb, uint32_t dwTimeOut, BYTE FRM)
 
 {
     //Kopija Martinog koda
@@ -278,20 +278,38 @@
         }
     }
 }
-
+void waitFrame(){
+    while(!full);
+    full=false;
+    for(int i = 0;i<rdLen;i++){
+        pc1.printf("%X ",recBuff[i]);
+    }
+    
+    pc1.printf("\n\n- - - VOLTAGE - - -\n");
+    for(int i = 1; i < recBuff[0] - 1; i += 2){
+               
+        int voltage = recBuff[i+1];
+        voltage |= (recBuff[i]) << 8;
+        double vol = ((double)voltage)/65536.0 * 5.0;
+        pc1.printf("CELL[%d] = %.6f V\n",(recBuff[0] - 1)/2 -(i-1)/2,vol);
+    }
+      
+    pc1.printf("\n");
+}
 
 int main() 
 {
+   uint32_t  wTemp = 0;
    pc.attach(&callback);//sta radi callback?
    
-   sciSetBaudrate(scilinREG,250000);
+   //sciSetBaudrate(scilinREG, 250000);
    pc1.printf("INICIJALIZACIJA START \n");
    wakeUp();
    
-   sciSetBaudrate(scilinREG,250000);
-   CommReset(); 
+   //sciSetBaudrate(scilinREG,250000);
+   //CommReset(); 
    WriteReg(0,COMM_CTRL,0x3C3C,2, FRMWRT_ALL_NR);//setting the baud rate to device
-   sciSetBaudrate(scilinREG,1000000);
+   //sciSetBaudrate(scilinREG,1000000);
    
    WriteReg(0,ECC_TEST,0x00,1, FRMWRT_ALL_NR); //dummy write to the ECC_TESTregisterto syncthe DLL
    
@@ -301,7 +319,7 @@
    
    WriteReg(0,CONFIG, 0x01 ,1, FRMWRT_SGL_NR);//If there is only one device,you can instead do one command to assign the device as both the base AND top of stack(set CONFIG to 0x01)
    //****
-   ReadReg(0, uint16_t wAddr, void * bufferData, 1, uint32_t dwTimeOut, FRMWRT_SGL_R)//dummy read of ECC_TEST DORADITI!
+   //ReadReg(0, uint16_t wAddr, void * bufferData, 1, uint32_t dwTimeOut, FRMWRT_SGL_R)//dummy read of ECC_TEST DORADITI!
    //****
    
    WriteReg(0, COMM_TO, 0x56, 1, FRMWRT_ALL_NR);//Setting Communications Timeout (10 minute short communication timeout, sleep mode on long communication timeout, long timeout length of 30 minutes)
@@ -342,7 +360,7 @@
    
    pc1.printf("Response? \n");
    // read device ID to see if there is a response
-   ReadReg(0, 10, &wTemp, 1, 0);
+   ReadReg(0, 10, &wTemp, 1, 0,FRMWRT_SGL_R );
    wait_ms(10);
    wait(1);
    
@@ -368,32 +386,31 @@
    */
    
    WriteReg(0, 0x109, 0x3F, 1, FRMWRT_ALL_NR);// enables ADC for all 6 cell channels
-   delayms(5);// ensure proper settling time for best accuracy
+   wait_ms(5);// ensure proper settling time for best accuracy
    
    
    //WHICHEVER WE NEED
    //One-Shot ADC Conversions
    WriteReg(0, CONTROL2, 0x01, 1, FRMWRT_ALL_NR);//set the CELL_ADC_GO bit
-   delayms(5);//delay for ADC accuracy
+   wait_ms(5);//delay for ADC accuracy
    
    //DORADI!
-   ReadReg(0, 0x215, void * bufferData, 12, 0, FRMWRT_SGL_R);// will return 6 overhead byte sand 12 data bytes per device, highest device address responds first
-   delayms(1);
+   //ReadReg(0, 0x215, void * bufferData, 12, 0, FRMWRT_SGL_R);// will return 6 overhead byte sand 12 data bytes per device, highest device address responds first
+   wait_ms(1);
    
    //Continuous ADC Conversions
    WriteReg(0, 0x25, 0x0A, 1, FRMWRT_ALL_NR);// enable continuous conversion with 5ms conversion interval
    WriteReg(0, CONTROL2, 0x01, 1, FRMWRT_ALL_NR);//set the CELL_ADC_GO bit
-   delayms(5);//delay for ADC accuracy
+   wait_ms(5);//delay for ADC accuracy
    //da li je ovo ispod isto sto i Martin waitFrame? Ako jeste staviti ga u posebnu funkciju, ako nije proveriti da li je uopste potrebno
-   ReadReg(0, 0x215, void * bufferData, 12, 0, FRMWRT_SGL_R);// will return 6 overhead byte sand 12 data bytes per device, highest device address responds first
-   delayms(1);//ISTA STVAR KAO IZNAD KOD ONE-SHOT
+   //ReadReg(0, 0x215, void * bufferData, 12, 0, FRMWRT_SGL_R);// will return 6 overhead byte sand 12 data bytes per device, highest device address responds first
+   wait_ms(1);//ISTA STVAR KAO IZNAD KOD ONE-SHOT
    //martin deo koda
    while (1) {
         pc1.printf("Main Code \n");
         wait(2);
-        nDev_ID = 0;
         //*****
-        WriteReg(nDev_ID, 2, 0x20, 1, FRMWRT_SGL_R); // send read sampled values command, OVO TREBA PROMENITI AKO VEC ZADRZAVAS OVAJ KOD!!!!!
+        WriteReg(0, 2, 0x20, 1, FRMWRT_SGL_R); // send read sampled values command, OVO TREBA PROMENITI AKO VEC ZADRZAVAS OVAJ KOD!!!!!
         //*****
         waitFrame();
         if(bmsFault)