Question
I2c2 start bit generation fail in STM32F103RB
Posted on May 29, 2011 at 12:41
Hi, all
I2c2 start bit generation fail - after timeout of 10 ms I2C_FLAG_SB = RESET = 0 but I2c1 work well read and write. anyone can help ?
More details: 10k poll up on each pin. Clock Speed - 50000.I2c2 start bit generation fail - after timeout of 10 ms I2C_FLAG_SB = RESET = 0 but I2c1 work well read and write.
More details: 10k poll up on each pin. Clock Speed - 50000. my code: /******************************************************************************* * Function Name : ISC_Config * Description : Configure the ISC interface * Input : None * Output : None * Return : None *******************************************************************************/ void I2C_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; /* Configure the SDA And the SCL line to alternate function Open Drain */ I2C_DeInit(I2C1); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF_OD; GPIO_Init(I2C_PORT, &GPIO_InitStructure); /* Configure the I2C peripheral */ I2C_SoftwareResetCmd(I2C1,ENABLE); I2C_SoftwareResetCmd(I2C1,DISABLE); I2C_Cmd(I2C1, DISABLE); I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVEADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = I2C_CLOCKSPEED; I2C_Init(I2C1, &I2C_InitStructure); I2C_Cmd(I2C1, ENABLE); I2C_AcknowledgeConfig (I2C1, DISABLE); I2C_DeInit(I2C2); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11; GPIO_Init(I2C_PORT, &GPIO_InitStructure); /* Configure the I2C peripheral */ I2C_SoftwareResetCmd(I2C2,ENABLE); I2C_SoftwareResetCmd(I2C2,DISABLE); I2C_Cmd(I2C2, DISABLE); I2C_Init(I2C2, &I2C_InitStructure); I2C_Cmd(I2C2, ENABLE); I2C_AcknowledgeConfig (I2C2, DISABLE); } /******************************************************************************* * Function Name : GenerateStartCondition * Description : Generates the I2C start condition * Input : None * Output : None * Return : TRUE - Start condition generated successfuly. FALSE - otherwise *******************************************************************************/ static BOOL GenerateStartCondition(void) { BOOL bRes=FALSE; BOOL bStatusChangeTimeout=FALSE; I2C_GenerateSTART (I2C2, ENABLE); if (TriggerTimeoutCounter(I2C_STATUS_CHANGE_TIMEOUT_MSEC)) { while ((I2C_GetFlagStatus (I2C2,I2C_FLAG_SB)== RESET) && !bStatusChangeTimeout) { if (IsTimeoutExpired()) bStatusChangeTimeout=TRUE; } if (!bStatusChangeTimeout) bRes=TRUE; } return bRes; } main() { return GenerateStartCondition(); //it's return false } #i2c2-start-bit-generation-fail-in-stm32f103rb