diff --git a/cores/arduino/analog.cpp b/cores/arduino/analog.cpp index cd61c281f..dd1de77f1 100644 --- a/cores/arduino/analog.cpp +++ b/cores/arduino/analog.cpp @@ -570,13 +570,17 @@ float analogReference() { case ADC_VREF_CONTROL_VREFH0_AVSS0: // the user must know the voltage he applies from outside return NAN; +#ifdef AR_INTERNAL_VOLTAGE + case ADC_VREF_CONTROL_IVREF_AVSS0: + return AR_INTERNAL_VOLTAGE; +#endif default: #if defined(AVCC_MEASURE_PIN) if (aref == 0) { analogReference(AR_INTERNAL); delayMicroseconds(5); for (int i = 0; i < 10; i++) { - aref += analogRead(AVCC_MEASURE_PIN) * 1.43f * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution); + aref += analogRead(AVCC_MEASURE_PIN) * AR_INTERNAL_VOLTAGE * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution); } aref = aref / 10; analogReference(AR_DEFAULT); diff --git a/variants/MINIMA/pins_arduino.h b/variants/MINIMA/pins_arduino.h index c8c08f807..be936298a 100644 --- a/variants/MINIMA/pins_arduino.h +++ b/variants/MINIMA/pins_arduino.h @@ -156,6 +156,8 @@ static const uint8_t SS = PIN_SPI_CS; #define AVCC_MEASURE_PIN 20 #define AVCC_MULTIPLY_FACTOR 8.33 +#define AR_INTERNAL_VOLTAGE 1.43f + #define USB_VID (0x2341) #define USB_PID (0x0069) #define USB_NAME "UNO R4 Minima" diff --git a/variants/PORTENTA_C33/pins_arduino.h b/variants/PORTENTA_C33/pins_arduino.h index e7eecf25f..898a1940d 100644 --- a/variants/PORTENTA_C33/pins_arduino.h +++ b/variants/PORTENTA_C33/pins_arduino.h @@ -207,3 +207,5 @@ static const uint8_t SS = PIN_SPI_CS; #define SerialLoRa Serial3 #define RTC_CLOCK_SOURCE RTC_CLOCK_SOURCE_SUBCLK + +#define AR_INTERNAL_VOLTAGE 1.18f \ No newline at end of file diff --git a/variants/UNOWIFIR4/pins_arduino.h b/variants/UNOWIFIR4/pins_arduino.h index 755b642bf..4f0ebb897 100644 --- a/variants/UNOWIFIR4/pins_arduino.h +++ b/variants/UNOWIFIR4/pins_arduino.h @@ -158,6 +158,8 @@ static const uint8_t SS = PIN_SPI_CS; #define AVCC_MEASURE_PIN 20 #define AVCC_MULTIPLY_FACTOR 8.33 +#define AR_INTERNAL_VOLTAGE 1.43f + #define USB_VID (0x2341) #define USB_PID (0x006D) #define USB_NAME "UNO R4 WiFi"