AnsweredAssumed Answered

LpcXpresso802

Question asked by Mihai Robu on Aug 30, 2018
Latest reply on Sep 3, 2018 by Kerry Zhou

Hi. I'm new to the embedded world. I have a LPCXpresso802 Board and an accelerometer MPU6050.

I want to read data from Mpu6050 using I2C. I use LPCOpen Lib but I don't understand that well. I was able to connect with him but I guess I don't extract the data from where I need. I modified this code to read data from 0x68 because I know that is MPU6050 access register. 

 

#define MPU_I2CAddress             0x68

void MPU_read(float *data, uint8_t *orgdatabuffer)
{
    uint8_t  LM75_Buf[8];
    WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_IDLE); // Wait for the master state to be idle
    LPC_I2C0->MSTDAT = (MPU_I2CAddress<<1) | 0;       // Address with 0 for RWn bit (WRITE)
    LPC_I2C0->MSTCTL = CTL_MSTSTART;                   // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.
    WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX);   // Wait for the address to be ACK'd
    LPC_I2C0->MSTDAT = 0x00;
    LPC_I2C0->MSTCTL = CTL_MSTCONTINUE;
    WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX);   // Wait for the address to be ACK'd
   
    LPC_I2C0->MSTDAT = MPU_I2CAddress<<1) | 1;       // Address with 1 for RWn bit (READ)
    LPC_I2C0->MSTCTL = CTL_MSTSTART;                   // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.
    while ((LPC_I2C0->STAT & MASTER_STATE_MASK) != STAT_MSTRX)
    {
       
    }
    MPU_Buf[0] = LPC_I2C0->MSTDAT;
    LPC_I2C0->MSTCTL = CTL_MSTCONTINUE;
    WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_RX);   // Wait for the address to be ACK'd
    while ((LPC_I2C0->STAT & MASTER_STATE_MASK) != STAT_MSTRX)
    {
       
    }

   MPU_Buf[1] = LPC_I2C0->MSTDAT;
    LPC_I2C0->MSTCTL = CTL_MSTSTOP;   
    while ((LPC_I2C0->STAT & MASTER_STATE_MASK) != STAT_MSTIDLE)
    {
       
    }
*data= (LM75_Buf[0]+(LM75_Buf[1]);
Can you help me ?
Mihai R.

Outcomes