cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Communication Between STM32F446RE and MCP4725

Soniaa12
Associate

Hello everyone,

I'm working on a project with an STM32F446RE, a MCP4725 DAC, and a potentiometer to simulate the throttle of an electric racing motorcycle. My goal is to read the potentiometer value through the ADC of the STM32 and then transmit it via I2C to the MCP4725 to generate a proportional output voltage based on the potentiometer's position.

Hardware Configuration:

  • STM32F446RE:

    • Communicating with the MCP4725 via I2C (pins PB8 as SCL and PB9 as SDA).
    • A potentiometer is connected to PA0 to be read by the ADC, with DMA configured to continuously read the potentiometer value.
  • MCP4725 DAC:

    • Powered at 3.3V (same as the STM32).
    • SDA and SCL pins are connected to the corresponding I2C pins on the STM32 (PB8 and PB9).
    • The OUT pin of the MCP4725 is connected to a multimeter to measure the output voltage.
  • Potentiometer:

    • Connected to 3.3V and GND, with the wiper connected to pin PA0 of the STM32 to read the analog signal.

Problem:

The issue I'm encountering is that, although the ADC value changes correctly when I move the potentiometer (verified through debugging), the HAL_I2C_Master_Transmit function to send the value to the MCP4725 doesn't execute properly. The data transmission gets stuck at this line, and there is no change in the DAC's output voltage (it remains fixed at 1.62V).

What I've tried so far:

  • Added pull-up resistors on the SDA and SCL lines (5.1kΩ).
  • Confirmed that the I2C address is correct (0x60).
  • Ensured that SDA and SCL pins are correctly configured for I2C in STM32CubeMX.
  • Configured DMA for continuous ADC readings from the potentiometer.
  • Checked physical connections to confirm continuity.

Questions:

  1. Is there anything specific I should check regarding the I2C configuration or the MCP4725?
  2. Is it necessary to connect the OUT pin of the MCP4725 to the STM32, or is it sufficient to measure the signal with a multimeter?
  3. Has anyone experienced a similar issue with I2C communication between STM32 and MCP4725?

Any advice or suggestions would be greatly appreciated.

 

1 REPLY 1
Andrew Neil
Evangelist III

@Soniaa12 wrote:

The data transmission gets stuck at this line, .


What line?

Are you getting ant error return codes from the HAL functions?

Have you looked at  the I2C lines with an oscilloscope or logic analyser  to see what (if anything) is happening?

I would suggest that you forget about the ADC, DMA, etc for now and write a simple app which just handles the DAC.

Once you have that tested & working, then mode on to integrating it with the DAC stuff.