AnsweredAssumed Answered

STM32L152 - i2c interupt not firing

Question asked by PaulLeicester on Nov 30, 2012
Latest reply on Dec 7, 2012 by STOne-32
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




Outcomes