![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
for checking multiple SOLID T sensors
Dependencies: DevInterfaces AT30TSE75x I2Cinterfaces
Fork of AT30TSE752TST by
Diff: main.cpp
- Revision:
- 2:8ce5a2128381
- Parent:
- 1:d175631a5803
- Child:
- 3:789bc6653f83
diff -r d175631a5803 -r 8ce5a2128381 main.cpp --- a/main.cpp Wed Jan 13 19:12:45 2016 +0000 +++ b/main.cpp Fri Jan 13 12:28:09 2017 +0000 @@ -1,16 +1,19 @@ -/** example program for the use of the MCP4728 class and DACInterface.h classes +/** example program for the use of the AT30TSE7xx class * - * V 1.0 : tested on the KL05z but without the MCP4728 connected \ - * (C) Wim Beaumont Universiteit Antwerpen 2016 + * V 0.4 : tested on the KL25z + * tested eeprom read/ write full page / single byte + * temperature read 12 bit resolution + * fix chip configuration. + * (C) Wim Beaumont Universiteit Antwerpen 2017 */ -#define MCP4728EXAMPLEVER "1.10 " +#define AT30TSE753EXAMPLEVER "0.40" #include "mbed.h" #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) - PinName const SDA = PTE25; - PinName const SCL = PTE24; + PinName const SDA = PTE0; + PinName const SCL = PTE1; #elif defined (TARGET_KL05Z) PinName const SDA = PTB4; PinName const SCL = PTB3; @@ -24,74 +27,74 @@ #include "I2C.h" #include "I2CInterface.h" -#include "MBEDI2CInterface.h" -#include "DACInterface.h" +#include "MBEDI2CInterface.h" #include "dev_interface_def.h" -#include "mcp4728.h" +#include "AT30TSE75x.h" + MBEDI2CInterface mbedi2c( SDA, SCL); MBEDI2CInterface* mbedi2cp= &mbedi2c ; I2CInterface* i2cdev= mbedi2cp; -const float Vdd=5.0; Serial pc(USBTX, USBRX); +void print_buf_hex( char *data, int length){ + int nr; + char *ptr=data; + for ( int lc=0; lc < length ; lc++){ + nr= (int) *(ptr++); + printf( "%02x ",nr); + } + printf("\n\r"); +} + + int main(void) { - + char str1[16] = "SOLID Temp"; + char write_eprom= 'n'; // get the version of getVersion getVersion gv; - printf("MCP4728 example program version %s, compile date %s time %s\n\r",MCP4728EXAMPLEVER,__DATE__,__TIME__); - printf("getVersion :%s\n\r",gv.getversioninfo()); + int addr=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); - MCP4728 dac( i2cdev ,0, Vdd); // assuming the address of the MCP4728 is set to 0 factory default - printf("MCP4728 :%s\n\r",dac.getversioninfo()); - wait(4); - float voltage=0; + 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); + int cnt=0; - while(cnt < 4096){ - // first set the 4 channels - for ( int cc =0 ; cc <4 ; cc++) { - if ( dac.setDACvalue(cnt,cc) ) - printf("failed to set dac value %d for channel %d\n\r",cnt,cc); - } - printf("set DAC value to %d result in",cnt); - // no else read anyway even if set fails - if(dac.update()) printf("\n\rfailed to readback channel info \n\r"); - else { - for ( int cc =0 ; cc <4 ; cc++) { - (void)dac.getVoltage(voltage,cc);//no need to test done with updat - printf(" CH%d %f[V]",cc,voltage); - } - printf("\n\r"); - } - cnt++; - cnt=cnt % 4096; - wait_ms(200); - - } - // now the same with the DAC interface - DACInterface* di = &dac; - cnt=0; - while(1){ - // first set the 4 channels - for ( int cc =0 ; cc <4 ; cc++) { - if ( di->setDACvalue(cnt,cc) ) - printf("failed to set dac value %d for channel %d\n\r",cnt,cc); - } - printf("set DAC value to %d result in",cnt); - // no else read anyway even if set fails - if(di->update()) printf("\n\rfailed to readback channel info \n\r"); - else { - for ( int cc =0 ; cc <4 ; cc++) { - (void)di->getVoltage(voltage,cc);// no need to test done with update - printf(" CH%d %f[V]",cc,voltage); - } - printf("\n\r"); - } - - cnt++; - cnt=cnt % 4096; - wait_ms(200); + int i2cerr; + 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("%c",&write_eprom); + int pagenr=0;write_eprom = 'y'; + if(write_eprom == 'y'){ + printf("\n\rgive pagenr"); + scanf("%d",&pagenr); + i2cerr= tid.write_eeprompage(str1, 16, 0, (uint8_t) pagenr); + if(i2cerr) printf("eeprom write error %d\n\r",i2cerr); + } + wait_ms(400); // give some time to write + while(1) { + i2cerr=tid.read_eeprompage(str1, 16, 0, (uint8_t) pagenr); + if(i2cerr) printf("eeprom read error %d \n\r",i2cerr); + str1[15]='\0'; //make sure it ends + printf("eeprom content page %d :\n\r %s\n\r",pagenr,str1); + //print_buf_hex( str1,16); + 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); + }