Initial rough copy

Dependencies:   BQ76PL536A mbed

Revision:
2:6c664dcbd052
Parent:
1:af7a249bd2b2
diff -r af7a249bd2b2 -r 6c664dcbd052 main.cpp
--- a/main.cpp	Thu Jul 30 01:55:19 2020 +0000
+++ b/main.cpp	Sun Jul 25 18:23:02 2021 +0000
@@ -1,8 +1,18 @@
+///-----------------------------------------------------------------
+///   Description:      BQ76PL536A Driver
+///   Author:           David Wahl
+///   Date:             13-JUL-2021
+///   Notes:            Initial release
+///
+///   Revision History:
+///   Name:           Date:        Description:
+///-----------------------------------------------------------------
+
 #include "mbed.h"
 #include "bq76pl536a.h"
 
 // a SPI sub-class that provides a constructed default
-class SPIPreInit : public SPI
+/*class SPIPreInit : public SPI
 {
 public:
     SPIPreInit(PinName mosi, PinName miso, PinName sclk, int freq, int bits, int mode) : SPI(mosi, miso, sclk)
@@ -10,7 +20,7 @@
         frequency(freq);
         format(bits, mode);
     };
-};
+};*/
 
 //SPIPreInit spi(PA_7, PA_6, A1, 500000, 8, 1);
 SPI spi(PA_7, PA_6, A1);
@@ -23,7 +33,7 @@
 BQ76PL536A bq_pack(spi, PB_0, numDev, 4000, 3000, 5, true);
 
 Serial pc(SERIAL_TX, SERIAL_RX);
-DigitalOut cs(D3);
+DigitalOut cs(D3); // Chip select for BQ76PL536A
 
 int main()
 {
@@ -31,34 +41,20 @@
     //spi.format(8,1);
     //spi.frequency(50000);
 
-    //spi.lock();
-    //cs = 0;
-    //wait_ms(1);
-
-    //cs = 1;
-
-    
-    //wait_ms(1);
-    
-    //cs = 0;
-    //spi.write(0x01);
-    //spi.write(0x3b);
-    //spi.write(0x01);
-    //spi.write(0x02);
-    //cs=1;
-    //spi.unlock();
-
-    //   spi.write(BROADCAST_ADDR);
-    //spi.write(RESET_REG);
-    //spi.write(BQ76PL536A_RESET);
-
 
     for (int i = 0; i<numDev; i++) {
         numCells +=attachedCells[i];
     }
+
+    float cellVolts[5];
+
     pc.baud(115200);
     pc.printf("Starting up...\r\n");
-    bq_pack.devStatus();
+
+    //wait_us(6);
+    bq_pack.readAll(1);
+    bq_pack.write(1,ADC_CONTROL_REG,bq_pack.bqPackData[ADC_CONTROL_REG]|5);
+
     //pc.printf("Status: %u\r\n",bq_pack.devStatus());
     //pc.printf("COV: %u CUV: %u, numDev: %d numCells: %d\r\n", bq_pack.cov, bq_pack.cuv, bq_pack.numDev, numCells);
     //pc.printf("%u %u %u %u %u\r\n", bq_pack.attachedCells[0], bq_pack.attachedCells[1], bq_pack.attachedCells[2], bq_pack.attachedCells[3], bq_pack.attachedCells[4]);
@@ -66,25 +62,32 @@
 
     while(1) {
         wait(1);
+        bq_pack.adcConvert();
+
+        wait_us(500);
+        bq_pack.readAll(1);
+
+        /*for (int i = 0; i <5; i++) {
+            cellVolts[i] = bq_pack.cellVolts(bq_pack.bqPackData[VCELL1_L_REG+(i<<1)],bq_pack.bqPackData[VCELL1_L_REG+(i<<1)|1]);
+        }
+
+        for (int i = 0; i <5; i++) {
+            pc.printf("%.3f",cellVolts[i]);
+            if (i!=4) {
+                pc.printf(" ,");
+            } else {
+                pc.printf("\r\n");
+            }
+        }*/
+
+
+
+        pc.printf(" %.3f",bq_pack.cellVolts(bq_pack.bqPackData[VCELL1_L_REG],bq_pack.bqPackData[VCELL1_L_REG+1]));
+        pc.printf(" %.3f",bq_pack.cellVolts(bq_pack.bqPackData[VCELL2_L_REG],bq_pack.bqPackData[VCELL2_L_REG+1]));
+        pc.printf(" %.3f",bq_pack.cellVolts(bq_pack.bqPackData[VCELL3_L_REG],bq_pack.bqPackData[VCELL3_L_REG+1]));
+        pc.printf(" %.3f",bq_pack.cellVolts(bq_pack.bqPackData[VCELL4_L_REG],bq_pack.bqPackData[VCELL4_L_REG+1]));
+        pc.printf(" %.3f\r\n",bq_pack.cellVolts(bq_pack.bqPackData[VCELL5_L_REG],bq_pack.bqPackData[VCELL5_L_REG+1]));
         //u8t addr_ctrl = bq_pack.readRegister(1, ADDRESS_CONTROL_REG);
 
-        //bq_pack.readCells();
-
-        //pc.printf("%u %u %u %u %u\r\n", bq_pack.cellVolts[0], bq_pack.cellVolts[1], bq_pack.cellVolts[2], bq_pack.cellVolts[3], bq_pack.cellVolts[4]);
-
-        //pc.printf("%u\r\n",bq_pack.devStatus());
-        /*u8t data[8];
-        bq_pack.adcConvert();
-        wait_ms(10);
-        cs = 0;
-        spi.write(1);
-        spi.write(VCELL1_L_REG);
-        spi.write(8);
-        for (int i = 0; i<8; i++)
-        {
-            data[i] = spi.write(0x00);
-        }
-        cs = 1;
-        pc.printf("%u %u %u %u\r\n", (data[0]<<8)|data[1], (data[2]<<8)|data[3], (data[4]<<8)|data[5], (data[6]<<8)|data[7]);*/
     }
 }