AnsweredAssumed Answered

KL26Z i2c problem - IICIF flag.

Question asked by Arkadiusz Motyka on Aug 22, 2017
Latest reply on Aug 27, 2017 by Kerry Zhou

Hi, 

Firstly I want to apologise for my English, it's not my native language.

I'm using KL26Z128VLH4 processor and I want to start i2c module. The code hangs while waiting for IICIF flag. I tried with Processor Expert and without, with different CPU speed, with different GPIO. The best, my friend have got the same issue with KL46Z. 

Below is code I'm using:

void InitI2C(void){
SIM_BASE_PTR->SCGC5 |= SIM_SCGC5_PORTB_MASK; // clock for port B
SIM_BASE_PTR->SCGC4 |= SIM_SCGC4_I2C0_MASK; // clock for  I2C0

PORTB_BASE_PTR->PCR[0] = PORT_PCR_MUX(1UL<<2); //PTB0 I2C0 SCL
PORTB_BASE_PTR->PCR[1] = PORT_PCR_MUX(1UL<<2); //PTB1 I2C0 SDA


I2C0_BASE_PTR->F = 0x14; // baudrate: 300kHz
I2C0_BASE_PTR->C1 |= I2C_C1_IICEN_MASK; // enable I2C0
}

uint8_t BusyI2C(void){
while((I2C0_BASE_PTR->S & I2C_S_IICIF_MASK)==0){} //here program hangs
if(I2C0_BASE_PTR->S & I2C_S_RXAK_MASK){return 0;}
I2C0_BASE_PTR->S |= I2C_S_IICIF_MASK; // reset IICIF
return 1;
}

 

Thank you in advance for help

Outcomes