i2c

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

main.cpp

Committer:
Andreus
Date:
2015-03-27
Revision:
2:24f2636c2915
Parent:
1:560b8ced44df

File content as of revision 2:24f2636c2915:

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
I2C i2c(p28, p27);
const int addr_r = 0xA9; //Read of EEPROM 10101001
const int addr_w = 0xA8; //Write of EEPROM 10101000
//const int freq = 300000;


int main() {
    pc.printf("EEPROM operation util\n\r");
    char cmd[] = "aahello!!!";
    cmd[0]=0xAA;
    cmd[1]=0x12;
    char buffer[8];


    //i2c.frequency(freq);
    pc.printf("Selection of i2c offset ");
    if(i2c.write(addr_w,cmd,2,true)==0) {pc.printf("succeed"); } 
    else pc.printf ("failed");
    i2c.read(addr_r, buffer, 8, false);
 /*   pc.printf("\n\rread 8 bytes: %s\n\r", buffer);
    wait(0.5);
    pc.printf("trying to write: %s ",cmd);
    if(i2c.write(addr_w,cmd,10,false)) printf("succeed"); 
    else printf ("failed");
    wait(0.5);
    pc.printf("Selection of i2c offset ");
    if(i2c.write(addr_r,cmd,2,true)==0) {printf("succeed"); }
    else printf ("failed");
    i2c.read(addr_r, buffer, 8, true);
    i2c.stop();
    pc.printf("\n\rread 8 bytes: %s\n\r", buffer);
  */  
    
    
    
    while(1)
    {
    }    
}