2014-04-08 11:48 AM
Hi I'
m working on STM32F401,
I configure I2C1 port as an I2C Master
at ''init_I2C1(void)'', and I succeed to communicate with the slave side. Now I'm trying to configure I2C3port as an I2C Master
at ''init_I2C3(void)'' But The SDA3 pin (PB4) stay low and I can't communicate.What I'm doing wrong? #i2c #coide-1.7.8 #special-kind-of-stupid #stm32f4012014-04-08 12:09 PM
Your code looks good.
Does PB4 stay low even when the I2C slave is not connected ? Ideally, try with PB4 connected to nothing (you work on discovery board or your own design?) My guess is that transient states from reset to I2C3/GPIO init might trouble the slave, and the slave maintains SDA low.2014-04-09 05:08 AM
Thanks ,
That happens when the slave side is connected or not connected.I working with the STM32F401-DICO board .When i start debugging the project the PB4 pin is in''high'' state.When the debugger execute the command ''GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_I2C3); // SDA '' the PB4 pin go to ''low'' state.2014-04-09 05:34 AM
Looking deeper the RM and the ST library, I tumbled on that:
#define GPIO_AF9_I2C2 ((uint8_t)0x09) /* I2C2 Alternate Function mapping (Only for STM32F401xx Devices) */ #define GPIO_AF9_I2C3 ((uint8_t)0x09) /* I2C3 Alternate Function mapping (Only for STM32F401xx Devices) */ I bet it will solve your issue.2014-04-09 06:03 AM
It's already define on the stm32f4xx_gpio.h
#define GPIO_AF9_I2C2 ((uint8_t)0x09) /* I2C2 Alternate Function mapping (Only for STM32F401xx Devices) */#define GPIO_AF9_I2C3 ((uint8_t)0x09) /* I2C3 Alternate Function mapping (Only for STM32F401xx Devices) */2014-04-09 06:13 AM
Thanks,
I configure the commands: // Connect I2C3 pins to AF GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_I2C3); // SCL GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF9_I2C3); // SDAand it's works.Thanks.2014-04-09 08:11 AM
Looking deeper the RM and the ST library, I tumbled on that:
Another good call there. The PB4 option wasn't on some of the other earlier parts, and the AF mux is normally 4, and that was empty on PB4, what the heck was ST thinking? The pin escape strategy on these parts seems poorly considered at times. I can see this biting a number of people.2014-04-09 08:29 AM
Now that's some special kind of stupid!!!
2015-07-19 07:32 AM
Albeit this issue is addressed in the newer release of the STM's STM32F4 Standard Peripheral Library, the problem can be experienced if using CooCox CoIDE as development environment! If one uses the library repository available through the CoIDE, he will be offered to download an older version of the ''stm32f4xx_gpio.h'' file, which uses AlternateFunction04 for SDA pin for the I2C2, and I2C3 interface.
One will have to either replace files used with newer ones, or do some manual modifications. Quick test of e.g. I2C2 interface would be to use these lines:GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, (uint8_t)0x04); /* SCL - AF4 */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, (uint8_t)0x09); /* SDA - AF9 */
=)