AnsweredAssumed Answered

No proper I2C clock. Is my baudrate calculation correcT?

Question asked by clive palmer on Jun 9, 2014
Latest reply on Jun 11, 2014 by Mark Butcher

I'm trying to get some I2C ISR code working on my KL02Z device. I'm getting complete garbage with no reliable start sequence  clock. I am getting a bit bogged down.

Is there anyone who can verify my I2C init and baud rate calculation? Am I doing something stupid here?

 

 

void i2c_master_init(void)

{

// disable IRQ I2C0 vector is 24

 

 

  NVIC_ICER = 1 << (8%32);

  SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK;  // enable IIC0 clock

  SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // enable PORTA clock

 

  PORTA_PCR3 |= PORT_PCR_MUX(2);

 

  PORTA_PCR4 |= PORT_PCR_MUX(2);

 

   /* Configure Divider Register - about 375K baud rate with 24MHZ bus clock */

I2C0_F |= (I2C_F_MULT(1) | I2C_F_ICR(9));

 

  I2C0_C1 |= (I2C_C1_IICEN_MASK |  // enable IIC

  I2C_C1_IICIE_MASK |  // interrupt enable

  I2C_C1_TX_MASK);  // enable TX mode

 

   // enable_irq(8);

 

  NVIC_ICPR |= 1 << (8%32);

 

  NVIC_ISER |= 1 << (8%32);

}

 

If I perform a write with a address then I start off with something like............

 

 

I2C0_S |= I2C_S_IICIF_MASK;

 

NVIC_ICER = 1 << (8%32);

I2C0_C1 |= I2C_C1_TX_MASK; // write direction

I2C0_C1 |= I2C_C1_MST_MASK; // Generate START SIGNAL

I2C0_D = ((addr << 1) | WRITE); // Write 7-bit Slave Address + WRITE bit

while (0 == (I2C0_S & I2C_S_IICIF_MASK))

{ };  // wait for address transferred

//enable_irq(8);

 


Outcomes