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.

TM4C1294NCPDT: I2c start event detection

Part Number: TM4C1294NCPDT

Hi,

I am trying to detect i2c start event on TM4C1294 board with a falling edge triggered interrupt and bit banded clock pin named "SYSTEM_SCL".

ISR looks something like this,

void StartEventISR()

{

    if(SYSTEM_SCL)  

    {

       // DisableInterrupts();        // Disable all interrupts to sample GPIO for maximum precision

        DEBUG_PIN = 1;

        isStart = true;                         // Signals the start of transaction

        LED1 ^= 1;

        GPIO_PORTC_AHB_IM_R |= 0x10;    // Enable rising edge interrupt on SCL line for data sampling

    }

    DEBUG_PIN = 0;

    GPIO_PORTA_AHB_ICR_R |= 0x20;               // Clear interrupt after serving ISR

}

While the start event is detected successfully but sometimes there are false interrupt triggers along with it, please look at the picture attached.

Any help would be appreciated.

Thanks,

Nihit

  • Hello Nihit,

    We do not support applications that use DRM rather than TivaWare on TM4C E2E Forums.

    This is clearly stated in Point #4 of our Forum Guidelines: e2e.ti.com/.../695568

    If you update your code to include TivaWare, we can review at that point, but we'd need far more than just the ISR to comment on what may be impacting the false triggers.
  • There you go,

    void StartEventISR()
    {
    if(SYSTEM_SCL) // checks if SCL is high (Important while clock stretching)
    {

    DEBUG_PIN = 1;
    isStart = true; // Signals the start of transaction
    LED1 ^= 1;

    GPIOPinTypeGPIOInput(PORTC_BASE, GPIO_PIN_4);
    GPIOIntTypeSet(PORTC_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);
    GPIOIntEnable(PORTC_BASE, GPIO_PIN_4);
    IntEnable(INT_GPIOC_TM4C129);



    }
  • "TI THINKS RESOLVED" ?? This shows on my page
  • Hello Nihit,

    Is the TIvaWare code being called inside of your ISR...?

    It looks like that is configuration code, so I am a bit confused by that. I would not recommend enabling an interrupt inside of another interrupt as you open yourself up to possible race conditions and/or stack overflow. I would suggest using a flag to indicate to the main code to enable the interrupt instead.

    Moving a bit beyond that, looking at your picture, I am going to assume the blue is what you are using to try and stack the start condition right?

    If so, it simply looks to be toggling for each transition of high to low on the SDA line. Not sure if that is from triggering when the clock goes high and SDA is low, or the actual edge transition of SDA. In any case, it looks like you are catching all transitions instead of just the start condition. What you may want to try doing is after catching the start condition, prevent the interrupt from firing while I2C data is being put on the lines.

    However to do that, you would need to be able to differentiate from a read vs write operation as well as a read operation will have two start conditions.

    Beyond that complication, the rest should be straight forward since you know the clock frequency for I2C so you could just monitor until SCL stops toggling and then resume your start condition monitoring at that point.

    All of that said, it may help to also understand what you seek to gain by capturing that the start condition occurs... perhaps there may be a more elegant solution available.
  • Hi Ralph,

    Thank you so much for your valuable insight, apologize for not being clear. Apparently, the problem has been solved and the issue was due to nested interrupts. But i would like to have your feedback on the project i'm working on.

    So the pin(PB5) on which SDA line is connected is configured for falling edge interrupt like this,

    GPIOPinTypeGPIOInput(PORTA_BASE, GPIO_PIN_5);
    GPIOIntTypeSet(PORTA_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);
    GPIOIntEnable(PORTA_BASE, GPIO_PIN_5);
    IntEnable(INT_GPIOA_TM4C129);

    and "SYSTEM_SCL" is bit banded on PC4.

    When falling edge is detected on SDA line, the ISR checks for SYSTEM_SCL value, if it is "high" a start condition is detected. I've verified this setup on oscilloscope and it seems to work fine.

    After start condition has been detected, i want to enable rising edge interrupt on PC4(for SCL) to sample SDA line for data bits.

    The whole motto of this project is to read i2c bus "transparently" and log the data in text file.

    Thank you very much for your time.

    -NB