Hello,
I am working with KL25Z Controller for I2C.
I have to write my own code without using processor expert.
I am in a master mode.
I have written code for data transmit and receive data with accelerometer without using interrupt.
This code is working.
Now i have to use interrupt for data received.
I refer the reference manual of KL2Z .
I am not getting any flag indicating data received.
Please guide me how to detect data receive on I2C when i am in master mode.
Regards,
Amreen
Hi Amreen,
About the I2C interrupt code of KL25Z, you can refer to the configuration and write flow of our sample PE code, the path is :KL25 Sample Code\kl25_sc_rev10\klxx-sc-pex\projects\accelerometer_demo
You can download the sample code from this link: FRDM-KL25Z: 面向KL14/15/24/25 MCU的飞思卡尔Freedom开发平台
I wish it helps you!
If you still have question, please contact with me !
Best regards!
Jingjing
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
Hello Amreen:
Attached you can find sample code for a Master - Slave use case (2 separate projects). It is bareboard non processor expert code based on interrupts.
The image shows you the code behavior. Simply a KL25 (Master) issues a read command to another KL25 (Slave) and waits to receive 10 bytes.
I hope this serves you as reference.
Regards!
Jorge Gonzalez
Hello
I am having an issue with your sample code that you provided (thank you very much by the way).
I am using a KL25 board as Slave with a separate device connected as the master.
I have build and ran the code and it goes into the interrupt routine fine but the bus hangs. The SCL is pulled high and SDA is pulled low
In addition to the sample code I set the SBRC bit in the C2 register as I thought the clock might be stretching but this had no effect.
Thanks in advance
Hello,
I have generated code for CPU using processor expert.now i have to add I2C without processor expert.
I have tried code for I master mode.
Master mode code is working but without interrupt and i can see the transmission waveform.
It is not going into interrupt routine.
I have added
I2C0_C1 |= I2C_C1_IICIE_MASK; | // enable I2C interrupt |
in Enable_irq function
Also for interrupt i have made 2 changed into vector.c file.
1) Addition of I2C.h file
2) Define I2C interrupt at 0x18 this number.
after this setting it is going into interrupt.
But somehow i am not able to see the transmission.
I am working on it.I will let you know once i finished with it.
Also i saw that there is another method for interrupt linking as
#undef VECTOR_024
#define VECTOR_024 I2C-_IRQ_Handler
I tried this but it is not working in my case.
Please suggest on this.