From 0f663da98656933f01886da8a4aa905e66d96c20 Mon Sep 17 00:00:00 2001 From: Mattias Schlenker Date: Mon, 21 Aug 2017 14:28:00 +0200 Subject: [PATCH] Add proper handling of ADMUXA and ADMUXB for Attiny 841 and Attiny 441 Attiny841/44 with 12+5 ADCs use ADMUXA and ADMUXB instead of ADMUX to select analog reference and channel. Just look at hardware/tools/avr/avr/include/avr/iotn841.h and hardware/tools/avr/avr/include/avr/iotn441.h. With this change ADMUXA and ADMUXB is properly initialized to make ADC usable, tested with Attiny841, thanks @awatterott for the hint. --- hardware/arduino/avr/cores/arduino/wiring_analog.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware/arduino/avr/cores/arduino/wiring_analog.c b/hardware/arduino/avr/cores/arduino/wiring_analog.c index 967c2b9761f..8c80d1970bd 100644 --- a/hardware/arduino/avr/cores/arduino/wiring_analog.c +++ b/hardware/arduino/avr/cores/arduino/wiring_analog.c @@ -69,6 +69,9 @@ int analogRead(uint8_t pin) #else ADMUX = (analog_reference << 6) | (pin & 0x07); #endif +#elif defined(ADMUXA) + ADMUXA = (pin & 0x07); + ADMUXB = (analog_reference << 5); #endif // without a delay, we seem to read from the wrong channel