Hello,
I have refer the code path is: Kinetis L Sample Code\kl25_sc_rev3\klxx-sc-baremetal\src\projects\FRDM_KL25ZDemo\I2C.
This code is for I2C without interrupt.
My code is working without interrupt.
Now i have enable interrupt in initialization of I2C as
void init_I2C(void)
{
SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK; //Turn on clock to I2C0 module
I2C0_C1 = 0x00U;
I2C0_FLT = I2C_FLT_STOPF_MASK;
I2C0_S = I2C_S_IICIF_MASK;
// configure GPIO for I2C0 function //
PORTB_PCR0 = PORT_PCR_MUX(2);
PORTB_PCR1 = PORT_PCR_MUX(2);
NVIC_IPR2 = (uint32_t)((NVIC_IPR2 & (uint32_t)~(uint32_t)(
NVIC_IP_PRI_8(0x7F)
)) | (uint32_t)(
NVIC_IP_PRI_8(0x80)
));
NVIC_ISER |= NVIC_ISER_SETENA(0x0100);
I2C0_C2 = 0x00U;
I2C0_FLT = 0x00U;
I2C0_SMB = I2C_SMB_SLTF_MASK;
I2C0_F = 0x14; // set MULT and ICR
I2C0_C1 = I2C_C1_IICEN_MASK; // enable IIC
I2C0_C1 |= I2C_C1_IICIE_MASK; // enable I2C interrupt
}
I have written ISR routine by refering ISR routine generated by processor expert.
I have written ISR as
void i2c_isr(void)
{
FRDM_RED_LED_ClrVal(NULL); //RED LED ON
LDD_I2C_TErrorMask ErrorMask = 0x00U; /* Temporary variable for error mask */
register uint8_t Status; /* Temporary variable for status register */
Status = I2C_PDD_ReadStatusReg(I2C0_BASE_PTR); /* Safe status register */
I2C_PDD_ClearInterruptFlags(I2C0_BASE_PTR, (Status)); /* Clear interrupt flag */
}
In ISR i have toggle the RED LED.
According to this when interrupt occurs RED LED should be ON.
But ISR routine is not executing so RED LED is in OFF condition.
While debuging the code i have seen that after interrupt I2C_S resister shows the interrupt occurred.
The IICIF bit is set after interrupt occurred but my ISR routine is not executing though interrupt occurs.
Is there any syntax for writing ISR?
Reg,
Amreen