![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2
Dependencies: mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces
main.cpp@2:8ce5a2128381, 2017-01-13 (annotated)
- Committer:
- wbeaumont
- Date:
- Fri Jan 13 12:28:09 2017 +0000
- Revision:
- 2:8ce5a2128381
- Parent:
- 1:d175631a5803
- Child:
- 4:527490fdcfd8
testprogram for the AT30TSE75X class
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 | 2:8ce5a2128381 | 3 | * V 0.4 : tested on the KL25z |
wbeaumont | 2:8ce5a2128381 | 4 | * tested eeprom read/ write full page / single byte |
wbeaumont | 2:8ce5a2128381 | 5 | * temperature read 12 bit resolution |
wbeaumont | 2:8ce5a2128381 | 6 | * fix chip configuration. |
wbeaumont | 2:8ce5a2128381 | 7 | * (C) Wim Beaumont Universiteit Antwerpen 2017 |
wbeaumont | 1:d175631a5803 | 8 | */ |
wbeaumont | 1:d175631a5803 | 9 | |
wbeaumont | 2:8ce5a2128381 | 10 | #define AT30TSE753EXAMPLEVER "0.40" |
wbeaumont | 1:d175631a5803 | 11 | |
wbeaumont | 0:5bc0f4bd5aa0 | 12 | #include "mbed.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 13 | |
wbeaumont | 0:5bc0f4bd5aa0 | 14 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
wbeaumont | 2:8ce5a2128381 | 15 | PinName const SDA = PTE0; |
wbeaumont | 2:8ce5a2128381 | 16 | PinName const SCL = PTE1; |
wbeaumont | 0:5bc0f4bd5aa0 | 17 | #elif defined (TARGET_KL05Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 18 | PinName const SDA = PTB4; |
wbeaumont | 0:5bc0f4bd5aa0 | 19 | PinName const SCL = PTB3; |
wbeaumont | 0:5bc0f4bd5aa0 | 20 | #elif defined (TARGET_K20D50M) |
wbeaumont | 0:5bc0f4bd5aa0 | 21 | PinName const SDA = PTB1; |
wbeaumont | 0:5bc0f4bd5aa0 | 22 | PinName const SCL = PTB0; |
wbeaumont | 0:5bc0f4bd5aa0 | 23 | #else |
wbeaumont | 0:5bc0f4bd5aa0 | 24 | #error TARGET NOT DEFINED |
wbeaumont | 0:5bc0f4bd5aa0 | 25 | #endif |
wbeaumont | 0:5bc0f4bd5aa0 | 26 | |
wbeaumont | 0:5bc0f4bd5aa0 | 27 | |
wbeaumont | 0:5bc0f4bd5aa0 | 28 | #include "I2C.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 29 | #include "I2CInterface.h" |
wbeaumont | 2:8ce5a2128381 | 30 | #include "MBEDI2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 31 | #include "dev_interface_def.h" |
wbeaumont | 2:8ce5a2128381 | 32 | #include "AT30TSE75x.h" |
wbeaumont | 2:8ce5a2128381 | 33 | |
wbeaumont | 0:5bc0f4bd5aa0 | 34 | |
wbeaumont | 0:5bc0f4bd5aa0 | 35 | MBEDI2CInterface mbedi2c( SDA, SCL); |
wbeaumont | 0:5bc0f4bd5aa0 | 36 | MBEDI2CInterface* mbedi2cp= &mbedi2c ; |
wbeaumont | 0:5bc0f4bd5aa0 | 37 | I2CInterface* i2cdev= mbedi2cp; |
wbeaumont | 0:5bc0f4bd5aa0 | 38 | |
wbeaumont | 0:5bc0f4bd5aa0 | 39 | Serial pc(USBTX, USBRX); |
wbeaumont | 0:5bc0f4bd5aa0 | 40 | |
wbeaumont | 2:8ce5a2128381 | 41 | void print_buf_hex( char *data, int length){ |
wbeaumont | 2:8ce5a2128381 | 42 | int nr; |
wbeaumont | 2:8ce5a2128381 | 43 | char *ptr=data; |
wbeaumont | 2:8ce5a2128381 | 44 | for ( int lc=0; lc < length ; lc++){ |
wbeaumont | 2:8ce5a2128381 | 45 | nr= (int) *(ptr++); |
wbeaumont | 2:8ce5a2128381 | 46 | printf( "%02x ",nr); |
wbeaumont | 2:8ce5a2128381 | 47 | } |
wbeaumont | 2:8ce5a2128381 | 48 | printf("\n\r"); |
wbeaumont | 2:8ce5a2128381 | 49 | } |
wbeaumont | 2:8ce5a2128381 | 50 | |
wbeaumont | 2:8ce5a2128381 | 51 | |
wbeaumont | 0:5bc0f4bd5aa0 | 52 | int main(void) { |
wbeaumont | 2:8ce5a2128381 | 53 | char str1[16] = "SOLID Temp"; |
wbeaumont | 2:8ce5a2128381 | 54 | char write_eprom= 'n'; |
wbeaumont | 0:5bc0f4bd5aa0 | 55 | // get the version of getVersion |
wbeaumont | 0:5bc0f4bd5aa0 | 56 | getVersion gv; |
wbeaumont | 2:8ce5a2128381 | 57 | int addr=0; |
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 | 2:8ce5a2128381 | 60 | printf("%s\n\r",str1); |
wbeaumont | 2:8ce5a2128381 | 61 | printf("give new addr "); scanf("%d", &addr); |
wbeaumont | 2:8ce5a2128381 | 62 | if ( addr < 0 || addr > 15) addr=0; |
wbeaumont | 2:8ce5a2128381 | 63 | fflush(stdin); |
wbeaumont | 0:5bc0f4bd5aa0 | 64 | |
wbeaumont | 2:8ce5a2128381 | 65 | AT30TSE75x tid( i2cdev ,addr); |
wbeaumont | 2:8ce5a2128381 | 66 | printf ( "AT30SE75x version :%s\n\r ",tid.getversioninfo()); |
wbeaumont | 2:8ce5a2128381 | 67 | printf( "Taddr %x , Eaddr %x subaddr %d\n\r ", tid.getTaddr(),tid.getEaddr(), addr); |
wbeaumont | 2:8ce5a2128381 | 68 | |
wbeaumont | 0:5bc0f4bd5aa0 | 69 | int cnt=0; |
wbeaumont | 2:8ce5a2128381 | 70 | int i2cerr; |
wbeaumont | 2:8ce5a2128381 | 71 | i2cerr=tid.set_config(); |
wbeaumont | 2:8ce5a2128381 | 72 | if( i2cerr) printf("config not set %d \n\r", i2cerr); |
wbeaumont | 2:8ce5a2128381 | 73 | int configrd= tid.read_config( 0, &i2cerr); |
wbeaumont | 2:8ce5a2128381 | 74 | printf( " config %x I2cerr %d \n\r", configrd,i2cerr ); |
wbeaumont | 2:8ce5a2128381 | 75 | printf("write to eprom ?"); scanf("%c",&write_eprom); |
wbeaumont | 2:8ce5a2128381 | 76 | int pagenr=0;write_eprom = 'y'; |
wbeaumont | 2:8ce5a2128381 | 77 | if(write_eprom == 'y'){ |
wbeaumont | 2:8ce5a2128381 | 78 | printf("\n\rgive pagenr"); |
wbeaumont | 2:8ce5a2128381 | 79 | scanf("%d",&pagenr); |
wbeaumont | 2:8ce5a2128381 | 80 | i2cerr= tid.write_eeprompage(str1, 16, 0, (uint8_t) pagenr); |
wbeaumont | 2:8ce5a2128381 | 81 | if(i2cerr) printf("eeprom write error %d\n\r",i2cerr); |
wbeaumont | 2:8ce5a2128381 | 82 | } |
wbeaumont | 2:8ce5a2128381 | 83 | wait_ms(400); // give some time to write |
wbeaumont | 2:8ce5a2128381 | 84 | while(1) { |
wbeaumont | 2:8ce5a2128381 | 85 | i2cerr=tid.read_eeprompage(str1, 16, 0, (uint8_t) pagenr); |
wbeaumont | 2:8ce5a2128381 | 86 | if(i2cerr) printf("eeprom read error %d \n\r",i2cerr); |
wbeaumont | 2:8ce5a2128381 | 87 | str1[15]='\0'; //make sure it ends |
wbeaumont | 2:8ce5a2128381 | 88 | printf("eeprom content page %d :\n\r %s\n\r",pagenr,str1); |
wbeaumont | 2:8ce5a2128381 | 89 | //print_buf_hex( str1,16); |
wbeaumont | 2:8ce5a2128381 | 90 | char singlechar; |
wbeaumont | 2:8ce5a2128381 | 91 | i2cerr=tid.read_eeprombyte(singlechar, 3, (uint8_t) pagenr); |
wbeaumont | 2:8ce5a2128381 | 92 | if(i2cerr) printf("eeprom read error %d \n\r",i2cerr); |
wbeaumont | 2:8ce5a2128381 | 93 | printf("third char is : %c\n\r",singlechar); |
wbeaumont | 2:8ce5a2128381 | 94 | wait_ms(1000); |
wbeaumont | 2:8ce5a2128381 | 95 | float Tmp= tid.get_temperature(&i2cerr); |
wbeaumont | 2:8ce5a2128381 | 96 | printf ("%d:Temp = %f I2cerr %d \n\r",cnt++, Tmp, i2cerr); |
wbeaumont | 2:8ce5a2128381 | 97 | |
wbeaumont | 1:d175631a5803 | 98 | |
wbeaumont | 1:d175631a5803 | 99 | } |
wbeaumont | 1:d175631a5803 | 100 | |
wbeaumont | 1:d175631a5803 | 101 | |
wbeaumont | 0:5bc0f4bd5aa0 | 102 | // never reach this |
wbeaumont | 0:5bc0f4bd5aa0 | 103 | return 1; |
wbeaumont | 0:5bc0f4bd5aa0 | 104 | } |