Could you guys help please review my code and suggest any potential mistakes or improvements?
Good day guys, I'm currently working on a project involving the MCP3424 ADC module and an STM32 microcontroller. My intention is to verify whether the MCP3424 is connected to the master STM32 at the defined address 0x68. While the ADC module successfully connects to an Arduino at the same address, I am facing issues with the STM32 connection.
This is my code ;
With this, I am still unable to establish a connection with the MCP3424 using the STM32.
The error output keeps showing "no device".
Could you guys help please review my code and suggest any potential mistakes or improvements? Also, if there are specific considerations or configurations needed for interfacing the MCP3424 with the STM32, please I would love to know.
Thanks guys 🙏.
@Middleware & OS
@Middleware & OS
Solution:Jump to solution
Alright @Sterling this code example can help guide you to refine your code for more detailed debugging:
```c
while (1) {
HAL_StatusTypeDef result = HAL_I2C_IsDeviceReady(&hi2c1, 0x68 << 1, 10, 1000);...
8 Replies
Hi @Sterling your code looks generally correct, but let's check a few things. Have you ensured that your I2C peripheral (
hi2c1
) is properly configured in your STM32CubeMX
or your initialization code?I think so, but I'm not entirely sure. What specific configurations should I look for?
You need to check the I2C clock speed, the GPIO pins for
SCL
and SDA
, and make sure the I2C peripheral
is enabled. Also, make sure you have pulled up resistors on the SCL
and SDA
lines.
Without these, the I2C communication won't work correctly.Okay, I will check the pull-up resistors. Anything else?
Hi @Sterling , you can also make sure your MCP3424 is properly powered and the ground connections between the STM32 and MCP3424 are secure. Power issues can often cause connectivity problems.
The power should be fine, but I'll double check.
How about the addressing? Is it being done correctly?
@Sterling Yes, you're correctly shifting it by a bit. The
MCP3424
has a 7-bit address of 0x68
, which translates to 0xD0
for write operations and 0xD1
for read operations when shifted. Your code looks fine in this respect.Solution
Alright @Sterling this code example can help guide you to refine your code for more detailed debugging:
This will print a detailed error message to help diagnose specific I2C issues