Test

Dependencies:   mbed AccelSensor

main.cpp

Committer:
Alegrowin
Date:
2013-01-15
Revision:
3:4e4e4d7f6ee1
Parent:
2:3e6b509d7eca
Child:
4:3397631c2f65

File content as of revision 3:4e4e4d7f6ee1:

#include "mbed.h"

I2C i2c(p9, p10);        // sda, scl
Serial pc(USBTX, USBRX); // tx, rx
Serial Damn(p28,p27);


const int addr = 0x9A; // define the I2C Address for TC74-A0
const int Afficheur_addr = 0xE2; // define the I2C Address for 4*7seg display

int main()
{
    int temp = 0;
    int a,b,c;
    char cmd[2];
    
    wait(1);           //Make sure system is fully initialized
    
    cmd[0] = 0x76; 
    i2c.write(Afficheur_addr,cmd,1);
        
    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 2 :: %d\r\n\n", cmd[0]);

        cmd[0] = 0x7b;
        cmd[1] = 0x3E;
    
        i2c.write(Afficheur_addr,cmd,2);
        
        wait(0.07);
        
        cmd[0] = 0x7c;
        cmd[1] = 0x79;
    
        i2c.write(Afficheur_addr,cmd,2);
        
        wait(0.07);
        
        cmd[0] = 0x7d;
        cmd[1] = 0x77;
    
        i2c.write(Afficheur_addr,cmd,2);
        
        wait(0.07);
        
        cmd[0] = 0x7e;
        cmd[1] = 0x3F;
    
        i2c.write(Afficheur_addr,cmd,2);
        wait(1);
    }
}