AnsweredAssumed Answered

stuck on I2C_FLAG_BUSY

Question asked by on Feb 16, 2016
Latest reply on Feb 17, 2016 by Amel N

I have try to send data from my stm to accelerator.
The problem is when I check the flag before start to sending first command it stuck on busy.(I2C_GetFlagStatus)
my pins are :D6, D7 (PINS that are free)

What I have try:
1. put the the status check in the end
2. I2C_CMD before the Init
3. Try to mapping other pins that on other ports than D

The code:

void WriteTrim(uint8_t TrimAddr)

      // While the bus is busy 
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
   //Send START condition
   I2C_GenerateSTART(I2C1, ENABLE);
   // poll on EV5 and clear it 

   while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
   // Send  address for write
   I2C_Send7bitAddress(I2C1, TrimAddr, I2C_Direction_Transmitter);
//---- VERIFY EV8_1-----------
//poll EV6 and clear it 
   //poll EV8 and clear it
   while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTING));//

 void TrimInit(void)
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

//========== Configure GPIO ======================
     // Configurer as alternative function I2C

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;   
GPIO_Init(GPIOD, &GPIO_InitStructure);
// configure I2C parameters
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x33;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 100000;

I2C_Init(I2C1, &I2C_InitStructure);

// Enable the I2C peripheral
I2C_Cmd(I2C1, ENABLE);

Someone encouner this problem?