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.

LAUNCHXL2-RM46: I2C ICRRDY int problem

Part Number: LAUNCHXL2-RM46
Other Parts Discussed in Thread: HALCOGEN

I am having problem with code.

It doesn't go to i2c interrupt.


I placed Arduino to constantly send information to my TI controller and I want to receive them in interrupt routine.

This is my code for CCS:

sys_main.c:

i2cInit ();

i2cSetOwnAdd (i2cREG1, 0x0A);
i2cSetCount (i2cREG1, 10);
i2cSetDirection (i2cREG1, I2C_RECEIVER);
i2cSetMode (i2cREG1, I2C_MASTER);
i2cEnableNotification (i2cREG1, I2C_RX_INT);
_enable_IRQ ();

while (1);

This is my notification.c code:

i2cReceive (i2cREG1, 10, buff);
while (i2cIsBusBusy (i2cREG1) == true);

while (i2cIsStopDetected (i2cREG1) == 0);

clearSCD (i2cREG1);

This does not work. It never goes to interrupt.


If I place this in main (red color what I add):

i2cInit ();

i2cSetOwnAdd (i2cREG1, 0x0A);
i2cSetCount (i2cREG1, 10);
i2cSetDirection (i2cREG1, I2C_RECEIVER);
i2cSetMode (i2cREG1, I2C_MASTER);
i2cEnableNotification (i2cREG1, I2C_RX_INT);
_enable_IRQ ();

i2cReceive (i2cREG1, 10, buff_main);

while (i2cIsBusBusy (i2cREG1) == true);
while (i2cIsStopDetected (i2cREG1) == 0);

i2cClearSCD (i2cREG1);

while (1);

It receives few information (not 10 as proposed) in main and then enters interrupt.


What is my mistake?

Thanks!

  • Hello David,
    Could you check whether you have enabled I2C interrupt channel in VIM and ICRRDY interrupt in I2C Global Tab? I suppose you have set I2C pins in PINMUX Tab with checking i2c checkbox and setting appropriate pins.
    I suppose LAUNCHXL2-RM46 is slave and Arduino is master. PLease check whether Arduino and LAUNCHXL2-RM46 are set in a same way (baudrate, address mode, bit count, data count).
    I suppose in HALCoGen you set I2C as slave and receiver.
    After i2cInit() you need only to set slave address (i2cSetOwnAdd(i2cBASE_t *i2c, uint32 oadd)) and call i2cReceive(i2cBASE_t *i2c, uint32 length, uint8 * data). i2cReceive will set length and address of buffer where data to be stored when interrupt is generated (see description of where function is declared).
    You can refer to examples in HALCoGen. There is no fiel "example_i2cInterrupt_Communication.c" under RM46x folder but you can find it under RM48x folder, for example.

    Best regards,
    Miro
  • Thank you for answer Miro.

    I have used that example for I2C interrupt, but it is not what I want.
    All the things you've told me I have checked and they are all fine, except one thing. Both TI and Arduino are master devices.

    I want my TI to be master device, not slave. I do not want Arduino to be slave device either.

    This is project where I need to exchange information between two masters.

    If I write: i2cReceive (i2cREG1, DATA_COUNT, BUFF_REG); in sys_main.c, what should I write in notification.c? The same command? What if I do not know the length of data prior to the interrupt. i2cReceiveByte didn't help me. It only gets one piece of data, not all.

    I've tried placing the for loop and the first data I send is the number of information I want to read, and with that I set the DATA_COUNT, and read data, but it only works if I write those things in sys_main.c, not in notification.c.

  • Hello David,
    Do you have progress?

    Best regards,
    Miro
  • Unfortunately none.

    I cannot figure this one out. Do you have any idea?
  • Unfortunately not. Do you have any ideas?
  • Hello David,
    Usually in notification.c you have to call i2cReceive(). This function sets data length and address for the NEXT receive. You could call this function as well outside i2cNotification. You should call this function after data length of next data that will be received is known. Also, i2cReceive must not be called again until the transfer is complete.

    Best regards,
    Miro