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