test program for the AT30TSE75X class

Dependencies:   AT30TSE75x DevInterfaces I2Cinterfaces mbed

Fork of MCP4728test by wimbeaumont Project

This is a program to use the AT30TSE752 with MBED . The program is used to test this device as temperature probes for the the SOLID project. It also is able to write to the ee-prom and is able to write protect the ee-prom and unprotect.

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Tue Jan 17 18:10:31 2017 +0000
Parent:
3:789bc6653f83
Commit message:
tested also unprotect function

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 789bc6653f83 -r 4d20444d5116 main.cpp
--- a/main.cpp	Tue Jan 17 13:44:20 2017 +0000
+++ b/main.cpp	Tue Jan 17 18:10:31 2017 +0000
@@ -7,7 +7,7 @@
  * (C) Wim Beaumont Universiteit Antwerpen 2017 
  */ 
 
-#define AT30TSE753EXAMPLEVER "0.56"
+#define AT30TSE753EXAMPLEVER "0.63"
 
 #include "mbed.h"
 
@@ -36,6 +36,8 @@
 MBEDI2CInterface* mbedi2cp=  &mbedi2c ;
 I2CInterface* i2cdev= mbedi2cp;
 
+DigitalInOut  CntrA1(PTD1, PIN_INPUT ,  PullNone,0);
+DigitalInOut  CntrA2(PTD3, PIN_INPUT ,  PullNone,0);
 Serial pc(USBTX, USBRX);
 
 void print_buf_hex( char *data, int length){
@@ -50,9 +52,10 @@
 
 
 int main(void) {  //432109876543210 \0   
-   char str1[16] = "SOLTEMPERAT0230";
+   char str1[16] = "SOLTEMPERAT0231";
    char str2[16] ;
-   char str3[16]=  "20170116...0230" ;
+   char str4[16] ;
+   char str3[16]=  "20170117...0230" ;
    char resp[3];
    // get the version of getVersion 
    getVersion gv;
@@ -71,9 +74,6 @@
    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"); }
    
  
    
@@ -91,7 +91,12 @@
     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);
+    i2cerr= tid.write_eeprompage(str3, 16, 0, (uint8_t) pagenr++);
+    float tempcor, tempref;
+    printf("\n\rgive temperature correction"); scanf("%f",&tempcor);
+    printf("\n\rgive ref temperature "); scanf("%f",&tempref);
+    sprintf(str4,"%8.4f %7.4f",tempcor,tempref);
+    i2cerr= tid.write_eeprompage(str4, 16, 0, (uint8_t) pagenr++);
    }
    wait_ms(400); // give some time to write 
    //strcpy(str1,"newstr1");strcp(str2,"newstr2");strcp(str3,"newstr3");
@@ -103,18 +108,55 @@
     
     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);
+    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 );
+    i2cerr=tid.read_eeprompage(str4, 16, 0, (uint8_t) pagenr);
+    if(i2cerr) printf("eeprom read error %d \n\r",i2cerr);
+    str1[15]='\0';str2[15]='\0';str3[15]='\0';str4[15]='\0'; //make sure it ends 
+    printf("eeprom content page %d :\n\r %s  %s  %s %s \n\r",pagenr,str1 ,str2 ,str3 ,str4);
     //print_buf_hex( str1,16);
     if ( fix) {
-        printf("protect eeprom ?") ; scanf("%s",resp);
+        printf("protect eeprom ?") ;scanf("%s",resp);
         if(resp[0] == 'y'){  
+            printf("\n\rconnect A0 to 7 V  y, t return when done \n\r");scanf("%s",resp);
+            CntrA1.output(); CntrA1.write(0);
+            CntrA2.output(); CntrA2.write(0);
+            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.protect_eeprom();
             if(i2cerr) printf("eeprom  protect failed %d \n\r", i2cerr);
+            i2cerr=tid.get_eeprom_protec();
+            wait_ms(100);
+            if ( i2cerr ) { printf("ee-prom write protected \n\r");}
+            else { printf("ee-prom NOT write protected \n\r"); }
+            CntrA1.input(); CntrA1.mode(PullNone);
+            CntrA2.input(); CntrA2.mode(PullNone);
+            printf("disconnect A0 from 7 V  y, t return when done \n\r");scanf("%s",resp);
         }
         // fix=false;
+        printf("unprotect eeprom ?") ;scanf("%s",resp);
+        if(resp[0] == 'y'){  
+            printf("\n\rconnect A0 to 7 V  y, t return when done \n\r");scanf("%s",resp);
+            CntrA1.output(); CntrA1.write(0);
+            CntrA2.output(); CntrA2.write(0);
+            i2cerr=tid.get_eeprom_protec();
+            if ( i2cerr ) { printf("ee-prom write protected \n\r");}
+            else { printf("ee-prom NOT write protected \n\r"); }
+            CntrA1.output(); CntrA1.write(1);
+            wait_ms(100);
+            i2cerr=tid.unprotect_eeprom();
+            if(i2cerr) printf("eeprom  protect failed %d \n\r", i2cerr);
+            CntrA1.output(); CntrA1.write(0);
+            wait_ms(100);
+            i2cerr=tid.get_eeprom_protec();
+            if ( i2cerr ) { printf("ee-prom write protected \n\r");}
+            else { printf("ee-prom NOT write protected \n\r"); }
+            CntrA1.input(); CntrA1.mode(PullNone);
+            CntrA2.input(); CntrA2.mode(PullNone);
+            printf("disconnect A0 from 7 V  y, t return when done \n\r");scanf("%s",resp);
+        }
+        
     }
     char singlechar;
     i2cerr=tid.read_eeprombyte(singlechar, 3, (uint8_t) pagenr);