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.

TMS320F280049C: How am I supposed to implement I2C communication

Part Number: TMS320F280049C


Hi, run into following problem.

There does not seem to be a way to detect easily and without polling following conditions:

1) All bytes inte the I2C FIFO have been transmitted.

2) The STOP condition has been generated and complete.

Yes, I get an interrupt when the TX FIFO is empty. Also I can get an interrupt when the tramit register contents have been moved to the shift register.

But that happens as soon as the last byte starts to be shifted out, not when it has been shifted out AND importantly the interrpt happens before the ACK/NACK bit has been detected by the I2C interface.

Now, this is a problem because the next message can depend on weather the previous message was NACKed or ACKed.

Further I can't  (must not) request the STOP condition to be generated before the last byte has been sent.

So where am I supposed to generate the STOP condition when there is no interrupt to hook to.

And it gets worse, where do I start the next transmission when there is no interrupt that tell the STOP condition generation in the hardware has completed.

I tried the STOP detected interrupt and the corresponding flag polling but I could not get that to work reliably. Sometimes it worked, sometimes not.

(there is strange note on the datasheet that say I need to wait for as long as the longest message before I communicate for the bus busy bit to be reliable, I don't get that either, but maybe this is not related to this question.

As a side note, I need to tallk to several I2C devices with different addresses and some of them reqularly NACK messages.

So what am I missing, this can't be that cumbersome border line design flaw?

I must be doing something wrong but I'm stuck at how to implement this efficiently, without polling, handling NACKs as they come and getting the messages moving back to back.''

  • Kustaa,

    I2C module does support NACK interrupt and STOP condition interrupt.

    Whenever any target (slave) sends NACK, I2C will generate NACK interrupt allowing you to handle in I2C ISR routine.If you wish to generate STOP condition only after you transmit / receive 'N' byte consider using non-repeat mode as this mode allows you use I2CCNT register which determines amount of I2C byte transaction before STOP condition can be generated.

    Have you already checked i2c_ex6_eeprom_interrupt interrupt example? This example shows how to interface with EEPROM using I2C without using polling method. This example shows how to transmit (or) receiver 'N' bytes using interrupt method.

    Regards,

    Manoj

  • Hi,

    thanks. 

    I have indeed checked that example before, but for us that is useless cause it does not show any of the details, it just calls the driver lib which we are cannot use in this project. Is the driver lib source code available somewhere so I could compare my code with that?

    I think I'm using the non-repeat mode, I just do:

                I2C_setSlaveAddress(I2CA_BASE, trxn->m_addr);

                I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE);

                I2C_setDataCount(I2CA_BASE, trxn->m_data_len);

                uint16_t i;

                for (i = 0; i < trxn->m_data_len; i++) {

                    I2C_putData(I2CA_BASE, trxn->m_data[i]);

                }

                I2C_setFIFOInterruptLevel(I2CA_BASE, I2C_FIFO_TXEMPTY, I2C_FIFO_RXFULL);

                I2C_enableInterrupt(I2CA_BASE, I2C_INT_TXFF);

                I2C_disableInterrupt(I2CA_BASE, I2C_INT_RXFF);

                 I2C_sendStartCondition(I2CA_BASE);


    Are you saying that the STOP condition should be automatically generated and that I should get the SDCINT (STOP) interrupt?

    I did try that and I did not, but if that is how it should be then I must have had a some other issue at that point in time and I have drawn the wrong conclusion.

  • Driver lib source code is available in below path.

    <DRIVERLIB>\driverlib\f28004x\driverlib

    In non-repeat mode, you can execute I2C_sendStopCondition(I2CA_BASE) just after I2C_sendStartCondition(I2CA_BASE). It will send the stop condition only after 'N' bytes of transaction is complete. This behavior is explained in I2C chapter.

    Regards,

    Manoj

  • Thanks, this is probably what I've been missing. I'll test this and come back. Thank you.

  • Closing this thread for now. Feel free to re-open this ticket if necessary but replying to this thread.