Register address not sent using I2C in TM4C123GH6PM board

133 views Asked by At

I have been testing the ADXL345 accelerometer using, being able to get the Device ID so as to check that it was properly wired. Now that I am trying to get the acceleration in the different axis,I am not able to complete it as the register address is not sent for some reason I don't know.

According to the datasheet of the accelerometer, in order to write a byte:

enter image description here

The code used:

    void initialize_accelerometer()
    {
        I2C0_MSA_R |=0x000000A6;    //Specify the slave address of the master and that the next operation is a Transmit or write
        I2C0_MDR_R=0x2D;    //Register address, this is the data not sent
        I2C0_MCS_R=0x00000003;  // (START, RUN);
        while(I2C0_MCS_R&I2C_MCS_BUSBSY){};
        if((I2C0_MCS_R&I2C_MCS_ERROR)==0)
        {
            I2C0_MDR_R=0x08;    //Data -> Set power control to measure
            I2C0_MCS_R=0x00000005;  // (RUN, STOP);
            if((I2C0_MCS_R&I2C_MCS_ERROR)==0)
            {
                set_data_format();
            }
        }

}

Testing with a logic analyser, the result is the following:

enter image description here

As you can see, all is sent but the register address. Can you help me to find the error?

Thanks, Javier

1

There are 1 answers

0
Javier On BEST ANSWER

Oh, reading the datasheet again I discovered that I masked the wrong bit, so changing while(I2C0_MCS_R&I2C_MCS_BUSBSY){}; for while(I2C0_MCS_R&I2C_MCS_BUSY){}; solved the problem.