Hi.
I have some problems witch i2c on mkl15z128.
I try to communicate with RTC DS1338. For beginning i try get on the bug START condition, Slave address write and STOP condition.
But i have problems.
I use PTE0/TPE1 GPIO pins.
My init function
void init_I2C(void)
{
SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK; //Turn on clock to I2C1 module
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;
/* configure GPIO for I2C1 function */
PORTE_PCR0 = PORT_PCR_ISF_MASK | PORT_PCR_MUX(6);
PORTE_PCR1 = PORT_PCR_ISF_MASK | PORT_PCR_MUX(6);
I2C1_F = I2C_F_ICR(14) | I2C_F_MULT(0);
I2C1_C1 = I2C_C1_IICEN_MASK;
}
My functions for write i take from examples
void i2c_Wait(void)
{
while((I2C1_S & I2C_S_IICIF_MASK)==0)
{
wdtFeed();
}
I2C1_S |= I2C_S_IICIF_MASK;
}
void IIC_StartTransmission (unsigned char SlaveID, unsigned char Mode)
{
if(Mode == MWSR)
{
/* set transmission mode */
MasterTransmission = MWSR;
}
else
{
/* set transmission mode */
MasterTransmission = MRSW;
}
/* shift ID in right possition */
SlaveID = (unsigned char) MMA7660_I2C_ADDRESS << 1;
/* Set R/W bit at end of Slave Address */
SlaveID |= (unsigned char)MasterTransmission;
/* send start signal */
i2c_Start();
/* send ID with W/R bit */
i2c_write_byte(SlaveID);
}
void MMA7660WriteRegister(unsigned char u8RegisterAddress, unsigned char u8Data)
{
/* send data to slave */
IIC_StartTransmission(SlaveID,MWSR);
i2c_Wait();
/* Send I2C address */
I2C1_D = u8RegisterAddress;
i2c_Wait();
/* Send data */
I2C1_D = u8Data;
i2c_Wait();
i2c_Stop();
//Pause();
}
When i call MMA7660WriteRegister(0x1, 0x2) i have reboot device by WDT.
When i insert wdtFeed in while loop i have no reboot.
while((I2C1_S & I2C_S_IICIF_MASK)==0)
{
wdtFeed();
}
I have START condition but in I2C1_S i have no I2C_S_IICIF_MASK after START.
I have no idea what i do wrong. Pleas help me.