I2C not working on Mapped Pins, why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 4:22 AM
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
Solved! Go to Solution.
- Labels:
-
EEPROM devices
-
I2C
-
STM32G0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-19 4:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 5:24 AM
I have also tried 1K resistor and it still gets pulled low with the MCU awake.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 6:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 7:02 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 2:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 2:39 PM
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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-27 11:54 PM
Hello,
The pulled down voltage is literally 80mV and is 3.32V when held in reset
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-28 12:02 AM
Hello,
I have checked the Alternative functions and everything looks okay, at least to me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-28 1:20 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-19 4:36 AM
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.
