
This following statement is a formula used to calculate the voltage from the ADC input value (0 to 4096) with the reference voltage of 3.3V. Following statement reads the analog value from pin PA0 and converts it into digital value ranging from 0 to4096 as ADC is 12-bit resolution and store in the variable adc. First in buffer put the control byte value (0b01000000). Next set the LCD display in the 16x2 mode and display a welcome message. Wire.begin() //Begins the I2C communication The MCP4725 DAC default I2C address is 0圆0 #define MCP4725 0圆0įirst begin the I2C communication at the pins PB7 (SDA) and PB6 (SCL) of STM32F103C8. Then define the I2C address of the MCP4725 DAC IC. Next define and initialize the LCD pins according to the LCD pins connected with the STM32F103C8 const int rs = PB11, en = PB10, d4 = PB0, d5 = PB1, d6 = PC13, d7 = PC14 LiquidCrystal lcd(rs, en, d4, d5, d6, d7) Learn more about I2C in STM32 Microcontroller here. Complete program for this STM32 DAC tutorial is given at the end.įirst include library for I2C and LCD using wire.h, SoftWire.h and liquidcrystal.h library. Visit this link to learn more about Programming your STM32 in Arduino IDE.
#How analog to digital converter works Pc#
Simply connect it to PC via USB port of STM32 and start programming with ARDUINO IDE.
#How analog to digital converter works code#
Programming STM32F103C8 for Digital to Analog ConversionĪ FTDI programmer is not needed now to upload code to STM32F103C8. Finally display the both ADC & DAC values with voltages in the 16x2 LCD display. Then convert those digital values to analog using the DAC MCP4725 IC and then use another ADC pin PA1 of STM32 to check the analog output of MCP4725 from the pin OUT. After that send those digital values to MCP4725 via I2C bus. And then use ADC to convert analog value into digital form. In this tutorial we will connect a MCP4725 DAC IC with STM32 and use a 10k potentiometer to provide analog input value to STM32 ADC pin PA0. Pin from Centre of Potentiometer for contrastĬonnection between MCP4725 DAC IC and STM32F103C8Ī potentiometer is also connected, with center pin connected to PA1 analog input (ADC) of STM32F10C8, Left Pin connected to GND and right most pin connected to 3.3V of STM32F103C8. Maximum reference voltage is 5V.įormula to calculate Output Voltage O/P Voltage = (Reference Voltage / Resolution) x Digital Valueįor Example if we use 5V as reference voltage and let’s assume that digital value is 2048. This means we use (0 to 4096) as input to provide the voltage output with respect to reference voltage.

It also comes with on board nonvolatile memory EEPROM. MCP4725 IC is a 12-Bit Digital to Analog Converter Module which is used to generate output analog voltages from (0 to 5V) and it is controlled by using I2C communication. MCP4725 DAC Module (Digital to Analog Converter)


Today we will use the same MCP4725 DAC IC to design a Digital to Analog converter using the STM32F103C8 Microcontroller. We already interfaced MCP4725 DAC Module with Arduino. DAC can be used in many applications such as Motor control, Control Brightness of the LED Lights, Audio Amplifier, Video Encoders, Data Acquisition Systems etc.
