2016-02-16 08:44 AM
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 end2. I2C_CMD before the Init3. Try to mapping other pins that on other ports than DThe 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 I2CGPIO_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 parametersI2C_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 peripheralI2C_Cmd(I2C1, ENABLE);}Someone encouner this problem? #i2c
2016-02-16 09:41 AM
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?
2016-02-17 06:31 AM
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!2016-02-17 08:37 AM
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.