for checking multiple SOLID T sensors
Dependencies: DevInterfaces AT30TSE75x I2Cinterfaces
Fork of AT30TSE752TST by
main.cpp@8:02f48ff4ea1a, 2019-06-24 (annotated)
- Committer:
- wbeaumont
- Date:
- Mon Jun 24 15:37:20 2019 +0000
- Revision:
- 8:02f48ff4ea1a
- Parent:
- 7:7f469b082fb2
removed mbed lib;
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:7f469b082fb2 | 5 | |
wbeaumont | 7:7f469b082fb2 | 6 | * ver 0.22 updated to the last mbed , see if mbed studio accepts now |
wbeaumont | 1:d175631a5803 | 7 | */ |
wbeaumont | 1:d175631a5803 | 8 | |
wbeaumont | 7:7f469b082fb2 | 9 | #define AT30TSE753EXAMPLEVER "0.22" |
wbeaumont | 1:d175631a5803 | 10 | |
wbeaumont | 0:5bc0f4bd5aa0 | 11 | #include "mbed.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 12 | |
wbeaumont | 0:5bc0f4bd5aa0 | 13 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
wbeaumont | 2:8ce5a2128381 | 14 | PinName const SDA = PTE0; |
wbeaumont | 2:8ce5a2128381 | 15 | PinName const SCL = PTE1; |
wbeaumont | 0:5bc0f4bd5aa0 | 16 | #elif defined (TARGET_KL05Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 17 | PinName const SDA = PTB4; |
wbeaumont | 0:5bc0f4bd5aa0 | 18 | PinName const SCL = PTB3; |
wbeaumont | 0:5bc0f4bd5aa0 | 19 | #elif defined (TARGET_K20D50M) |
wbeaumont | 0:5bc0f4bd5aa0 | 20 | PinName const SDA = PTB1; |
wbeaumont | 0:5bc0f4bd5aa0 | 21 | PinName const SCL = PTB0; |
wbeaumont | 0:5bc0f4bd5aa0 | 22 | #else |
wbeaumont | 0:5bc0f4bd5aa0 | 23 | #error TARGET NOT DEFINED |
wbeaumont | 0:5bc0f4bd5aa0 | 24 | #endif |
wbeaumont | 0:5bc0f4bd5aa0 | 25 | |
wbeaumont | 0:5bc0f4bd5aa0 | 26 | |
wbeaumont | 0:5bc0f4bd5aa0 | 27 | #include "I2C.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 28 | #include "I2CInterface.h" |
wbeaumont | 2:8ce5a2128381 | 29 | #include "MBEDI2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 30 | #include "dev_interface_def.h" |
wbeaumont | 2:8ce5a2128381 | 31 | #include "AT30TSE75x.h" |
wbeaumont | 2:8ce5a2128381 | 32 | |
wbeaumont | 0:5bc0f4bd5aa0 | 33 | |
wbeaumont | 0:5bc0f4bd5aa0 | 34 | MBEDI2CInterface mbedi2c( SDA, SCL); |
wbeaumont | 0:5bc0f4bd5aa0 | 35 | MBEDI2CInterface* mbedi2cp= &mbedi2c ; |
wbeaumont | 0:5bc0f4bd5aa0 | 36 | I2CInterface* i2cdev= mbedi2cp; |
wbeaumont | 0:5bc0f4bd5aa0 | 37 | |
wbeaumont | 0:5bc0f4bd5aa0 | 38 | Serial pc(USBTX, USBRX); |
wbeaumont | 0:5bc0f4bd5aa0 | 39 | |
wbeaumont | 2:8ce5a2128381 | 40 | void print_buf_hex( char *data, int length){ |
wbeaumont | 2:8ce5a2128381 | 41 | int nr; |
wbeaumont | 2:8ce5a2128381 | 42 | char *ptr=data; |
wbeaumont | 2:8ce5a2128381 | 43 | for ( int lc=0; lc < length ; lc++){ |
wbeaumont | 2:8ce5a2128381 | 44 | nr= (int) *(ptr++); |
wbeaumont | 2:8ce5a2128381 | 45 | printf( "%02x ",nr); |
wbeaumont | 2:8ce5a2128381 | 46 | } |
wbeaumont | 2:8ce5a2128381 | 47 | printf("\n\r"); |
wbeaumont | 2:8ce5a2128381 | 48 | } |
wbeaumont | 2:8ce5a2128381 | 49 | |
wbeaumont | 2:8ce5a2128381 | 50 | |
wbeaumont | 4:576303494244 | 51 | int main(void) { |
wbeaumont | 4:576303494244 | 52 | |
wbeaumont | 0:5bc0f4bd5aa0 | 53 | // get the version of getVersion |
wbeaumont | 0:5bc0f4bd5aa0 | 54 | getVersion gv; |
wbeaumont | 2:8ce5a2128381 | 55 | int addr=0; |
wbeaumont | 3:789bc6653f83 | 56 | int i2cerr; |
wbeaumont | 3:789bc6653f83 | 57 | |
wbeaumont | 2:8ce5a2128381 | 58 | printf("AT30TSE752 example program version %s, compile date %s time %s\n\r",AT30TSE753EXAMPLEVER,__DATE__,__TIME__); |
wbeaumont | 2:8ce5a2128381 | 59 | printf("getVersion :%s\n\r ",gv.getversioninfo()); |
wbeaumont | 0:5bc0f4bd5aa0 | 60 | |
wbeaumont | 2:8ce5a2128381 | 61 | |
wbeaumont | 3:789bc6653f83 | 62 | |
wbeaumont | 4:576303494244 | 63 | AT30TSE75x tid[8] ={ AT30TSE75x( i2cdev ,0), AT30TSE75x( i2cdev ,1),AT30TSE75x( i2cdev ,2) ,AT30TSE75x( i2cdev ,3), |
wbeaumont | 4:576303494244 | 64 | AT30TSE75x( i2cdev ,4), AT30TSE75x( i2cdev ,5),AT30TSE75x( i2cdev ,6) ,AT30TSE75x( i2cdev ,7)}; |
wbeaumont | 4:576303494244 | 65 | bool addrfound[8]; |
wbeaumont | 4:576303494244 | 66 | for (int lc=0; lc <7 ;lc++) { |
wbeaumont | 4:576303494244 | 67 | printf ( "AT30SE75x version :%s\n\r ",tid[lc].getversioninfo()); |
wbeaumont | 4:576303494244 | 68 | printf( "Taddr %x , Eaddr %x subaddr %d\n\r ", tid[lc].getTaddr(),tid[lc].getEaddr(), addr); |
wbeaumont | 4:576303494244 | 69 | if( tid[lc].getInitStatus() ){ printf("reading config registers failed \n\r");addrfound[lc]=false; } |
wbeaumont | 4:576303494244 | 70 | else { |
wbeaumont | 4:576303494244 | 71 | addrfound[lc]=true; |
wbeaumont | 4:576303494244 | 72 | tid[lc].set_resolution(12 , i2cerr ); |
wbeaumont | 4:576303494244 | 73 | tid[lc].set_FaultTollerantQueue('6', i2cerr ); |
wbeaumont | 4:576303494244 | 74 | tid[lc].set_AlertPinPolarity(0,i2cerr); |
wbeaumont | 4:576303494244 | 75 | tid[lc].set_AlarmThermostateMode(0,i2cerr); |
wbeaumont | 4:576303494244 | 76 | tid[lc].set_config(i2cerr,0); |
wbeaumont | 4:576303494244 | 77 | int configrd= tid[lc].read_config( i2cerr, 0); |
wbeaumont | 4:576303494244 | 78 | printf( " config %x I2cerr %d \n\r", configrd,i2cerr ); |
wbeaumont | 4:576303494244 | 79 | } |
wbeaumont | 4:576303494244 | 80 | } |
wbeaumont | 3:789bc6653f83 | 81 | int pagenr=0; |
wbeaumont | 4:576303494244 | 82 | const int nrstrs=4; |
wbeaumont | 4:576303494244 | 83 | char str[nrstrs][16]; |
wbeaumont | 4:576303494244 | 84 | |
wbeaumont | 2:8ce5a2128381 | 85 | while(1) { |
wbeaumont | 4:576303494244 | 86 | for (int lc=0; lc<7 ;lc++) { |
wbeaumont | 4:576303494244 | 87 | if( addrfound[lc]) { |
wbeaumont | 4:576303494244 | 88 | pagenr=0; |
wbeaumont | 4:576303494244 | 89 | for ( int sc=0 ; sc <nrstrs;sc++){ |
wbeaumont | 4:576303494244 | 90 | i2cerr=tid[lc].read_eeprompage(str[sc], 16, 0, (uint8_t) pagenr++); |
wbeaumont | 4:576303494244 | 91 | if(i2cerr) printf("eeprom read error %d addr %d \n\r",i2cerr,lc); |
wbeaumont | 4:576303494244 | 92 | } |
wbeaumont | 4:576303494244 | 93 | |
wbeaumont | 4:576303494244 | 94 | for (int sc=0 ; sc < nrstrs;sc ++) { |
wbeaumont | 4:576303494244 | 95 | str[sc][15]='\0'; //make sure it ends |
wbeaumont | 4:576303494244 | 96 | printf("%d:%15s ",sc,str[sc]); |
wbeaumont | 3:789bc6653f83 | 97 | } |
wbeaumont | 4:576303494244 | 98 | // temperature correction |
wbeaumont | 4:576303494244 | 99 | str[3][7]='\0'; |
wbeaumont | 4:576303494244 | 100 | float tempcor=atof(str[3]); |
wbeaumont | 4:576303494244 | 101 | if ( tempcor < -2.5 || tempcor > 2.5) tempcor=0.0; |
wbeaumont | 4:576303494244 | 102 | float Tmp= tid[lc].get_temperature(i2cerr); |
wbeaumont | 4:576303494244 | 103 | printf ("T=%f %f I2cerr %d addr %d\n\r", Tmp,Tmp+tempcor, i2cerr,lc); |
wbeaumont | 4:576303494244 | 104 | } // if |
wbeaumont | 4:576303494244 | 105 | } // for |
wbeaumont | 4:576303494244 | 106 | printf("\n\r"); |
wbeaumont | 4:576303494244 | 107 | wait_ms(500); |
wbeaumont | 4:576303494244 | 108 | } //while |
wbeaumont | 1:d175631a5803 | 109 | |
wbeaumont | 0:5bc0f4bd5aa0 | 110 | } |