AnsweredAssumed Answered

I2C as a master in FRDM_K22F

Question asked by Negar Erfanian on Jul 13, 2015
Latest reply on Jul 29, 2015 by Jorge_Gonzalez

Hi,

 

Has anyone worked with K22F? I'm working on this project to use I2c as a master and I want to show the waveform on oscilloscope. the problem is it seems like the bus is always busy. I checked the initialization of the registers of I2C which is generated by processor and everything seems ok. this is the initialization generated by the processor expert:

void I2C0_Init(void) {

 

 

  /* Register 'I2C0_FLT' initialization */

  #ifdef I2C0_FLT_VALUE

  I2C0_FLT = I2C0_FLT_VALUE;

  #endif

 

 

  /* Register 'I2C0_A1' initialization */

  #ifdef I2C0_A1_VALUE

  I2C0_A1 = I2C0_A1_VALUE;

  #endif

 

 

  /* Register 'I2C0_C2' initialization */

  #ifdef I2C0_C2_VALUE

  I2C0_C2 = I2C0_C2_VALUE;

  #endif

 

 

  /* Register 'I2C0_RA' initialization */

  #ifdef I2C0_RA_VALUE

  I2C0_RA = I2C0_RA_VALUE;

  #endif

 

 

  /* Register 'I2C0_F' initialization */

  #ifdef I2C0_F_VALUE

  I2C0_F = I2C0_F_VALUE;

  #endif

 

 

  /* Register 'I2C0_A2' initialization */

  #ifdef I2C0_A2_VALUE

  I2C0_A2 = I2C0_A2_VALUE;

  #endif

 

 

  /* Register 'I2C0_SMB' initialization */

  #ifdef I2C0_SMB_VALUE

  I2C0_SMB = I2C0_SMB_VALUE;

  #endif

 

 

  /* Register 'I2C0_SLTL' initialization */

  #ifdef I2C0_SLTL_VALUE

  I2C0_SLTL = I2C0_SLTL_VALUE;

  #endif

 

 

  /* Register 'I2C0_SLTH' initialization */

  #ifdef I2C0_SLTH_VALUE

  I2C0_SLTH = I2C0_SLTH_VALUE;

  #endif

 

 

  /* Register 'I2C0_S' initialization */

  #ifdef I2C0_S_VALUE

  I2C0_S = I2C0_S_VALUE;

  #endif

 

 

  /* Register 'I2C0_C1' initialization */

  #ifdef I2C0_C1_VALUE_1

  I2C0_C1 = I2C0_C1_VALUE_1;

  #endif

 

 

  /* Register 'I2C0_C1' initialization */

  #if I2C0_C1_MASK_2

    #if I2C0_C1_MASK_2 == 0xFF

  I2C0_C1 = I2C0_C1_VALUE_2;

   #elif I2C0_C1_MASK_2 == I2C0_C1_VALUE_2

  I2C0_C1 |= I2C0_C1_VALUE_2;

    #elif I2C0_C1_VALUE_2 == 0

  I2C0_C1 &= ~I2C0_C1_MASK_2;

    #else

  I2C0_C1 = (I2C0_C1 & (~I2C0_C1_MASK_2)) | I2C0_C1_VALUE_2;

    #endif

  #elif defined(I2C0_C1_VALUE_2)

  I2C0_C1 = I2C0_C1_VALUE_2;

  #endif

}

 

and the main loop is:

 

for(;;){

 

 

   I2C0_C1 = I2C0_C1 | (1 << 7);//Enable I2C

   I2C0_C1 = I2C0_C1 | (1 << 6);

    I2C0_C1 = I2C0_C1 | (1 << 4);//TX mode

    I2C0_C1 = I2C0_C1 | (1 << 5);//start

if (! (I2C0_S & 0x20)){

 

 

  I2C0_D= 0x55;}

 

can anyone help me?

Thanks,

Outcomes