cancel
Showing results for 
Search instead for 
Did you mean: 

stuck on I2C_FLAG_BUSY

galcohen92
Associate II
Posted on February 16, 2016 at 17:44

Hello,

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 

   while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

   //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_PinAFConfig(GPIOD,GPIO_PinSource6,GPIO_AF_I2C1);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource7,GPIO_AF_I2C1);

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_DeInit(I2C1);

I2C_Init(I2C1, &I2C_InitStructure);

// Enable the I2C peripheral

I2C_Cmd(I2C1, ENABLE);

}

Someone encouner this problem?

#i2c
3 REPLIES 3
clark2
Associate II
Posted on February 16, 2016 at 18:41

The BUSY flag is set on detection of SDA or SCL being low.  Have you checked the level of these signals?  You do have pullup resitors on them?

galcohen92
Associate II
Posted on February 17, 2016 at 15:31

sorry for taking me time to answer. I just want to be sure what was the problem. 

one of the pins was down so I switched the pins and now I succeed to pass the ''busy flag''.

Thanks for the help!

Amel NASRI
ST Employee
Posted on February 17, 2016 at 17:37

Hi cohen.gal,

Unfortunately your lst post is empty.

Could you please update on the status of the faced issue r answer Clive's questions?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.