I2C_comm

Dependencies:   mbed

Fork of I2C_comm by Raphaël Drouin

Committer:
ShaolinPoutine
Date:
Wed Jan 11 22:53:22 2017 +0000
Revision:
0:656742ec86ae
Child:
1:7f23dfc59683
ASDFGHJ

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ShaolinPoutine 0:656742ec86ae 1 #include "mbed.h"
ShaolinPoutine 0:656742ec86ae 2
ShaolinPoutine 0:656742ec86ae 3 //read register value
ShaolinPoutine 0:656742ec86ae 4
ShaolinPoutine 0:656742ec86ae 5 I2C i2c(p9, p10);
ShaolinPoutine 0:656742ec86ae 6
ShaolinPoutine 0:656742ec86ae 7 const char reg[1] = {0x0D};
ShaolinPoutine 0:656742ec86ae 8 const char device = 0x3A;
ShaolinPoutine 0:656742ec86ae 9 char data[1];
ShaolinPoutine 0:656742ec86ae 10
ShaolinPoutine 0:656742ec86ae 11 int main() {
ShaolinPoutine 0:656742ec86ae 12
ShaolinPoutine 0:656742ec86ae 13 i2c.write(device,reg,1,true);
ShaolinPoutine 0:656742ec86ae 14 i2c.read(device,data,1);
ShaolinPoutine 0:656742ec86ae 15
ShaolinPoutine 0:656742ec86ae 16 printf("Result : %d \r\n", data[1]);
ShaolinPoutine 0:656742ec86ae 17
ShaolinPoutine 0:656742ec86ae 18
ShaolinPoutine 0:656742ec86ae 19 /*i2c.read(addr,);
ShaolinPoutine 0:656742ec86ae 20
ShaolinPoutine 0:656742ec86ae 21
ShaolinPoutine 0:656742ec86ae 22 cmd[0] = 0x01;
ShaolinPoutine 0:656742ec86ae 23 cmd[1] = 0x00;
ShaolinPoutine 0:656742ec86ae 24 i2c.write(addr, cmd, 2);
ShaolinPoutine 0:656742ec86ae 25
ShaolinPoutine 0:656742ec86ae 26 wait(0.5);
ShaolinPoutine 0:656742ec86ae 27
ShaolinPoutine 0:656742ec86ae 28 cmd[0] = 0x00;
ShaolinPoutine 0:656742ec86ae 29 i2c.write(addr, cmd, 1);
ShaolinPoutine 0:656742ec86ae 30 i2c.read(addr, cmd, 2);
ShaolinPoutine 0:656742ec86ae 31
ShaolinPoutine 0:656742ec86ae 32 float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
ShaolinPoutine 0:656742ec86ae 33 printf("Temp = %.2f\n", tmp);*/
ShaolinPoutine 0:656742ec86ae 34
ShaolinPoutine 0:656742ec86ae 35 }