Question
I2C doesn't work!
Posted on October 15, 2014 at 11:38
Please, help me into get out of this trouble!
I' am working on discovery board STM32F429L-disco. In order to have an I2C available to drive an external device, I am using PC9 ad PA8 pins (I2C3), that are also used to drive the on board touch screen controller. (in orther to be sure I have also desoldered the controller from the board to have a plenty free I2C bus!!)The two pull up on the line are connected, so I can see with the scope the two line normally high.I use the following code to set the pin and to start and configure the peripheral:RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE); //Enable I2C3 peripheral clock RCC_AHB1PeriphClockCmd(GYRO_I2C_SDA_GPIO_CLK, ENABLE); //Enable gpio pin clock RCC_AHB1PeriphClockCmd(GYRO_I2C_SCL_GPIO_CLK, ENABLE); //Enable gpio pin clock GPIO_PinAFConfig(GYRO_I2C_SDA_PORT, GYRO_I2C_SDA_SOURCE, GYRO_I2C_SDA_AF); GPIO_PinAFConfig(GYRO_I2C_SCL_PORT, GYRO_I2C_SCL_SOURCE, GYRO_I2C_SCL_AF); /* Configure the GPIO_GYRO_I2C_SDA pin */ GPIO_InitStructure.GPIO_Pin = GYRO_I2C_SDA_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GYRO_I2C_SDA_PORT, &GPIO_InitStructure); /* Configure the GPIO_GYRO_I2C_SCL in */ GPIO_InitStructure.GPIO_Pin = GYRO_I2C_SCL_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GYRO_I2C_SCL_PORT, &GPIO_InitStructure); /* Configure the I2C init structure */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_ClockSpeed = 100000; I2C_InitStructure.I2C_OwnAddress1 = 0xA0; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_Init(GYRO_I2C, &I2C_InitStructure); I2C_Cmd(GYRO_I2C, ENABLE);////here also all the define:#define GYRO_I2C I2C3#define GYRO_I2C_CLK RCC_APB1Periph_I2C3#define GYRO_I2C_SDA_PIN GPIO_Pin_9#define GYRO_I2C_SDA_PORT GPIOC#define GYRO_I2C_SDA_GPIO_CLK RCC_AHB1Periph_GPIOC#define GYRO_I2C_SDA_SOURCE GPIO_PinSource9#define GYRO_I2C_SDA_AF GPIO_AF_I2C3#define GYRO_I2C_SCL_PIN GPIO_Pin_8#define GYRO_I2C_SCL_PORT GPIOA#define GYRO_I2C_SCL_GPIO_CLK RCC_AHB1Periph_GPIOA#define GYRO_I2C_SCL_SOURCE GPIO_PinSource8#define GYRO_I2C_SCL_AF GPIO_AF_I2C3In the main program I call the: I2C_GenerateSTART(GYRO_I2C, ENABLE);and the : I2C_Send7bitAddress(GYRO_I2C, 0x55, I2C_Direction_Receiver);After the start generation setting I aspect ther the peripheral is in master mode as wrote on the referance manual, but nothing happen! the two line remein high to clock generation no data.I also tried to add this controlwhile ((!I2C_CheckEvent(GYRO_I2C, I2C_EVENT_MASTER_MODE_SELECT))) {} and discovered that the I2C_EVENT_MASTER_MODE_SELECT condition is never true! so seems that the peripheral is not in master mode or is not active also after a start condition generation request.Please, can you tell me where I am wrong?thanks