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.

EK-TM4C1294XL: I2C Interrupt

Part Number: EK-TM4C1294XL

Hi

I'm not able to get interrupt form I2C. Is the following setup code right?

// set PB2, PB3 for I2C
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
// I2C over PB2, PB3
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

// enable I2C0
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
// wait peripheral ready
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0));

I2CMasterInitExpClk(I2C0_BASE, clock, false);

I2CIntRegister(I2C0_BASE, I2C0_handler);

I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_STOP |
I2C_MASTER_INT_NACK |
I2C_MASTER_INT_DATA |
I2C_MASTER_INT_TIMEOUT);

I2CMasterEnable(I2C0_BASE);

If I try to send data to unconnected device I expect to receice NACK interrupt....

I2CMasterSlaveAddrSet(I2C0_BASE, 0x55, false);

I2CMasterDataPut(I2C0_BASE, '*');
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(true);

But nothing...

Regards

  • Hello Luca,

    Do you have any of the system wide interrupt enable API's in your code as well?

    All I see is I2C configuration code but you need these calls in addition:

    ROM_IntEnable(INT_I2C0);
    ROM_IntMasterEnable();

    (ROM prefix is optional)

    Also do you have a SysCtlPeripheralEnable for SYSCTL_PERIPH_GPIOB?

  • Hi Ralph

    Now I have interrupts, not adding your code only changing pin setup for SCL and SDA as follows:

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    I think that I have the ARB lost interrupt that I don't have enabled.

    I wolud like to use interrupt because try to send a command using polling to an unconnected peripheral I don't get any error, is this possible?

    Regards

     

  • Hi Ralph

    Looking at the TIVA datasheet I write this simple polling routine to write 2 or more byte. But if I step true the code I never have error also without any connected slave???

    bool I2CWrite(uint8_t address, uint8_t count)
    {
    bool esito = false;
    bool end = false;
    
        g_i2c0.txptr = 0;
        //  Write slave address
        I2CMasterSlaveAddrSet(I2C0_BASE, address, false);
        //  Write data
        I2CMasterDataPut(I2C0_BASE, g_i2c0.txd[g_i2c0.txptr++]);
        //  Start transfer
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        //
        do
        {
            while(I2CMasterBusy(I2C0_BASE));
            //
            if( I2CMasterErr(I2C0_BASE) )
            {
                //  Abort transfer
                I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_STOP);
                end = true;
            }
            else
            {
                //
                if( g_i2c0.txptr < count )
                {
                    //  Write next data
                    I2CMasterDataPut(I2C0_BASE, g_i2c0.txd[g_i2c0.txptr++]);
                    //  Continue transfer
                    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
                }
                else
                {
                    //  Finish transfer
                    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
                    while(I2CMasterBusy(I2C0_BASE));
                    if( !I2CMasterErr(I2C0_BASE) )
                    {
                        esito = true;
                    }
                    end = true;
                }
            }
        } while( !end );
    
        return( esito );
    }
    
    

  • Hello Luca,

    Sorry for not catching the pin configurations on my first reply, glad you got that figured out.

    Regarding the lack of errors without a slave, my first thought is that perhaps you aren't even getting to a point where the I2C module sees an error, but since you have interrupts, that seems unlikely.

    When you debug the code, do you actually get to the I2CMasterErr lines?

    Also have you checked on an oscilloscope how the signal looks? I'm guessing you have the pull-ups installed already if you are getting interrupts.

  • Hello Ralph

    You are right I have error only using interrupt, but if I use polling I have not any error. Furthermore I have a strange behaviour in polling because the code I send to you Yesterday works only stepping trought not running, is like the data register will be overwritten... Today I go haead using interrupt...

    Regard

    Luca 

  • Hi Ralph

    If I call I2CMasterErr() inside the I2C master interrupt procedure and instead of use the I2CMasterBusy I use a flag cleared in the I2C master interrupt procedure all work fine.

    Regards