cancel
Showing results for 
Search instead for 
Did you mean: 

I2C not working on Mapped Pins, why?

MikeP
Senior

Hello,

I am using an STM32G061K6T (only MCU I could find in stock at the time) and I'm try to communicate with an EEPROM via I2C.

I have the SCL and SDA mapped to PA9 and PA10, respectively with 3K3 Pull up resistors. SDA pin is pulled up and stays up however SCL is High when the MCU is held in reset but then it is pulled low and I don't know why. This happens with an EEPROM connected.

I have mapped SCL and SDA to PB6 and PB7 and this works and I can communicate with the EEPROM.

My questions are:

Why does it work when the pins are mapped differently - am I missing something in the datasheet ?

Why is the pin pulled low when the MCU is awake., despite the 3K3 pullup.

I have also checked for shorts

Any help would be apricated. Thanks, Mike

1 ACCEPTED SOLUTION

Accepted Solutions
sam2399
Associate

Hi all, I had the same problem and found that if CubeMX autogenerates the code then you'll need to add 'GPIO_InitStruct.Alternate = GPIO_AF6_I2C1;' to the GPIO pin struct definition in the 'HAL_I2C_MspInit' function. This is because if you use PA9 and PA10 as the i2c1 peripheral pins instead of the default pins PB6 and PB7 CubeMX doesn't add the alternate function definition to the struct mapping the pins. Hope that makes sense.

View solution in original post

10 REPLIES 10
MikeP
Senior

I have also tried 1K resistor and it still gets pulled low with the MCU awake.

TDK
Guru

I would guess a hardware error. Unlikely, but perhaps the EEPROM is holding SCL low. If you can get a logic analyzer on the lines it may yield better information. See what happens if the EEPROM is not connected. Try initializing both PA9/PA10 and PB6/PB7 as I2C simultaneously with the EEPROM connected to PB6/PB7 and see what happens.

If you feel a post has answered your question, please click "Accept as Solution".
MikeP
Senior

Hi, Thanks for your reply, sorry in my initial description I meant with the EEPROM unconnected, so the SCL pin is high when the MCU is in reset but as soon as its released SCL Pin goes low. - This says to me that its something my MCU configuration ?!

How do I initialise both both PA9/PA10 and PB6/PB7 at the same time? I'm using CubeMX and this only allows i2c set (if that makes sense).

Which PA10/PA9?

What is the pulled-down voltage level at 3k3 and at 1k pullup (no need to swap resistor, I just need to know if it's significantly less than VDD * R/5k1)?

JW

Double check the AF settings from the data sheet, different pins can have different AF mux values.

The Data Sheet and CubeMX are always 100% correct or agreement, but the odds of the DS being correct are bankable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello,

The pulled down voltage is literally 80mV and is 3.32V when held in reset

Mike

Hello,

I have checked the Alternative functions and everything looks okay, at least to me

0693W00000FE0LCQA1.png

QSHAO.1
ST Employee

A statement of "Pins PA9/PA10 can be remapped in place of pins PA11/PA12 (default mapping), using SYSCFG_CFGR1 register" is in G0 datasheet. it may provide some clue to fix this issue?

sam2399
Associate

Hi all, I had the same problem and found that if CubeMX autogenerates the code then you'll need to add 'GPIO_InitStruct.Alternate = GPIO_AF6_I2C1;' to the GPIO pin struct definition in the 'HAL_I2C_MspInit' function. This is because if you use PA9 and PA10 as the i2c1 peripheral pins instead of the default pins PB6 and PB7 CubeMX doesn't add the alternate function definition to the struct mapping the pins. Hope that makes sense.