cancel
Showing results for 
Search instead for 
Did you mean: 

STR7 I2C Interrupt Not Working

court
Associate
Posted on April 19, 2007 at 07:57

STR7 I2C Interrupt Not Working

2 REPLIES 2
court
Associate
Posted on April 18, 2007 at 15:27

:-Y I'm frustrated trying to get the I2C to generate an interrupt when I set the STARTGenerate bit. I can use the I2C in polled mode talking to my slave device without any problems. But when I move to IRQ based communications the I2C never IRQ's! I have the following code as my main() and set a breakpoint in the STR71x_vectors.c I2C0_IRQHandler() and I never get there.

Before calling I2C_STARTGenerate, I2C0->CR has a value of 0x25 and the I2C0->SR1 has a value of 0x00. When I call I2C_STARTGenerate I2C0->CR stays the same and I2C0->SR1 has a value of 0x93. But I never get an IRQ. What am I missing?

Here is my code:

EIC_Init();

GPIO_Config( GPIO1, 0x6000, GPIO_AF_OD );

I2C_Init( I2C0 );

I2C_FCLKConfig( I2C0 );

I2C_OnOffConfig( I2C0, ENABLE );

I2C_AddressConfig ( I2C0, 0, I2C_Mode7 );

I2C_SpeedConfig( I2C0, 400000 );

I2C_AcknowledgeConfig( I2C0, ENABLE );

I2C_ITConfig( I2C0, ENABLE );

EIC_IRQChannelPriorityConfig( I2C0ITERR_IRQChannel, 2 );

EIC_IRQChannelConfig( I2C0ITERR_IRQChannel, ENABLE );

EIC_IRQChannelPriorityConfig( I2C0_IRQChannel, 7 );

EIC_IRQChannelConfig( I2C0_IRQChannel, ENABLE );

EIC_IRQConfig( ENABLE );

I2C_STARTGenerate( I2C0, ENABLE );

kleshov
Associate II
Posted on April 19, 2007 at 07:57

Here is my code, and it does generate an interrupt:

Code:

/* Configure relevant port lines as Alternate Function, Open Drain */

IOPORT0_PC0 &= ~0x000C;

IOPORT0_PC2 |= 0x000C;

I2C1_OAR2 = 0x40; /* System frequency range: 16.67-26.67 MHz */

I2C1_CCR = 0x92; /* Bus clock = 397 kHz */

I2C1_CR = 1 << 5; /* Enable peripheral */

I2C1_CR = 1 << 5 | /* Enable peripheral */

1 << 2 | /* Enable acknowledge */

1; /* Enable interrupts */

EIC_SIR8_bit.SIPL = DAC_PRIORITY; /* Configure the channel 7 priority */

EIC_SIR16_bit.SIPL = DAC_PRIORITY; /* Configure the channel 15 priority */

EIC_IER0 |= (1<<8 | 1<<16); /* Enable interrupt on channels 7, 15 */

I2C1_CR_OFF |= 1 << 3; /* Set START bit */

There are two interrupts associated with an I2C. Make sure you are looking at the right one.

Also pay attention to this note from the manual:

Note: To enable the I2C interface, write the I2Cn_CR register TWICE with PE=1 as the first write only activates the interface (only PE is set).

I don't know if the library does this for you. It probably does, since you are reading I2C0_CR as 0x25, which is the correct value.

Regards,

- mike