Test
Dependencies: mbed AccelSensor
Diff: main.cpp
- Revision:
- 1:60bb79c9a01e
- Parent:
- 0:b325845b05af
- Child:
- 2:3e6b509d7eca
--- a/main.cpp Mon Jan 14 17:27:19 2013 +0000 +++ b/main.cpp Mon Jan 14 18:05:34 2013 +0000 @@ -9,40 +9,47 @@ { int temp = 0; int a,b,c; - - - wait(1); - char cmd[2]; + wait(1); //Make sure system is fully initialized + while(1) { - pc.printf("\r\n\nStart of read Temperature\r\n"); + pc.printf("\r\n\nStart reading the temperature of TC74 on I2C\r\n"); //Méthode 1 - - i2c.start(); // - a = i2c.write(addr); - b = i2c.write(0x00); + //Utilisation des fonctions bas niveau - wait(0.07); - - i2c.start(); + i2c.start(); // Start condition + a = i2c.write(addr); // Write Device Address + b = i2c.write(0x00); // Write READ command of TC74 (voir page 8 de la datasheet du TC74) + + i2c.start(); //Reissue start condition + //Au lieu de faire Stop condition et Start de nouveau - c= i2c.write(addr|1); - temp = i2c.read(0); - i2c.stop(); + c= i2c.write(addr|1); //Adresse du Device en mode Lecture + temp = i2c.read(0); //Lecture de la valeur du registre de température + i2c.stop(); //Fermeture de la trame //Méthode 2 + //Utilisation des fonctions haut niveau + + cmd[0] = 0x0; //Command :: READ + cmd[1] = 0x0; //Param :: Unused in this case + i2c.write(addr, cmd, 1); //Issue required command to perform a write of the command + i2c.read(addr, cmd, 1); //Read the Data from the device - cmd[0] = 0x0; - cmd[1] = 0x0; - i2c.write(addr, cmd, 1); - i2c.read(addr, cmd, 1); + //-----------------Print out section ---------------------- + //Display device Address and informations + pc.printf("Device with address 0x%x with\r\n", addr); - pc.printf("Device at %d is reading %d degree\r\n", addr, cmd[0]); + //Prints out the result of Method 1 + //pc.printf("ACK1 :: %d\n\rACK2 :: %d\n\rACK3 :: %d\n\r", a,b,c); //ACK bits + pc.printf("Method 1 :: %d\n\r", temp); + + //Prints out the Data from Method 2 + pc.printf("Method 1 :: %d\r\n\n", cmd[0]); - pc.printf("ACK1 :: %d\n\rACK2 :: %d\n\rACK3 :: %d\n\r", a,b,c); - pc.printf("Temp :: %d\n\r", temp); + wait(1); } } \ No newline at end of file