cancel
Showing results for 
Search instead for 
Did you mean: 

I2C_GetFlagStatus problem

javidan
Associate
Posted on February 02, 2016 at 21:32

hi

I have  problem with this function I2C_GetFlagStatus, when I call it  as bellow :

I2C_GetFlagStatus(IOE_I2C, I2C_FLAG_SB)

/**************************************

FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)

{

  FlagStatus bitstatus = RESET;

  __IO uint32_t i2creg = 0, i2cxbase = 0;

  /* Check the parameters */

  assert_param(IS_I2C_ALL_PERIPH(I2Cx));

  assert_param(IS_I2C_GET_FLAG(I2C_FLAG));

  /* Get the I2Cx peripheral base address */

  i2cxbase = (uint32_t)I2Cx;

  

  /* Read flag register index */

  i2creg = I2C_FLAG >> 28;

  

  /* Get bit[23:0] of the flag */

  I2C_FLAG &= FLAG_MASK;

  

  if(i2creg != 0)

  {

    /* Get the I2Cx SR1 register address */

    i2cxbase += 0x14;

  }

  else

  {

    /* Flag in I2Cx SR2 Register */

    I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);

    /* Get the I2Cx SR2 register address */

    i2cxbase += 0x18;

  }

  

  if(((*(__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)RESET)

  {

    /* I2C_FLAG is set */

    bitstatus = SET;

  }

  else

  {

    /* I2C_FLAG is reset */

    bitstatus = RESET;

  }

  

  /* Return the I2C_FLAG status */

  return  bitstatus;

}

/**************************************

the function returns set bitstatuse but when I call it as bellow:

I2C_GetFlagStatus(IOE_I2C, I2C_FLAG_ADDR)

the function returns reset bitstatuse! 

I'm very confused since  value of I2C_FLAG_SB is 0x10000001 and value of I2C_FLAG_ADDR is 0x10000002. 

the program should be return set bitstatuse to work, how can I fix it?

#i2c #i2c_getflagstatus
0 REPLIES 0