cancel
Showing results for 
Search instead for 
Did you mean: 

I2C3 configuration

gil23
Associate III
Posted on April 08, 2014 at 20:48

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 I2C3

port 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 #stm32f401
8 REPLIES 8
stm322399
Senior
Posted on April 08, 2014 at 21:09

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.

gil23
Associate III
Posted on April 09, 2014 at 14:08

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.

 

stm322399
Senior
Posted on April 09, 2014 at 14:34

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.

gil23
Associate III
Posted on April 09, 2014 at 15:03

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) */

gil23
Associate III
Posted on April 09, 2014 at 15:13

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); // SDA

and it's works.

Thanks.

Posted on April 09, 2014 at 17:11

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 09, 2014 at 17:29

Now that's some special kind of stupid!!!

0690X00000605PqQAI.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Matej Zub?i?
Associate II
Posted on July 19, 2015 at 16:32

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 */

=)