Hi,
I’m trying to understand how to implement this feature, which is available in Arduino 168 and 328. It is possible to measure it own input voltage through it internal Vref, and i notice that the STM32 Spark Core have available a similar internal reference. ADC_CR2_TSVREFE ((uint32_t)0x00800000)
. Any help to migrate this code to Spark?
Arduino code version:
https://code.google.com/p/tinkerit/wiki/SecretVoltmeter
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}```