Test
Dependencies: mbed AccelSensor
main.cpp
- Committer:
- Alegrowin
- Date:
- 2013-01-14
- Revision:
- 1:60bb79c9a01e
- Parent:
- 0:b325845b05af
- Child:
- 2:3e6b509d7eca
File content as of revision 1:60bb79c9a01e:
#include "mbed.h" I2C i2c(p28, p27); // sda, scl Serial pc(USBTX, USBRX); // tx, rx const int addr = 0x9A; // define the I2C Address for TC74-A0 int main() { int temp = 0; int a,b,c; char cmd[2]; wait(1); //Make sure system is fully initialized while(1) { pc.printf("\r\n\nStart reading the temperature of TC74 on I2C\r\n"); //Méthode 1 //Utilisation des fonctions bas niveau 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); //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 //-----------------Print out section ---------------------- //Display device Address and informations pc.printf("Device with address 0x%x with\r\n", addr); //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]); wait(1); } }