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.

TIVA: I2C: Send one byte and get 2 bytes



Hello,

I have to send one (1) byte (0xAA) via I2C  and then get 2 bytes in response. The code is:

//-------------------------------------- INIT -------------------------------------------------------------

I2CMasterInitExpClk (I2C6_BASE, SysCtrlClockGet (), false);

I2CMasterEnable (I2C6_BASE); 

//-------------------------------------- SEND ----------------------------------------------------------

I2CMasterSlaveAddrSet (I2C6_BASE, 0x48, false); //set slave address to 0x48, initiating write

I2CMasterDataPut (I2C6_BASE, 0xAA); //Put 0xAA in the FIFO

I2CMasterControl (I2C6_BASE, I2C_MASTER_CMD_SINGLE_SEND); //Send

while (I2CMasterBusy(I2C6_BASE)); //Wait till end of transaction

//-------------------------------------- RECEIVE ----------------------------------------------------------

I2CMasterSlaveAddrSet (I2C6_BASE, 0x48, true); //set slave address to 0x48, initiating read

I2CMasterControl (I2C6_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); //Receive

while (I2CMasterBusy(I2C6_BASE)); //Wait till end of transaction

Byte1 = I2CMasterDataGet (I2C6_BASE); //Read from FIFO

I2CMasterControl (I2C6_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); //Receive

while (I2CMasterBusy(I2C6_BASE)); //Wait till end of transaction

Byte2 = I2CMasterDataGet (I2C6_BASE); //Read from FIFO

//-------------------------------------------------------------------------------------------------------------------------------

Is this the right sequence ?

Before this code I set the pinout with code created with the Pinmux utility

Thanks,

Zvika

  • Hi Zvika,

    The Transmit section is fine. In the receive section since you want to recieve two bytes I would change the sequence as follows

    I2CMasterControl (I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); //Receive

    while (I2CMasterBusy(I2C6_BASE)); //Wait till end of transaction

    Byte1 = I2CMasterDataGet (I2C6_BASE); //Read from FIFO

    I2CMasterControl (I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); //Receive

    while (I2CMasterBusy(I2C6_BASE)); //Wait till end of transaction

    Byte2 = I2CMasterDataGet (I2C6_BASE); //Read from FIFO

    Amit