Part Number: TMS570LC4357
Tool/software: Code Composer Studio
HI,
I'm trying to read data from a sensor with the I2C but I don't success.
This is the function that I use to read the data from sensor:
void I2CReceive(uint8_t SLAVE_ADDRESS, uint8_t reg, uint8 *buff)
{
while(i2cIsBusBusy (i2cREG2) == true);
i2cREG2->MDR = I2C_RESET_OUT;
i2cSetMode(i2cREG2, I2C_MASTER);
i2cSetSlaveAdd(i2cREG2, SLAVE_ADDRESS);
i2cSetDirection(i2cREG2, I2C_TRANSMITTER);
i2cSetCount(i2cREG2, 1);
i2cSetStart(i2cREG2);
while((i2cREG2->STR & (I2C_TX | I2C_ARDY)) == false); // To wait for the tx ready and register access ready
i2cSendByte(i2cREG2, reg);
// Start receiving the data from slave
// wait for ARDY before beginning the read phase of the transaction
while((i2cREG2->STR & I2C_ARDY) == false); // BLOCKED--------------------------------------------------
i2cREG2->MDR = I2C_RESET_OUT; // To set the MDR with I"C is out of reset
i2cSetMode(i2cREG2, I2C_MASTER);
i2cSetDirection(i2cREG2, I2C_RECEIVER);
i2cSetCount(i2cREG2, 1);
i2cSetStop(i2cREG2);
i2cSetStart(i2cREG2);
// To receive one byte
while((i2cREG2->STR &(I2C_RX | I2C_ARDY)) == true);
buff[0] = i2cREG2->DRR;
while(i2cIsBusBusy (i2cREG2) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG2) == false);
/* Clear the Stop condition */
i2cClearSCD(i2cREG2);
}
it remains blocked in the following line:
// Start receiving the data from slave
// wait for ARDY before beginning the read phase of the transaction
while((i2cREG2->STR & I2C_ARDY) == false); // BLOCKED--------------------------------------------------
what mistake did I make?
Best Regards
Pisc