How to get real adc dac on bluepill

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
Posts: 3
Joined: Wed Dec 05, 2018 7:45 am

How to get real adc dac on bluepill

Post by triple_m » Wed Dec 05, 2018 9:56 pm

Bluepill should allow us to 12bit DAC, ADC in a material form (beyond simple PWM) according to the specification.
How do I use this functionality properly?

I tried to connect things to PA0 and PA1 and just read and write to them analog with the following code:

Code: Select all

unsigned int sample = 0;
 void setup() 
     // define that i used pa0 as output pin
     pinMode(0, OUTPUT);
  void loop()
    // read analog data converted to digital (adc)  - i get 12 bit resulution here but cand use analogReadResolution/analogWriteResolution
    sample = analogRead(1);  // 1 == pa1
    // print to serial the digital data i got
    // write digital to analog data (dac) - i can get only 8 bit resulution here (analogWrite writes 255 max)
    analogWrite(0 , sample );  // 0 == pa0

And the result was particularly miserable ...
Can you direct me to a good code of analog reading and writing using analog to digital conversions and vice versa?

Posts: 432
Joined: Fri Jun 03, 2016 8:19 am

Re: How to get real adc dac on bluepill

Post by edogaldo » Wed Dec 05, 2018 10:33 pm

According to the specs, the blue pill does not have DAC, only ADC.
DAC is only supported on the bigger versions (the so said high density and xl density versions)

User avatar
Posts: 3001
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta

Re: How to get real adc dac on bluepill

Post by mrburnette » Wed Dec 05, 2018 10:39 pm

The best analog example is IMO:

As stated previously, the Blue Pill does NOT have a DAC internal.

PWM to analog is a subject outside this post. I suggest you start here: ... to+voltage

Good luck,


Post Reply