STM32F302 - I2C Error Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-07 7:58 AM
Hello Community :),
I'm using the I2C of the STM32F302:
I2C configuration:
- 7 bit data
- standard mode "100 KHz"
- mode polling
When initiating communication between the STM32 and the sensor, the "HAL_I2C_Master_Transmit" function returns "HAL_ERROR."
Upon investigation, I discovered that this error is associated with an error code. Does anyone know the significance of the error code?
I catch the error in line 679 of the HAL function:
Thanks,
With Kind Regards,
Aymen
Solved! Go to Solution.
- Labels:
-
I2C
-
STM32F3 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-08 6:36 AM
If HAL_I2C_IsDeviceReady fails, could be a number of issues:
- Wrong slave address
- Slave isn't powered or connected correctly
- Master/Slave are out of sync (reset both, power cycle, or toggle SCL line 9 times).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-07 8:08 AM - edited ‎2024-02-07 8:19 AM
Hello @Mohamed Aymen ,
Make sure that you are using the correct address.
Use a logic analyzer to check SDA and SCL behavior and identify the issue.
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-07 8:13 AM - edited ‎2024-02-07 8:15 AM
AF is an acknowledgement failure--the slave failed to acknowledge the address.
This could be because you're using the wrong address, or the slave isn't hooked up correctly. Note that the slave address should be left-shifted. If the 7-bit slave address is 42, you should be sending 42 << 1 to the HAL_I2C functions.
Use HAL_I2C_IsDeviceReady and ensure the return value is HAL_OK before doing anything else with I2C.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-07 8:20 AM - edited ‎2024-02-07 8:22 AM
I wanted to second what @TDK said. I've never had an I2C application work without left shifting the address by a bit (and I almost always forget to do this initially and run into this same issue). Best bet with any comms issue is to hook it up to a scope or logic analyzer and make sure your lines look like you expect them to. It's helped speed up diagnosing these kinds of issues, CS issues in SPI, etc. Trying to diagnose issues without seeing what the signal is actually doing makes things much, much harder. Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-08 12:47 AM
Hello All, and thanks for the prompt reply,
I omitted to mention that the initial communication proceeded smoothly, but after some time, the error occurred. Following a suggestion, I conducted a test using "HAL_I2C_IsDeviceReady"
- Initially, there were no errors returned, but after a while, the error occurred.
Any other thoughts will be helpful !
Thanks,
With Regards,
Aymen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-08 1:12 AM
Hi,
Just a simple question :
>
I2C configuration:
- 7 bit data
<
How you can set this ? afaik I2C always working with bytes , = 8 bit data .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-08 6:36 AM
If HAL_I2C_IsDeviceReady fails, could be a number of issues:
- Wrong slave address
- Slave isn't powered or connected correctly
- Master/Slave are out of sync (reset both, power cycle, or toggle SCL line 9 times).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-13 6:43 AM
