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.

TMS320F28069: Count bytes available to be read from I2C

Part Number: TMS320F28069

In the past I have used Arduino microcontrollers to control touch screens made by 4DSystems over I2C.

Now I want to use a TI microcontroller, specifically the TMS320F28069, to control a 4DSystems touch screen over I2C.

On the Github account for 4DSystems, they have generic C code for controlling the touch screen. In order to use this generic C code, you yourself must implement the following functions:

uint16_t genieGetByteCount(void);
uint_least8_t genieGetByte(void);
uint_least8_t geniePeekByte(void);
void geniePutByte(uint_least8_t);

It doesn't seem as though we're able to 'peek' a byte from the I2C, and so I've had to simulate this functionality by writing the 'get' and 'peek' functions as follows:


bool has_peeked_byte = false;
uint_least8_t peeked_byte = '\0';

uint_least8_t genieGetByte(void)
{
    if ( has_peeked_byte )
    {
        has_peeked_byte = false;
        return peeked_byte;
    }

    // Put code here for reading from I2C
}

uint_least8_t geniePeekByte(void)
{
    if ( has_peeked_byte ) return peeked_byte;

    // If control reaches here, 'has_peeked_byte' is false,
    // which is important when invoking genieGetByte
    peeked_byte = genieGetByte();

    has_peeked_byte = true;

    return peeked_byte;
}

But now I'm wondering how I will implement the 'GetByteCount' function. Looking at the datasheet for the TMS320F28069, I see that it has a few I2C registers, and one of them is I2CCNT. I have seen code examples where this register is set before sending data (i.e. it is used to indicate how many bytes to send). But can it also be used to determine how many bytes are available to be read?

  • Hello Thomas,

    You can use the FIFO mode on the I2C peripheral to transmit/receive multiple bytes and keep track of them. Specifically, the TXFFST bits of the I2CFFTX register and the RXFFST bits of the I2CFFRX register can be used to monitor the status of the number of bytes sent/received in the I2C FIFO. The I2CCNT register does NOT reflect any status on the number of bytes sent. To quote the device manual, "The internal data counter is decremented by 1 for each byte transferred (I2CCNT remains unchanged)."

    Best regards,

    Omer Amir