2024-02-07 07:58 AM
Hello Community :),
I'm using the I2C of the STM32F302:
I2C configuration:
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.
2024-02-08 06:36 AM
If HAL_I2C_IsDeviceReady fails, could be a number of issues:
2024-02-07 08:08 AM - edited 2024-02-07 08: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.
2024-02-07 08:13 AM - edited 2024-02-07 08: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.
2024-02-07 08:20 AM - edited 2024-02-07 08: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!
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"
Any other thoughts will be helpful !
Thanks,
With Regards,
Aymen
2024-02-08 01:12 AM
Hi,
Just a simple question :
>
I2C configuration:
<
How you can set this ? afaik I2C always working with bytes , = 8 bit data .
2024-02-08 06:36 AM
If HAL_I2C_IsDeviceReady fails, could be a number of issues:
2024-02-13 06:43 AM