const uint8_t led = BOARD_LED_PIN;
enum { LED_ON=0, LED_OFF=1 }; // for Blue Pill .. active low led
void setup_vcc_sensor() {
adc_reg_map *regs = ADC1->regs;
regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor
regs->SMPR1 = ADC_SMPR1_SMP17; // sample rate for VREFINT ADC channel
}
void setup(){
setup_vcc_sensor();
Serial1.begin(115200);
pinMode(led,OUTPUT);
Serial1.println("\r\nPrint Internal VCC Voltage");
systick_uptime_millis = 0; // really sleazy way to reset millis;
}
void loop() {
int millivolts;
uint32_t t0 = millis();
digitalWrite(led,LED_ON);
delay(50);
millivolts = 1200 * 4096 / adc_read(ADC1, 17); // ADC sample to millivolts
Serial1.print(t0); Serial1.print(" ");
Serial1.print(millivolts/1000,DEC);Serial1.print(".");Serial1.print(millivolts%1000,DEC);
Serial1.println("V");
digitalWrite(led,LED_OFF);
while((millis()-t0) < 1000); // delay 1000ms
}
Reason:
I’m building a NRF24 remote control with 18650 li-ion’s. I use 2 in parallel tested successfully with min. voltage: ~3 to max 4.2 (absolut minimum is about 2.5V but I won’t reach that limit). Before I was thinking about 2 in serial (so 6->8.4-V) but I didn’t need that voltage which results in burning battery time because of LDO’s (There are 3.3v components only).
So I got the problem with measuring voltage without having a constant 3.3V reference. On good old AVR’s there is an internal voltage reference about 1.1V, very handy for such exercises, but not on a STM32F1xx.
So with this code snipplet I got my (flexible) reference voltage, the rest are some easy calculations!
Do you think we should add this function to the core ?
It should not make sketches any bigger unless it is used ( called )
Maybe it’s time for a “arduino -stm32duino” comparison table/sheet meanwhile a BIG todo….
I guess it would be better just to add it to the examples
(other suppliers are available of course).

The datasheed claims 15 ppm/°C maximum, 0°C to 70°C which should be sufficiently accurate for most applications, including calibrating a cheap multimeter.
I believe a bigger problem is, that there is no “real” VREF input on the maple mini’s, so you need always a REF analog in pin and the need for a SW calculation (compare with another input pin). Correct me, if I’m wrong…
I believe a bigger problem is, that there is no “real” VREF input on the maple mini’s, so you need always a REF analog in pin and the need for a SW calculation (compare with another input pin). Correct me, if I’m wrong…
After graduation, I managed a State University EE lab – mainly watched over undergrads and graduate students to make sure none of the equipment grew legs
A good overview of what calibration IS and ISNOT
One of the locked-up toys was a Standard Cell … a liquid battery in sealed glass with far too many decimal points to be comfortable. If you are an amateur chemist and want to do your own standard voltage battery, the math is pretty simple. Just be certain that you have access to chemical pure reagents and a high accuracy lab balance. Here is the link to the online calculator.
Ray
Input to +5V via 10k and Vka=Vref=2.5V, 6mV drift over temp range, good for 12bit.
tl431ref.JPG
The datasheed claims 15 ppm/°C maximum, 0°C to 70°C which should be sufficiently accurate for most applications, including calibrating a cheap multimeter.
mcp1541 4.096v
aliexpress £0.18 & £0.26
srp
One thing that stands out is that the adc core was quite undeveloped. It does have a couple of functions that are interesting, but it seems as if the only development was done to get the equivalent of analogRead().
I managed to get the interrupts working and will be starting to look into the scan mode soon. ![]()


