branch to test I2C

Dependencies:   ADBMS2950

Files at this revision

API Documentation at this revision

Comitter:
sgarg2
Date:
Mon May 24 02:38:00 2021 +0000
Parent:
8:53d90d63f0e7
Commit message:
Add I2C test for EEPROM

Changed in this revision

ADBMS2950.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
program/inc/print_result.h Show annotated file Show diff for this revision Revisions of this file
program/src/adbms_2950.cpp Show annotated file Show diff for this revision Revisions of this file
program/src/application.cpp Show annotated file Show diff for this revision Revisions of this file
program/src/print_result.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 53d90d63f0e7 -r 0a4828d32e76 ADBMS2950.lib
--- a/ADBMS2950.lib	Wed Sep 23 14:58:29 2020 +0000
+++ b/ADBMS2950.lib	Mon May 24 02:38:00 2021 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/AnalogDevices/code/ADBMS2950/#17a67f00af89
+https://os.mbed.com/teams/AnalogDevices/code/ADBMS2950/#c19259b5b64f
diff -r 53d90d63f0e7 -r 0a4828d32e76 mbed-os.lib
--- a/mbed-os.lib	Wed Sep 23 14:58:29 2020 +0000
+++ b/mbed-os.lib	Mon May 24 02:38:00 2021 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#3ab72c71b75cb9cb91160a54fba22ec43b036ed2
+https://github.com/ARMmbed/mbed-os/#0be7685a27f28c02737f42055f4a9c182a7b483c
diff -r 53d90d63f0e7 -r 0a4828d32e76 program/inc/print_result.h
--- a/program/inc/print_result.h	Wed Sep 23 14:58:29 2020 +0000
+++ b/program/inc/print_result.h	Mon May 24 02:38:00 2021 +0000
@@ -45,7 +45,9 @@
 void printMsg(char *msg);
 void printPollAdcConvTime(int count);
 void printResultCount(int count);
+void printData(uint8_t data);
 void readUserInupt(int *user_command);
+void readUserData(uint8_t *data);
 float getVoltage(int data);
 float getCurrent(uint32_t data);
 float getAvgCurrent(uint32_t data);
diff -r 53d90d63f0e7 -r 0a4828d32e76 program/src/adbms_2950.cpp
--- 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]);
+    }
 }
 
 /**
diff -r 53d90d63f0e7 -r 0a4828d32e76 program/src/application.cpp
--- a/program/src/application.cpp	Wed Sep 23 14:58:29 2020 +0000
+++ b/program/src/application.cpp	Mon May 24 02:38:00 2021 +0000
@@ -229,9 +229,6 @@
 
    case 34:
     adi2950_gpio_i2c_write_to_slave(TOTAL_IC, &IC[0]);
-    break;
-
-   case 35:
     adi2950_gpio_i2c_read_from_slave(TOTAL_IC, &IC[0]);
     break;
 
diff -r 53d90d63f0e7 -r 0a4828d32e76 program/src/print_result.cpp
--- a/program/src/print_result.cpp	Wed Sep 23 14:58:29 2020 +0000
+++ b/program/src/print_result.cpp	Mon May 24 02:38:00 2021 +0000
@@ -750,8 +750,8 @@
   pc.printf("Start ADI2 Conversion(Continuous): 6                         |Set Reset GPO Pins: 31              \n");
   pc.printf("Start ADI1 Redundant Conversion(Single Shot): 7              |GPIO SPI Write to Slave: 32         \n");
   pc.printf("Start ADI1 Redundant Conversion(Continuous): 8               |GPIO SPI Read from Slave: 33        \n");
-  pc.printf("Read CR, VBAT & IVBAT Registers(Single Shot): 9              |GPIO I2C Write to Slave: 34         \n");
-  pc.printf("Read CR, VBAT & IVBAT Registers(Continuous): 10              |GPIO I2C Read from Slave: 35        \n");
+  pc.printf("Read CR, VBAT & IVBAT Registers(Single Shot): 9              |GPIO I2C Write/Read to Slave: 34    \n");
+  pc.printf("Read CR, VBAT & IVBAT Registers(Continuous): 10              |                                    \n");
   pc.printf("Read Overcurrent ADC Register(Single Shot): 11               |                                    \n");
   pc.printf("Read Overcurrent ADC Register(Continuous): 12                |                                    \n");
   pc.printf("Read Average CR, VBAT & IVBAT Registers(Single Shot): 13     |                                    \n");
@@ -1500,8 +1500,8 @@
   printf("Start ADI2 Conversion(Continuous): 6                         |Set Reset GPO Pins: 31              \n");
   printf("Start ADI1 Redundant Conversion(Single Shot): 7              |GPIO SPI Write to Slave: 32         \n");
   printf("Start ADI1 Redundant Conversion(Continuous): 8               |GPIO SPI Read from Slave: 33        \n");
-  printf("Read CR, VBAT & IVBAT Registers(Single Shot): 9              |GPIO I2C Write to Slave: 34         \n");
-  printf("Read CR, VBAT & IVBAT Registers(Continuous): 10              |GPIO I2C Read from Slave: 35        \n");
+  printf("Read CR, VBAT & IVBAT Registers(Single Shot): 9              |GPIO I2C Write/Read to Slave: 34    \n");
+  printf("Read CR, VBAT & IVBAT Registers(Continuous): 10              |                                    \n");
   printf("Read Overcurrent ADC Register(Single Shot): 11               |                                    \n");
   printf("Read Overcurrent ADC Register(Continuous): 12                |                                    \n");
   printf("Read Average CR, VBAT & IVBAT Registers(Single Shot): 13     |                                    \n");
@@ -1589,6 +1589,26 @@
 
 /**
 *******************************************************************************
+* Function: print Data
+* @brief Print Data.
+*
+* @details This function prints a Data of type int.
+*
+* @return None
+*
+*******************************************************************************
+*/
+void printData(uint8_t data)
+{
+#ifdef MBED
+  pc.printf("Read Data:%d\n", data);
+#else /* IAR */
+  printf("Read Data:%d\n", data);
+#endif /* MBED */
+}
+
+/**
+*******************************************************************************
 * Function: readUserInupt
 * @brief Read command input & print into console.
 *
@@ -1611,6 +1631,26 @@
 
 /**
 *******************************************************************************
+* Function: readUserData
+* @brief Read data byte & print into console.
+*
+* @return None
+*
+*******************************************************************************
+*/
+void readUserData(uint8_t *data)
+{
+#ifdef MBED
+    pc.scanf("%d", data);
+    pc.printf("Entered data:%d\n", *data);
+#else /* IAR */
+    scanf("%d", data);
+    printf("Entered data:%d\n", *data);
+#endif /* MBED */
+}
+
+/**
+*******************************************************************************
 * Function: getVoltage
 * @brief Get Voltage with multiplication factor.
 *