for checking multiple SOLID T sensors

Dependencies:   DevInterfaces AT30TSE75x I2Cinterfaces

Fork of AT30TSE752TST by wimbeaumont Project

Committer:
wbeaumont
Date:
Mon Jun 24 13:26:41 2019 +0000
Revision:
4:576303494244
Parent:
3:789bc6653f83
Child:
7:7f469b082fb2
not sure but just update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 2:8ce5a2128381 1 /** example program for the use of the AT30TSE7xx class
wbeaumont 1:d175631a5803 2 *
wbeaumont 4:576303494244 3 * check addresses connected, read them
wbeaumont 2:8ce5a2128381 4 * (C) Wim Beaumont Universiteit Antwerpen 2017
wbeaumont 1:d175631a5803 5 */
wbeaumont 1:d175631a5803 6
wbeaumont 4:576303494244 7 #define AT30TSE753EXAMPLEVER "0.21"
wbeaumont 1:d175631a5803 8
wbeaumont 0:5bc0f4bd5aa0 9 #include "mbed.h"
wbeaumont 0:5bc0f4bd5aa0 10
wbeaumont 0:5bc0f4bd5aa0 11 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
wbeaumont 2:8ce5a2128381 12 PinName const SDA = PTE0;
wbeaumont 2:8ce5a2128381 13 PinName const SCL = PTE1;
wbeaumont 0:5bc0f4bd5aa0 14 #elif defined (TARGET_KL05Z)
wbeaumont 0:5bc0f4bd5aa0 15 PinName const SDA = PTB4;
wbeaumont 0:5bc0f4bd5aa0 16 PinName const SCL = PTB3;
wbeaumont 0:5bc0f4bd5aa0 17 #elif defined (TARGET_K20D50M)
wbeaumont 0:5bc0f4bd5aa0 18 PinName const SDA = PTB1;
wbeaumont 0:5bc0f4bd5aa0 19 PinName const SCL = PTB0;
wbeaumont 0:5bc0f4bd5aa0 20 #else
wbeaumont 0:5bc0f4bd5aa0 21 #error TARGET NOT DEFINED
wbeaumont 0:5bc0f4bd5aa0 22 #endif
wbeaumont 0:5bc0f4bd5aa0 23
wbeaumont 0:5bc0f4bd5aa0 24
wbeaumont 0:5bc0f4bd5aa0 25 #include "I2C.h"
wbeaumont 0:5bc0f4bd5aa0 26 #include "I2CInterface.h"
wbeaumont 2:8ce5a2128381 27 #include "MBEDI2CInterface.h"
wbeaumont 0:5bc0f4bd5aa0 28 #include "dev_interface_def.h"
wbeaumont 2:8ce5a2128381 29 #include "AT30TSE75x.h"
wbeaumont 2:8ce5a2128381 30
wbeaumont 0:5bc0f4bd5aa0 31
wbeaumont 0:5bc0f4bd5aa0 32 MBEDI2CInterface mbedi2c( SDA, SCL);
wbeaumont 0:5bc0f4bd5aa0 33 MBEDI2CInterface* mbedi2cp= &mbedi2c ;
wbeaumont 0:5bc0f4bd5aa0 34 I2CInterface* i2cdev= mbedi2cp;
wbeaumont 0:5bc0f4bd5aa0 35
wbeaumont 0:5bc0f4bd5aa0 36 Serial pc(USBTX, USBRX);
wbeaumont 0:5bc0f4bd5aa0 37
wbeaumont 2:8ce5a2128381 38 void print_buf_hex( char *data, int length){
wbeaumont 2:8ce5a2128381 39 int nr;
wbeaumont 2:8ce5a2128381 40 char *ptr=data;
wbeaumont 2:8ce5a2128381 41 for ( int lc=0; lc < length ; lc++){
wbeaumont 2:8ce5a2128381 42 nr= (int) *(ptr++);
wbeaumont 2:8ce5a2128381 43 printf( "%02x ",nr);
wbeaumont 2:8ce5a2128381 44 }
wbeaumont 2:8ce5a2128381 45 printf("\n\r");
wbeaumont 2:8ce5a2128381 46 }
wbeaumont 2:8ce5a2128381 47
wbeaumont 2:8ce5a2128381 48
wbeaumont 4:576303494244 49 int main(void) {
wbeaumont 4:576303494244 50
wbeaumont 0:5bc0f4bd5aa0 51 // get the version of getVersion
wbeaumont 0:5bc0f4bd5aa0 52 getVersion gv;
wbeaumont 2:8ce5a2128381 53 int addr=0;
wbeaumont 3:789bc6653f83 54 int i2cerr;
wbeaumont 3:789bc6653f83 55
wbeaumont 2:8ce5a2128381 56 printf("AT30TSE752 example program version %s, compile date %s time %s\n\r",AT30TSE753EXAMPLEVER,__DATE__,__TIME__);
wbeaumont 2:8ce5a2128381 57 printf("getVersion :%s\n\r ",gv.getversioninfo());
wbeaumont 0:5bc0f4bd5aa0 58
wbeaumont 2:8ce5a2128381 59
wbeaumont 3:789bc6653f83 60
wbeaumont 4:576303494244 61 AT30TSE75x tid[8] ={ AT30TSE75x( i2cdev ,0), AT30TSE75x( i2cdev ,1),AT30TSE75x( i2cdev ,2) ,AT30TSE75x( i2cdev ,3),
wbeaumont 4:576303494244 62 AT30TSE75x( i2cdev ,4), AT30TSE75x( i2cdev ,5),AT30TSE75x( i2cdev ,6) ,AT30TSE75x( i2cdev ,7)};
wbeaumont 4:576303494244 63 bool addrfound[8];
wbeaumont 4:576303494244 64 for (int lc=0; lc <7 ;lc++) {
wbeaumont 4:576303494244 65 printf ( "AT30SE75x version :%s\n\r ",tid[lc].getversioninfo());
wbeaumont 4:576303494244 66 printf( "Taddr %x , Eaddr %x subaddr %d\n\r ", tid[lc].getTaddr(),tid[lc].getEaddr(), addr);
wbeaumont 4:576303494244 67 if( tid[lc].getInitStatus() ){ printf("reading config registers failed \n\r");addrfound[lc]=false; }
wbeaumont 4:576303494244 68 else {
wbeaumont 4:576303494244 69 addrfound[lc]=true;
wbeaumont 4:576303494244 70 tid[lc].set_resolution(12 , i2cerr );
wbeaumont 4:576303494244 71 tid[lc].set_FaultTollerantQueue('6', i2cerr );
wbeaumont 4:576303494244 72 tid[lc].set_AlertPinPolarity(0,i2cerr);
wbeaumont 4:576303494244 73 tid[lc].set_AlarmThermostateMode(0,i2cerr);
wbeaumont 4:576303494244 74 tid[lc].set_config(i2cerr,0);
wbeaumont 4:576303494244 75 int configrd= tid[lc].read_config( i2cerr, 0);
wbeaumont 4:576303494244 76 printf( " config %x I2cerr %d \n\r", configrd,i2cerr );
wbeaumont 4:576303494244 77 }
wbeaumont 4:576303494244 78 }
wbeaumont 3:789bc6653f83 79 int pagenr=0;
wbeaumont 4:576303494244 80 const int nrstrs=4;
wbeaumont 4:576303494244 81 char str[nrstrs][16];
wbeaumont 4:576303494244 82
wbeaumont 2:8ce5a2128381 83 while(1) {
wbeaumont 4:576303494244 84 for (int lc=0; lc<7 ;lc++) {
wbeaumont 4:576303494244 85 if( addrfound[lc]) {
wbeaumont 4:576303494244 86 pagenr=0;
wbeaumont 4:576303494244 87 for ( int sc=0 ; sc <nrstrs;sc++){
wbeaumont 4:576303494244 88 i2cerr=tid[lc].read_eeprompage(str[sc], 16, 0, (uint8_t) pagenr++);
wbeaumont 4:576303494244 89 if(i2cerr) printf("eeprom read error %d addr %d \n\r",i2cerr,lc);
wbeaumont 4:576303494244 90 }
wbeaumont 4:576303494244 91
wbeaumont 4:576303494244 92 for (int sc=0 ; sc < nrstrs;sc ++) {
wbeaumont 4:576303494244 93 str[sc][15]='\0'; //make sure it ends
wbeaumont 4:576303494244 94 printf("%d:%15s ",sc,str[sc]);
wbeaumont 3:789bc6653f83 95 }
wbeaumont 4:576303494244 96 // temperature correction
wbeaumont 4:576303494244 97 str[3][7]='\0';
wbeaumont 4:576303494244 98 float tempcor=atof(str[3]);
wbeaumont 4:576303494244 99 if ( tempcor < -2.5 || tempcor > 2.5) tempcor=0.0;
wbeaumont 4:576303494244 100 float Tmp= tid[lc].get_temperature(i2cerr);
wbeaumont 4:576303494244 101 printf ("T=%f %f I2cerr %d addr %d\n\r", Tmp,Tmp+tempcor, i2cerr,lc);
wbeaumont 4:576303494244 102 } // if
wbeaumont 4:576303494244 103 } // for
wbeaumont 4:576303494244 104 printf("\n\r");
wbeaumont 4:576303494244 105 wait_ms(500);
wbeaumont 4:576303494244 106 } //while
wbeaumont 1:d175631a5803 107
wbeaumont 0:5bc0f4bd5aa0 108 }