cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 - i2c interupt not firing

paulcowper
Associate II
Posted on November 30, 2012 at 02:22

Hi there, I am wondering if anyone could help me on a small issue.

My I2C1_EV_IRQHandler is not firing when I2C_GenerateSTART(I2C1, ENABLE); is called. Can anyone see anything in the below setup code that is wrong or would cause this not to fire?

void INIT_InternalNetwork (void)
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 , ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C1);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C1);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0xA0;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Init(I2C1, &I2C_InitStructure);
I2C_Cmd(I2C1, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQn;
NVIC_Init(&NVIC_InitStructure);
I2C_ITConfig(I2C1, (I2C_IT_ERR), ENABLE);
I2C_ITConfig(I2C1, (I2C_IT_EVT | I2C_IT_BUF), ENABLE);
}

In a normal situation the ''

I2C_ITConfig(I2C1, (I2C_IT_EVT | I2C_IT_BUF), ENABLE);

'' line is called just before the start condition is set as per the documentation in the perf library. I have also swapped round the NVIC init before and after the I2C init, neither makes a difference. What I do notice, in SR2 BUSY is set, is this what may be causing my issue? If so what could be causing this and how would I normally go about clearing it? Some other info... In CR1, ACK and PE are set. in CR2, ITBUFEN, ITEVTEN and ITERREN are all set. Both lines are pulled up to 3.3v although at the moment only with 5.6K resistors (Still waiting on my next order of 10K) My scope shows no movement on either of the lines so I suspect that the start bit is not getting to the pins. Many thanks in advance Paul #i2c-stm32l-interupts
3 REPLIES 3
Posted on November 30, 2012 at 04:39

Nothing is jumping out.

The Busy status is indicative of the SDA line being low, if an external device is driving it low then you will need to clock it out.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
paulcowper
Associate II
Posted on November 30, 2012 at 12:27

Thank you for your reply,

I have checked this out and tried 8 pulses low on the clock line to attempt to clock it through and it seems not to make a difference.

Both lines are sitting high,

I have even disconnected all devices on the bus and it still has the busy flag set. My scope shows no movement on the lines at all and they are holding at 3.3v

I am currently half tempted to bit bang this bus, but would rather use whats on board.

Nickname12657_O
Associate III
Posted on December 07, 2012 at 15:44

Hi Paul,

Try to configure the GPIO pins then enable the alternate functions.

Let me know if it is OK or problem persists.

Cheers,

STOne-32