This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS1224: MPU6050 read issue

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN,

Hello everybody,


I am trying to read a 6 axis accel/gyro via i2c with TMS570LS1224. The micro configuration has been done with HALcoGEN 4.06 (only i2c driver enabled, i2c pinmux, master mode, 7bit address, 8bit count and 400kHz). I have also added 10k pull-up resistors to SDA and SCL lines.

The reading sequence for this device (MPU-6050) is:

Master:  S -- AD+W --         -- RA --        -- S -- AD+R --                     -- NACK -- P

Salve:                        --  ack --       -- ack --                   -- ack -- Data --

S = start, AD= address, RA= register address, R/W = read or write bit, P= stop, ack= acknowledge, NACK= no acknowledge

This is my first time with i2c in Hercules MCU's so I excuse myself in advance for any fool error. The thecnical reference manual says that after every start condition, it follows the AD+R/W byte so I assumed (again, sorry if this is completly wrong) that if I previusly defined the slave address and R/W mode, the AD+W/R would be automatically put into the i2c bus so my attempt to read the sensor in code composer studio 6.1.1 is as follows:

/* USER CODE BEGIN (2) */


#define MPU_6050_addr 0x68
#define GYRO_XOUT_L 0x44
uint8 GYRO_X = 0;


/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    gioInit();
    i2cInit();
    _enable_interrupt_();
    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetSlaveAdd(i2cREG1, MPU_6050_addr);
    while(1)
    {
        i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
        i2cSetCount(i2cREG1,1);
        i2cSetStart(i2cREG1);
        i2cSendByte(i2cREG1, GYRO_XOUT_L); //RA

        i2cSetDirection(i2cREG1, I2C_RECEIVER);
        i2cSetCount(i2cREG1,1);
        i2cSetStart(i2cREG1);
        GYRO_X = i2cReceiveByte(i2cREG1); //data

        i2cSetStop(i2cREG1);
        i2cClearSCD(i2cREG1);
    }

/* USER CODE END */

    return 0;
}

My problem is that when I try to receive data from the sensor, the micro gets stuck into the while condition (while ((i2c->STR & (uint32)I2C_RX_INT) == 0U)) of the i2cReceiveByte function. I've also tried to send the AD+R/W instead of using i2cSetDirection but to no avail.


Could you please tell me what am I doing wrong?

I would greatly appreciate any help, tip, trick or example regarding MPU6050 and TMS570 interfacing.

Thanks in advance.

Mario

 

  • Not sure. Do you get an acknowledge from the slave when the master sends the address? If not, check that pin 9 of the MPU-6050 (AD0) is pulled low.
  • Hi Bob, thank you very much for taking the time to reply to this post.

    I went over the i2c section of the TRM again and noticed that the address+R/W byte is not sent automatically by the i2cStart and i2cSetDirection commands given the slave address is stored in the I2CSAR register. So I changed the setCNT to 2 in the initial data transfer in order to send adress+R/W and RA (register i wish to read) from the sensor.

    I am sure that de pin 9 (AD0) of the MPU-6050 is pulled low, so the address I am sending should correspond to that of the sensor. Looking at the changes of the i2c registers (I2CSTR and I2CMDR) while step by step running in CCS, it appears that I am receiving an acknowledge from MPU but unfortunately I do not have access to an oscilloscope by now so that I can confirm that, however I will keep on trying to figure it out. 

    Best regards,

    Mario