i2c

Dependencies:   mbed

Committer:
qaz
Date:
Sat Jul 18 08:23:26 2020 +0000
Revision:
0:519691976fbc
dasfd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
qaz 0:519691976fbc 1 #include "mbed.h"
qaz 0:519691976fbc 2
qaz 0:519691976fbc 3 // Read temperatures from Grid-EYE
qaz 0:519691976fbc 4 // note i2c stuff does not need a special ,h file
qaz 0:519691976fbc 5
qaz 0:519691976fbc 6 I2C i2c(PTE0, PTE1);
qaz 0:519691976fbc 7
qaz 0:519691976fbc 8 const int addr = 0x90;
qaz 0:519691976fbc 9
qaz 0:519691976fbc 10 int main() {
qaz 0:519691976fbc 11 char cmd[2];
qaz 0:519691976fbc 12 while (1) {
qaz 0:519691976fbc 13 cmd[0] = 0x01;
qaz 0:519691976fbc 14 cmd[1] = 0x00;
qaz 0:519691976fbc 15 i2c.write(addr, cmd, 2);
qaz 0:519691976fbc 16 wait(0.5);
qaz 0:519691976fbc 17 cmd[0] = 0x00;
qaz 0:519691976fbc 18 i2c.write(addr, cmd, 1);
qaz 0:519691976fbc 19 i2c.read(addr, cmd, 2);
qaz 0:519691976fbc 20
qaz 0:519691976fbc 21 float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
qaz 0:519691976fbc 22 printf("Temp = %.2f\n", tmp);
qaz 0:519691976fbc 23 }
qaz 0:519691976fbc 24 }