Andrey Myagkov
/
MRT-I2C-rw
i2c
Fork of Serial_HelloWorld_Mbed by
main.cpp@2:24f2636c2915, 2015-03-27 (annotated)
- Committer:
- Andreus
- Date:
- Fri Mar 27 14:52:54 2015 +0000
- Revision:
- 2:24f2636c2915
- Parent:
- 1:560b8ced44df
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:879aa9d0247b | 1 | #include "mbed.h" |
mbed_official | 0:879aa9d0247b | 2 | |
mbed_official | 0:879aa9d0247b | 3 | Serial pc(USBTX, USBRX); // tx, rx |
Andreus | 2:24f2636c2915 | 4 | I2C i2c(p28, p27); |
Andreus | 2:24f2636c2915 | 5 | const int addr_r = 0xA9; //Read of EEPROM 10101001 |
Andreus | 2:24f2636c2915 | 6 | const int addr_w = 0xA8; //Write of EEPROM 10101000 |
Andreus | 2:24f2636c2915 | 7 | //const int freq = 300000; |
Andreus | 2:24f2636c2915 | 8 | |
Andreus | 2:24f2636c2915 | 9 | |
mbed_official | 0:879aa9d0247b | 10 | int main() { |
Andreus | 2:24f2636c2915 | 11 | pc.printf("EEPROM operation util\n\r"); |
Andreus | 2:24f2636c2915 | 12 | char cmd[] = "aahello!!!"; |
Andreus | 2:24f2636c2915 | 13 | cmd[0]=0xAA; |
Andreus | 2:24f2636c2915 | 14 | cmd[1]=0x12; |
Andreus | 2:24f2636c2915 | 15 | char buffer[8]; |
Andreus | 2:24f2636c2915 | 16 | |
Andreus | 2:24f2636c2915 | 17 | |
Andreus | 2:24f2636c2915 | 18 | //i2c.frequency(freq); |
Andreus | 2:24f2636c2915 | 19 | pc.printf("Selection of i2c offset "); |
Andreus | 2:24f2636c2915 | 20 | if(i2c.write(addr_w,cmd,2,true)==0) {pc.printf("succeed"); } |
Andreus | 2:24f2636c2915 | 21 | else pc.printf ("failed"); |
Andreus | 2:24f2636c2915 | 22 | i2c.read(addr_r, buffer, 8, false); |
Andreus | 2:24f2636c2915 | 23 | /* pc.printf("\n\rread 8 bytes: %s\n\r", buffer); |
Andreus | 2:24f2636c2915 | 24 | wait(0.5); |
Andreus | 2:24f2636c2915 | 25 | pc.printf("trying to write: %s ",cmd); |
Andreus | 2:24f2636c2915 | 26 | if(i2c.write(addr_w,cmd,10,false)) printf("succeed"); |
Andreus | 2:24f2636c2915 | 27 | else printf ("failed"); |
Andreus | 2:24f2636c2915 | 28 | wait(0.5); |
Andreus | 2:24f2636c2915 | 29 | pc.printf("Selection of i2c offset "); |
Andreus | 2:24f2636c2915 | 30 | if(i2c.write(addr_r,cmd,2,true)==0) {printf("succeed"); } |
Andreus | 2:24f2636c2915 | 31 | else printf ("failed"); |
Andreus | 2:24f2636c2915 | 32 | i2c.read(addr_r, buffer, 8, true); |
Andreus | 2:24f2636c2915 | 33 | i2c.stop(); |
Andreus | 2:24f2636c2915 | 34 | pc.printf("\n\rread 8 bytes: %s\n\r", buffer); |
Andreus | 2:24f2636c2915 | 35 | */ |
Andreus | 2:24f2636c2915 | 36 | |
Andreus | 2:24f2636c2915 | 37 | |
Andreus | 2:24f2636c2915 | 38 | |
Andreus | 2:24f2636c2915 | 39 | while(1) |
Andreus | 2:24f2636c2915 | 40 | { |
Andreus | 2:24f2636c2915 | 41 | } |
mbed_official | 0:879aa9d0247b | 42 | } |