I2C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 3:59 AM
Hello
I am new with STM32 boards. I have 2 STM32 boards, and I am trying to get I2C communication between them. The boards I use are: NUCLEO-G071RB as the master, and STM32F412G-DISCO as the slave.
I success to send a response from the slave to the master once, but at other recalls I could not, unless I disconnect the slave's power and restarts it.
How can I solve the issue?
- Labels:
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 4:21 AM - edited ‎2024-05-01 3:54 PM
@MichaelR wrote:I am new with STM32 boards.
Do you have experience with any other microcontroller(s)?
Do you have experience with I2C in general?
@MichaelR wrote:I am trying to get I2C communication between them. ?
The classic mistake when doing this is to try to do both ends at once.
The trouble with that approach is that, when you have problems, you can't tell whether the issues are in the Master, or in the Slave - or both.
So I would strongly suggest that you concentrate on one end at a time:
https://www.avrfreaks.net/s/topic/a5C3l000000UYYaEAO/t146630?comment=P-1401100
@MichaelR wrote:How can I solve the issue?
Impossible to tell as we can't see what you have done!
Sounds like your code is getting itself stuck in some bad state...
Again, per the link above, concentrate on getting one end of the link working at a time - in particular, provide good debug/instrumentation/diagnostics...
#BothEnds
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 5:35 AM
I further debugged the code, and found out that the problem is that after transmitting the data, the slave handles an error callback with error code 4. Can you help me how do I handle this error that the slave will continue to get communication?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 6:17 AM
Start by looking-up what error code 4 means.
But, again, you're left not knowing if that's due to a problem (or problems) in the Master, or in the Slave - or both.
@MichaelR wrote:Can you help me how do I handle this
Again, don't try to do it all at once - get one end fully working, debugged, and understood before moving on to the other:
https://www.avrfreaks.net/s/topic/a5C3l000000UYYaEAO/t146630?comment=P-1401100
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 6:59 AM
Do you use pull up resistors ? that might be the reason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 7:03 AM
I don't use no pull up resistor. Should I use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 7:18 AM - edited ‎2024-04-30 7:19 AM
@MichaelR wrote:I don't use no pull up resistor. Should I use?
That's really basic to the operation of I2C! Not specific to STM32.
Sounds like you need to do some reading-up on the fundamentals:
Note that The internal pull-ups are not suitable for use as I2C bus pull-ups - you need to use external pullups.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 7:42 AM
see examples in CubeMX
you have two boards configured for I2C communication and the pins are pulled up.
those board's pins wouldn't be connected through resistors to 3.3V
Alternatively you can attach 10 K resistors.
see this example from CubeMX
/* Configure SCL Pin as : Alternate function, High Speed, Open drain, Pull up */
LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_0, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOC, LL_GPIO_PIN_0, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_0, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_0, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_0, LL_GPIO_PULL_UP);
/* Configure SDA Pin as : Alternate function, High Speed, Open drain, Pull up */
LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOC, LL_GPIO_PIN_1, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_1, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_1, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_1, LL_GPIO_PULL_UP);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-30 9:10 AM
The internal pullups are not recommended for use as I2C bus pullups - they are too high resistance:
See this post for the effect of too-high and too-low pullups:
https://electronics.stackexchange.com/a/473799
A complex system designed from scratch never works and cannot be patched up to make it work.
