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.

TMS570LC4357: I2C receive issue

Part Number: TMS570LC4357

Hello,

I am trying to communicate the TMS570LC4357 (master) with an Arduino (slave) via I2C. The arduino is getting the request and it is sending three bytes, however they are not received by the microcontroller.

I know the communication is working because I am able to send data to the Arduino, using the sendByte function (for some reason with the i2cSend it doesn't work), but I am not capable of receiving.

This is my code:

uint8 *r_buff = &RX_PACK[0];
uint32 buf_size = bsize;
uint32 i = 0;
i2cInit();

while(i2cIsMasterReady(i2cREG2) != true);

i2cSetSlaveAdd(i2cREG2, slave_address); // for the I2C1, the master
i2cSetDirection(i2cREG2, I2C_RECEIVER);
i2cSetCount(i2cREG2, 3);
i2cSetMode(i2cREG2, I2C_MASTER);

i2cSetStop(i2cREG2);
i2cSetStart(i2cREG2); // only for the master

/* Tranmit DATA_COUNT number of data in Polling mode */
i2cReceive(i2cREG2, 3, &RX_PACK[0]);

/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG2) == true);

i2cClearSCD(i2cREG2);

 


In this case, it is stuck at the i2cIsMasterReady statement. If I remove this line, it gets until the end of the main but no data is received.


Ground, SDA and SCL are connected to each other.

Thank you for your help. Best regards,

Sergio

  • Hello Sergio,

    1. The MST is cleared after generating a STOP condition. It is not cleared before starting  the 1st transaction in master mode. You don't need to check this bit before initiating your 1st transaction.

    2. reading data from a slave is very similar to writing, but  with some extra steps which depends on the protocol defined by slave. In order to read from a slave, the master must first tell the slave which register or address it wishes to read from. This is done by the master by sending the slave address with the R/nW = 0 (write), followed by the register address. Once the slave ACK this register address, the master will send a START condition, followed by the slave address with R/nW=1 (read). The slave will ACK the read request, and the master releases the SDA bus and supplies the clock to the slave continuously. At the end of every byte of data, the master will send ACK to the slave to let the salev know that it is ready for more data. Once the master has received expected number of bytes, it will send a NACK, then STOP condition.

    I don't know how I2C slave is implemented in Arduino MCU.