Hi,
I'm trying to configure the I2C for the Kinetis Kl25z dev board (in codewarrior as bareboard project). I want to use the PTE0 and PTE1 pins for the I2C-Communication. The I2C should be configured for 50kHz.
My question, I configured the I2C Modul, like this:
_____________________________________________________________________________________________
#include <stdio.h>
#include "derivative.h" /* include peripheral declarations */
int main(void)
{
int i=0;
//I2C clock on
SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK;
//Port clocks on
SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
//Set PIN as I2C1
PORTE_PCR0 = PORT_PCR_MUX(6);
PORTE_PCR1 = PORT_PCR_MUX(6);
//I2C Frequency Divider
I2C1_F = 0x27; //I2C to 50kHz
I2C1_C1 = 0x50; //Enable I2C Modul
I2C1_C1 |= I2C_C1_IICEN_MASK;
for (i = 0; i < 100; i++);
I2C1_C1 = 0x50;
return 0;
}
_____________________________________________________________________________________________
If the I2C is configured right, there should be a clock signal with 50kHz?
What register is missing to activaite the I2C Clock, I have no Clock signal on SCL?
thank you
Hi Ulrich,
I just have this I2C driver, actually the SMBus is nearly the same as I2C, you can modify the I2C driver to fulfill the SMBUS requirement.
Wish it helps you!
Jingjing
Hi Ulrich,
After you configure the I2C module, you need to transfer the I2C data, then you can see the i2c clock in the sck pin.
Besides, you should better add the external pullup resistor in the sck, sda pin.
Attached it the KL25 i2c driver, you can refer to it.
Any question, please let me know!
Hi
The following is the basic configuration of I2C1 on ports PTE0 and PTE1 on the KL25:
POWER_UP(4, SIM_SCGC4_I2C1); // enable clock to module
_CONFIG_PERIPHERAL(E, 0, (PE_0_I2C1_SDA | PORT_ODE | PORT_PS_UP_ENABLE)); // I2C1_SDA on PE0 (alt. function 6)
_CONFIG_PERIPHERAL(E, 1, (PE_1_I2C1_SCL | PORT_ODE | PORT_PS_UP_ENABLE)); // I2C1_SCL on PE1 (alt. function 6)
I2C1_F= 0x32; // set about 50kHz with 40MHz bus frequency
I2C1_C1 = (I2C_IEN); // enable I2C controller (0x80)
[complete code should check for bus-lockup and recovery before starting too]
See http://www.utasker.com/kinetis/FRDM-KL25Z.html and/or http://www.utasker.com/kinetis/TWR-KL25Z48M.html in case you prefer a complete industrial-quality solution (compatible with all Kinetis parts, including first and second generation parts with double-buffering - working around all erratas).
In your case I think there are three basic problems:
1. You haven't enabled open-drain mode with pull-ups on the ports (although the pull-ups are optional if there are external ones available)
2. The value 0x50 written to I2C1_C1 enables interrupts and master mode but don't actually enable the I2C operation
3. I2C master only generates clocks when actually sending data - if you don't send data the bus remains in high-impedance state so it is normal that there is no clock
Regards
Mark
I2C user's guide: http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF
[1 on 1 support available in English, German and French if ever needed]
Well,
I don't need a corrected code, It would help if someone has a functional i2c implementation - bareboard.
Hi,
You can refer the example I2C bareboard project for kl25z given in Code Warrior. It uses Process Expert component and communicates with on board accelerometer.
-Rini
Hi,
I wanted to do it without Process Expert, because I need to edit the whole code, so Process Expert is not helpful at all.
Is there no one which has a working i2c example, like it should be done after the ref.book? :smileycry: