branch to test I2C

Dependencies:   ADBMS2950

Revision:
9:0a4828d32e76
Parent:
7:540ecfbe1a26
--- a/program/src/adbms_2950.cpp	Wed Sep 23 14:58:29 2020 +0000
+++ b/program/src/adbms_2950.cpp	Mon May 24 02:38:00 2021 +0000
@@ -24,7 +24,7 @@
 #include "adbms2950.h"
 #include "application.h"
 #ifdef MBED
-extern Serial pc;
+//extern Serial pc;
 #endif /* MBED */
 /*******************************************************************************
 * @brief Setup Variables
@@ -463,14 +463,14 @@
     if(option == 1)
     {
 #ifdef MBED
-      pc.printf("IC[%d]: Select GPO Pin Drive to High\n", (cic+1));
-      pc.printf("0 : GPO1 \n");
-      pc.printf("1 : GPO2 \n");
-      pc.printf("2 : GPO3 \n");
-      pc.printf("3 : GPO4 \n");
-      pc.printf("4 : GPO5 \n");
-      pc.printf("5 : GPO6 \n");
-      pc.scanf("%d",&gpo);
+//      pc.printf("IC[%d]: Select GPO Pin Drive to High\n", (cic+1));
+//      pc.printf("0 : GPO1 \n");
+//      pc.printf("1 : GPO2 \n");
+//      pc.printf("2 : GPO3 \n");
+//      pc.printf("3 : GPO4 \n");
+//      pc.printf("4 : GPO5 \n");
+//      pc.printf("5 : GPO6 \n");
+//      pc.scanf("%d",&gpo);
 #else
       printf("IC[%d]: Select GPO Pin Drive to High\n", (cic+1));
       printf("0 : GPO1 \n");
@@ -486,13 +486,13 @@
     else if(option == 2)
     {
 #ifdef MBED
-      pc.printf("IC[%d]: Select GPO Pin Drive to Low\n", (cic+1));
-      pc.printf("0 : GPO1 \n");
-      pc.printf("1 : GPO2 \n");
-      pc.printf("2 : GPO3 \n");
-      pc.printf("3 : GPO4 \n");
-      pc.printf("4 : GPO5 \n");
-      pc.printf("5 : GPO6 \n");
+//      pc.printf("IC[%d]: Select GPO Pin Drive to Low\n", (cic+1));
+//      pc.printf("0 : GPO1 \n");
+//      pc.printf("1 : GPO2 \n");
+//      pc.printf("2 : GPO3 \n");
+//      pc.printf("3 : GPO4 \n");
+//      pc.printf("4 : GPO5 \n");
+//      pc.printf("5 : GPO6 \n");
       scanf("%d",&gpo);
 #else
       printf("IC[%d]: Select GPO Pin Drive to Low\n", (cic+1));
@@ -527,23 +527,27 @@
     for(uint8_t cic = 0; cic < tIC; cic++)
     {
       ic[cic].tx_cfga.refon = PWR_UP;
-      ic[cic].tx_cfga.gpio = 0xF;            /*!< All gpios pull down disable */
+      ic[cic].tx_cfga.gpio = 0xF;            /*All gpios pull down disable */
 
-      ic[cic].tx_comm.icomm[0] = 0x8;        /*!< Generate a CSBM Low signal */
-      ic[cic].tx_comm.fcomm[0] = 0x0;        /*!< Holds CSBM low */
-      ic[cic].tx_comm.icomm[1] = 0x8;        /*!< Generate a CSBM Low signal */
-      ic[cic].tx_comm.fcomm[1] = 0x9;        /*!< CSBM high */
-      ic[cic].tx_comm.icomm[2] = 0xF;        /*!< No transmit */
-      ic[cic].tx_comm.fcomm[2] = 0x9;        /*!< CSBM high */
+      ic[cic].tx_comm.icomm[0] = 0x8;        /*Generate a CSBM Low signal */
+      ic[cic].tx_comm.fcomm[0] = 0x0;        /*Holds CSBM low */
+      ic[cic].tx_comm.icomm[1] = 0x8;        /*Generate a CSBM Low signal */
+      ic[cic].tx_comm.fcomm[1] = 0x9;        /*CSBM high */
+      ic[cic].tx_comm.icomm[2] = 0xF;        /*No transmit */
+      ic[cic].tx_comm.fcomm[2] = 0x9;        /*CSBM high */
 
-      ic[cic].tx_comm.data[0] = 0x55;        /*!< data1, write the data on COMM register (D0,D1,D2) for sending the data on SPI bus*/
-      ic[cic].tx_comm.data[1] = 0xAA;        /*!< data2 */
-      ic[cic].tx_comm.data[2] = 0xFF;        /*!< data3 */
+      ic[cic].tx_comm.data[0] = 0x55;        /*data1, write the data on COMM register (D0,D1,D2) for sending the data on SPI bus*/
+      ic[cic].tx_comm.data[1] = 0xAA;        /*data2 */
+      ic[cic].tx_comm.data[2] = 0xFF;        /*data3 */
     }
+    
     adBmsWakeupIc(tIC);
+    /*Setting GPIO configurations to disable pull down*/
     adBmsWriteData(tIC, &ic[0], WRCFGA, Config, A);
     adBmsReadData(tIC, &ic[0], RDCFGA, Config, A);
-    adBmsReadData(tIC, &ic[0], RDSTATE, Status, E); /*!< Read Status E for gpio status*/
+    /*Read Status E for gpio status*/
+    adBmsReadData(tIC, &ic[0], RDSTATE, Status, E);
+    /**/
     adBmsWriteData(tIC, &ic[0], WRCOMM, Comm, NONE);
     adBms2950_Stcomm();
     adBmsReadData(tIC, &ic[0], RDCOMM, Comm, NONE);
@@ -598,26 +602,34 @@
 *******************************************************************************
 * @brief GPIO I2C Write on the GPIO Port.
 *        Refer to the data sheet.
+*        This is an example using eeprom 24AA01 
 *******************************************************************************
 */
 void adi2950_gpio_i2c_write_to_slave(uint8_t tIC, cell_asic *ic)
 {
+    uint8_t user_data = 0;
+    
+    printMsg("Enter a number to be written to EEPROM [0-255]");
+    readUserData(&user_data);
+    
     for(uint8_t cic = 0; cic < tIC; cic++)
     {
       ic[cic].tx_cfga.refon = PWR_UP;
-      ic[cic].tx_cfga.gpio = 0xF;            /*! All gpios pull down disable*/
+      ic[cic].tx_cfga.gpio = 0xF;            /*All gpios pull down disable*/
 
-      ic[cic].tx_comm.icomm[0] = 0x6;        /*!< Generate a START Signal on I2C Port Followed by Data Transmission */
-      ic[cic].tx_comm.fcomm[0] = 0x8;        /*!< Master Generated an NACK Signal*/
-      ic[cic].tx_comm.icomm[1] = 0x0;        /*!<! Blank, SDA Held Low Between Bytes*/
-      ic[cic].tx_comm.fcomm[1] = 0x8;        /*!< Master Generated an NACK Signal*/
-      ic[cic].tx_comm.icomm[2] = 0x0;        /*!< Blank, SDA Held Low Between Bytes*/
-      ic[cic].tx_comm.fcomm[2] = 0x9;        /*!< Master Generated a NACK Signal, Master Generated a STOP Signal*/
+      ic[cic].tx_comm.icomm[0] = 0x6;        /*Generate a START Signal on I2C Port Followed by Data Transmission */
+      ic[cic].tx_comm.fcomm[0] = 0x8;        /*Master Generated an NACK Signal*/
+      ic[cic].tx_comm.icomm[1] = 0x0;        /*Blank, SDA Held Low Between Bytes*/
+      ic[cic].tx_comm.fcomm[1] = 0x8;        /*Master Generated an NACK Signal*/
+      ic[cic].tx_comm.icomm[2] = 0x0;        /*Blank, SDA Held Low Between Bytes*/
+      ic[cic].tx_comm.fcomm[2] = 0x9;        /*Master Generated a NACK Signal, Master Generated a STOP Signal*/
 
-      ic[cic].tx_comm.data[0] = 0xA0;        /*!< data1, write the data on COMM register (D0,D1,D2) for sending the data on I2C bus*/
-      ic[cic].tx_comm.data[1] = 0x00;        /*!< data2*/
-      ic[cic].tx_comm.data[2] = 0x25;        /*!< data3*/
+/*write the data on COMM register (D0,D1,D2) for sending the data on I2C bus*/
+      ic[cic].tx_comm.data[0] = 0xA0;   /*Control byte*/
+      ic[cic].tx_comm.data[1] = 0x00;   /*Word Address*/
+      ic[cic].tx_comm.data[2] = user_data;   /*Data byte*/
     }
+    
     adBmsWakeupIc(tIC);
     adBmsWriteData(tIC, &ic[0], WRCFGA, Config, A);
     adBmsReadData(tIC, &ic[0], RDCFGA, Config, A);
@@ -625,18 +637,20 @@
     adBmsWriteData(tIC, &ic[0], WRCOMM, Comm, NONE);
     adBms2950_Stcomm();
     adBmsReadData(tIC, &ic[0], RDCOMM, Comm, NONE);
-    printMsg("GPIO I2C Write data to Slave completed");
+
     printWriteConfig(tIC, &ic[0], Config, A);
     printReadConfig(tIC, &ic[0], Config, A);
     printStatus(tIC, &ic[0], Status, E);
     printWriteCommData(tIC, &ic[0], Comm);
     printReadCommData(tIC, &ic[0], Comm);
+    printMsg("GPIO I2C Data written to EEPROM");
 }
 
 /**
 *******************************************************************************
 * @brief GPIO I2C Read from the GPIO Ports(using eeprom 24AA01)
 *        Refer to the data sheet.
+*        This is an example using eeprom 24AA01
 *******************************************************************************
 */
 void adi2950_gpio_i2c_read_from_slave(uint8_t tIC, cell_asic *ic)
@@ -644,36 +658,35 @@
     for(uint8_t cic = 0; cic < tIC; cic++)
     {
       ic[cic].tx_cfga.refon = PWR_UP;
-      ic[cic].tx_cfga.gpio = 0xF;            /*!< All gpios pull down disable*/
+      ic[cic].tx_cfga.gpio = 0xF;            /*All gpios pull down disable*/
 
-      ic[cic].tx_comm.icomm[0] = 0x6;        /*!< Generate a START Signal on I2C Port Followed by Data Transmission*/
-      ic[cic].tx_comm.fcomm[0] = 0x8;        /*!< Master Generated an NACK Signal*/
-      ic[cic].tx_comm.icomm[1] = 0x0;        /*!< Blank, SDA Held Low Between Bytes*/
-      ic[cic].tx_comm.fcomm[1] = 0x8;        /*!< Master Generated an NACK Signal*/
-      ic[cic].tx_comm.icomm[2] = 0x6;        /*!< Blank, SDA Held Low Between Bytes*/
-      ic[cic].tx_comm.fcomm[2] = 0x8;        /*!< Master Generated a NACK Signal, Master Generated a STOP Signal*/
+      ic[cic].tx_comm.icomm[0] = 0x6;        /*Generate a START Signal on I2C Port Followed by Data Transmission*/
+      ic[cic].tx_comm.fcomm[0] = 0x8;        /*Master Generated an NACK Signal*/
+      ic[cic].tx_comm.icomm[1] = 0x0;        /*Blank, SDA Held Low Between Bytes*/
+      ic[cic].tx_comm.fcomm[1] = 0x8;        /*Master Generated an NACK Signal*/
+      ic[cic].tx_comm.icomm[2] = 0x6;        /*Generate a START Signal on I2C Port Followed by Data Transmission*/
+      ic[cic].tx_comm.fcomm[2] = 0x8;        /*Master Generated a NACK Signal, Master Generated a STOP Signal*/
 
-      ic[cic].tx_comm.data[0] = 0xA0;        /*!<data1*/
-      ic[cic].tx_comm.data[1] = 0x00;        /*!<data2*/
-      ic[cic].tx_comm.data[2] = 0xA1;        /*!<data3*/
+      ic[cic].tx_comm.data[0] = 0xA0;        /*control byte W*/
+      ic[cic].tx_comm.data[1] = 0x00;        /*Word address*/
+      ic[cic].tx_comm.data[2] = 0xA1;        /*Control byte R*/
     }
+    
     /***************************** Write to slave devcie *****************/
+    
     adBmsWakeupIc(tIC);
-    adBmsWriteData(tIC, &ic[0], WRCFGA, Config, A);
-    adBmsReadData(tIC, &ic[0], RDCFGA, Config, A);
-    adBmsReadData(tIC, &ic[0], RDSTATE, Status, E); /*!< Read Status E for gpio status*/
+//    adBmsWriteData(tIC, &ic[0], WRCFGA, Config, A);
+//    adBmsReadData(tIC, &ic[0], RDCFGA, Config, A);
+//    adBmsReadData(tIC, &ic[0], RDSTATE, Status, E); /*!< Read Status E for gpio status*/
     adBmsWriteData(tIC, &ic[0], WRCOMM, Comm, NONE);
     adBms2950_Stcomm();
-    printWriteConfig(tIC, &ic[0], Config, A);
-    printReadConfig(tIC, &ic[0], Config, A);
+//    printWriteConfig(tIC, &ic[0], Config, A);
+//    printReadConfig(tIC, &ic[0], Config, A);
     printWriteCommData(tIC, &ic[0], Comm);
-    printStatus(tIC, &ic[0], Status, E);
+//    printStatus(tIC, &ic[0], Status, E);
 
     for(uint8_t cic = 0; cic < tIC; cic++)
     {
-      ic[cic].tx_cfga.refon = PWR_UP;
-      ic[cic].tx_cfga.gpio = 0xF;            /*!< All gpios pull down disable */
-
       ic[cic].tx_comm.icomm[0] = 0x0;        /*!< SDA held low */
       ic[cic].tx_comm.fcomm[0] = 0x9;        /*!<Slave NACk+ master STOP */
       ic[cic].tx_comm.icomm[1] = 0x7;        /*!< SDA held high */
@@ -687,13 +700,16 @@
     }
     /***************************** Read from slave devcie *****************/
     adBmsWakeupIc(tIC);
-    adBmsWriteData(tIC, &ic[0], WRCFGA, Config, A);
-    adBmsReadData(tIC, &ic[0], RDSTATE, Status, E); /*!< Read Status E for gpio status*/
+    adBmsWriteData(tIC, &ic[0], WRCOMM, Comm, NONE);
     adBms2950_Stcomm();
     adBmsReadData(tIC, &ic[0], RDCOMM, Comm, NONE);
-    printMsg("GPIO I2C Read data from Slave completed");
+    printWriteCommData(tIC, &ic[0], Comm);
     printReadCommData(tIC, &ic[0], Comm);
-    printStatus(tIC, &ic[0], Status, E);
+    printMsg("GPIO I2C read data from slave completed.");    
+    for(uint8_t cic = 0; cic < tIC; cic++)
+    {
+        printData(ic[cic].rx_comm.data[0]);
+    }
 }
 
 /**