for checking multiple SOLID T sensors

Dependencies:   DevInterfaces AT30TSE75x I2Cinterfaces

Fork of AT30TSE752TST by wimbeaumont Project

Revision:
4:576303494244
Parent:
3:789bc6653f83
Child:
7:7f469b082fb2
diff -r 789bc6653f83 -r 576303494244 main.cpp
--- a/main.cpp	Tue Jan 17 13:44:20 2017 +0000
+++ b/main.cpp	Mon Jun 24 13:26:41 2019 +0000
@@ -1,13 +1,10 @@
 /** example program for the use of the AT30TSE7xx class 
  *
- *  V 0.4  : tested on the KL25z 
- * tested eeprom read/ write  full page / single byte  
- * temperature read 12 bit resolution
- * fix chip configuration.
+ *  check addresses connected, read them 
  * (C) Wim Beaumont Universiteit Antwerpen 2017 
  */ 
 
-#define AT30TSE753EXAMPLEVER "0.56"
+#define AT30TSE753EXAMPLEVER "0.21"
 
 #include "mbed.h"
 
@@ -49,85 +46,63 @@
 }        
 
 
-int main(void) {  //432109876543210 \0   
-   char str1[16] = "SOLTEMPERAT0230";
-   char str2[16] ;
-   char str3[16]=  "20170116...0230" ;
-   char resp[3];
+int main(void) { 
+
    // get the version of getVersion 
    getVersion gv;
    int addr=0;
    int i2cerr;
-   int cnt=0;
    
    printf("AT30TSE752  example program version %s, compile date %s time %s\n\r",AT30TSE753EXAMPLEVER,__DATE__,__TIME__);
    printf("getVersion :%s\n\r ",gv.getversioninfo());
-   printf("%s\n\r",str1);
-   
-   printf("give new addr "); scanf("%d", &addr);
-   if ( addr < 0 || addr > 15) addr=0;
-   fflush(stdin);
    
-   AT30TSE75x tid( i2cdev ,addr); 
-   printf ( "AT30SE75x version :%s\n\r ",tid.getversioninfo());
-   printf( "Taddr %x , Eaddr %x  subaddr %d\n\r ", tid.getTaddr(),tid.getEaddr(), addr);
-   i2cerr=tid.get_eeprom_protec();
-   if ( i2cerr ) { printf("ee-prom write protected \n\r");}
-   else { printf("ee-prom NOT write protected \n\r"); }
    
- 
    
-   i2cerr=tid.set_config();
-   if( i2cerr) printf("config not set  %d \n\r", i2cerr);
-   int configrd= tid.read_config( 0, &i2cerr);
-   printf( " config %x  I2cerr %d \n\r", configrd,i2cerr ); 
-   printf("write to eprom ?"); scanf("%s",resp);
+   AT30TSE75x tid[8] ={ AT30TSE75x( i2cdev ,0), AT30TSE75x( i2cdev ,1),AT30TSE75x( i2cdev ,2) ,AT30TSE75x( i2cdev ,3),
+                        AT30TSE75x( i2cdev ,4), AT30TSE75x( i2cdev ,5),AT30TSE75x( i2cdev ,6) ,AT30TSE75x( i2cdev ,7)};
+   bool addrfound[8];
+   for (int lc=0; lc <7 ;lc++) {
+        printf ( "AT30SE75x version :%s\n\r ",tid[lc].getversioninfo());
+        printf( "Taddr %x , Eaddr %x  subaddr %d\n\r ", tid[lc].getTaddr(),tid[lc].getEaddr(), addr);
+        if( tid[lc].getInitStatus() ){ printf("reading config registers failed \n\r");addrfound[lc]=false; } 
+        else {
+            addrfound[lc]=true;   
+            tid[lc].set_resolution(12 , i2cerr );
+            tid[lc].set_FaultTollerantQueue('6', i2cerr );
+            tid[lc].set_AlertPinPolarity(0,i2cerr);
+            tid[lc].set_AlarmThermostateMode(0,i2cerr);
+            tid[lc].set_config(i2cerr,0);            
+            int configrd= tid[lc].read_config( i2cerr, 0);
+            printf( " config %x  I2cerr %d \n\r", configrd,i2cerr ); 
+        }
+    }
    int pagenr=0;
-   int sernr;
-   if(resp[0] == 'y'){  
-    i2cerr= tid.write_eeprompage(str1, 16, 0, (uint8_t) pagenr++);
-    if(i2cerr) printf("eeprom write error %d\n\r",i2cerr);
-    printf("give serial nr to write "); scanf("%d",&sernr);
-    sprintf(str2,"%015d",sernr);
-    i2cerr= tid.write_eeprompage(str2, 16, 0, (uint8_t) pagenr++);
-    wait_ms(400); // give some time to write 
-    i2cerr= tid.write_eeprompage(str3, 16, 0, (uint8_t) pagenr);
-   }
-   wait_ms(400); // give some time to write 
-   //strcpy(str1,"newstr1");strcp(str2,"newstr2");strcp(str3,"newstr3");
-   bool fix=true;
+   const int nrstrs=4;
+   char str[nrstrs][16];
+    
    while(1) {
-    pagenr=0;
-    i2cerr=tid.read_eeprompage(str1, 16, 0, (uint8_t) pagenr++);
-    if(i2cerr) printf("eeprom read error %d \n\r",i2cerr);
-    
-    i2cerr=tid.read_eeprompage(str2, 16, 0, (uint8_t) pagenr++);
-    if(i2cerr) printf("eeprom read error %d \n\r",i2cerr);
-    i2cerr=tid.read_eeprompage(str3, 16, 0, (uint8_t) pagenr);
-    if(i2cerr) printf("eeprom read error %d \n\r",i2cerr);
-    str1[15]='\0';str2[15]='\0';str3[15]='\0'; //make sure it ends 
-    printf("eeprom content page %d :\n\r %s  %s  %s \n\r",pagenr,str1 ,str2 ,str3 );
-    //print_buf_hex( str1,16);
-    if ( fix) {
-        printf("protect eeprom ?") ; scanf("%s",resp);
-        if(resp[0] == 'y'){  
-            i2cerr=tid.protect_eeprom();
-            if(i2cerr) printf("eeprom  protect failed %d \n\r", i2cerr);
+    for (int lc=0; lc<7 ;lc++) {
+      if( addrfound[lc]) { 
+        pagenr=0;
+        for ( int sc=0 ; sc <nrstrs;sc++){
+            i2cerr=tid[lc].read_eeprompage(str[sc], 16, 0, (uint8_t) pagenr++);
+            if(i2cerr) printf("eeprom read error %d addr %d  \n\r",i2cerr,lc);
+        }
+        
+        for (int sc=0 ; sc < nrstrs;sc ++) { 
+            str[sc][15]='\0'; //make sure it ends
+            printf("%d:%15s ",sc,str[sc]);
         }
-        // fix=false;
-    }
-    char singlechar;
-    i2cerr=tid.read_eeprombyte(singlechar, 3, (uint8_t) pagenr); 
-    if(i2cerr) printf("eeprom read error %d \n\r",i2cerr);
-    printf("third char is : %c\n\r",singlechar);
-    wait_ms(1000);    
-    float Tmp= tid.get_temperature(&i2cerr);      
-    printf ("%d:Temp = %f I2cerr %d \n\r",cnt++, Tmp, i2cerr);
-   
-
-  }
-  
+        // temperature  correction
+        str[3][7]='\0';
+        float tempcor=atof(str[3]);
+        if ( tempcor < -2.5 || tempcor > 2.5) tempcor=0.0; 
+        float Tmp= tid[lc].get_temperature(i2cerr);      
+        printf ("T=%f %f I2cerr %d addr %d\n\r", Tmp,Tmp+tempcor, i2cerr,lc);
+       } // if
+    } // for 
+    printf("\n\r");
+    wait_ms(500);
+  } //while
     
-    // never reach this   
-    return 1;
 }