So, this is peculiar. I am using an ATTINY84 chip as an i2c ADC converter (there are reasons why I'm using this rather than a dedicated chip, but that's not really relevant), and I've noticed that I get odd results unless I power the chip from 5v (it's normally at 3.3v since the other chips I'm using are 3.3v*).
If the chip is powered at 3.3V, analogRead provides a seemingly random value between 0 and 40 or so (which changes on each read over that whole range). At a 5v supply, it suddenly stabilizes to a change of no more than 10 and the range goes to the proper 0-1023. If I supply VCC to the pin in 3.3v mode, I get arbitrary garbage as described, but at 5v VCC and 5v to the ADC pin, I get 1023.
The datasheet says these work as low as 2.7v or 1.8v (depending on version), so why would the ADC only respond properly when it's powered from 5v?
I have the efuses set with:
avrdude -cusbasp -pt84 -v -B 100 -U lfuse:w:0xe2:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m
My setup code is:
// Setup fast ADC for sampling audio ADCSRA &= ~(bit(ADPS0) | bit(ADPS1) | bit(ADPS2)); // clear prescaler bits // uncomment as required (Credit: http://www.gammon.com.au/adc) ADCSRA |= bit(ADPS2); // 16
I'm not doing anything else that should be messing with the ADC modes. Perhaps this clock is too fast for 3.3v? I'm using the internal 8mhz clock source, and the ADC reference is whatever is selected as the default if I don't specify. (I could add analogReference(DEFAULT); -- but that should already BE the default?)
*The host controller for this is an ESP8266, which is a 3.3v chip. It's supposed to be 5v tolerant, but I'd prefer not to risk that. It seems that the Wire library for the Tiny is adding internal pullups on the '84, so is there any way to disable those when running it at 5V to prevent the i2c bus voltage creeping up? My other solution is to get the ADC to work properly even at the lower voltage supply...