Dependencies:   mbed

Committer:
soulx
Date:
Mon Nov 02 03:31:08 2015 +0000
Revision:
1:b2b38e1e4d0c
Parent:
0:b5986cc5eebd
add comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soulx 0:b5986cc5eebd 1 #include "mbed.h"
soulx 0:b5986cc5eebd 2
soulx 0:b5986cc5eebd 3 I2C i2c(I2C_SDA, I2C_SCL);
soulx 0:b5986cc5eebd 4
soulx 0:b5986cc5eebd 5 const int addr = 0xA0;
soulx 0:b5986cc5eebd 6
soulx 0:b5986cc5eebd 7 int main() {
soulx 0:b5986cc5eebd 8 char cmd[6];
soulx 0:b5986cc5eebd 9 int len=3;
soulx 0:b5986cc5eebd 10 char data[1];
soulx 0:b5986cc5eebd 11 int ack;
soulx 0:b5986cc5eebd 12
soulx 0:b5986cc5eebd 13 i2c.frequency(100000);
soulx 1:b2b38e1e4d0c 14 //address in eeprom
soulx 0:b5986cc5eebd 15 cmd[0] = 0x00;
soulx 0:b5986cc5eebd 16 cmd[1] = 0x01;
soulx 1:b2b38e1e4d0c 17 //data for write to eeprom
soulx 1:b2b38e1e4d0c 18 cmd[2] ='c';
soulx 1:b2b38e1e4d0c 19
soulx 1:b2b38e1e4d0c 20 //sent data i2c FIGURE 4-1
soulx 0:b5986cc5eebd 21 ack = i2c.write((int)addr,(char *)cmd,len);
soulx 1:b2b38e1e4d0c 22 //wait for write to memory
soulx 0:b5986cc5eebd 23 wait_ms(5);
soulx 1:b2b38e1e4d0c 24 //read data i2c FIGURE 6-2
soulx 1:b2b38e1e4d0c 25 ack = i2c.write((int)addr,(char *)cmd,len-1,true);
soulx 1:b2b38e1e4d0c 26 //read data i2c
soulx 0:b5986cc5eebd 27 ack = i2c.read((int)addr,(char *)&data,sizeof(data));
soulx 1:b2b38e1e4d0c 28
soulx 0:b5986cc5eebd 29 printf("Temp1 = %c\n", data[0]);
soulx 0:b5986cc5eebd 30
soulx 0:b5986cc5eebd 31
soulx 1:b2b38e1e4d0c 32 cmd[2] ='X';
soulx 0:b5986cc5eebd 33 ack = i2c.write((int)addr,(char *)cmd,len);
soulx 0:b5986cc5eebd 34 //i2c.write(addr, cmd, 2);
soulx 0:b5986cc5eebd 35
soulx 0:b5986cc5eebd 36 wait_ms(5);
soulx 0:b5986cc5eebd 37
soulx 0:b5986cc5eebd 38 ack = i2c.write((int)addr+1,(char *)cmd,len-1,true);
soulx 0:b5986cc5eebd 39
soulx 0:b5986cc5eebd 40 ack = i2c.read((int)addr,(char *)&data,sizeof(data));
soulx 0:b5986cc5eebd 41 printf("Temp2 = %c\n\n", data[0]);
soulx 0:b5986cc5eebd 42
soulx 0:b5986cc5eebd 43 //wait_us(100);
soulx 0:b5986cc5eebd 44 /*
soulx 0:b5986cc5eebd 45 cmd[0] = 0x00;
soulx 0:b5986cc5eebd 46 i2c.write(addr, cmd, 1);
soulx 0:b5986cc5eebd 47 i2c.read(addr, cmd, 6);
soulx 0:b5986cc5eebd 48 */
soulx 0:b5986cc5eebd 49
soulx 0:b5986cc5eebd 50 // float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
soulx 0:b5986cc5eebd 51 // printf("Temp = %s\n", cmd);
soulx 0:b5986cc5eebd 52 //}
soulx 0:b5986cc5eebd 53 }