I ran out of memory and I switch the project I'm working on from an ATmega16 to an ATmega1284p. When I did my ADC broke.
Here are my functions using the ADC:
void initializeADC(void) { ADCSRA |= (1 << ADPS1) | (1 << ADPS0); // Set ADC prescalar to 8 ADMUX |= (1 << REFS0); // Set ADC reference to AVCC ADMUX |= (0 << ADLAR); // Left adjust ADC ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // Select ADC Channel 7 ADCSRA |= (1 << ADEN); // Enable ADC } unsigned int getAdcValue(void) { ADCSRA |= (1 << ADSC); // Start A2D Conversions while(!(ADCSRA & (1<<ADIF))); // Wait for conversion to complete return ADCL | (ADCH << 8); // ADCL must be read first. } void disableADC(void) { ADCSRA |= (0 << ADEN); // Disable ADC }
My ADC was working fine on the ATmega16. However now with the ATmega1284p I receive these compiler errors:
Build started 9.3.2011 at 22:00:51 avr-gcc.exe -mmcu=atmega1284p -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT AVR-ADC-functions.o -MF dep/AVR-ADC-functions.o.d -c ../AVR-ADC-functions.c ../AVR-ADC-functions.c: In function 'initializeADC': ../AVR-ADC-functions.c:6: error: 'ADCSRA' undeclared (first use in this function) ../AVR-ADC-functions.c:6: error: (Each undeclared identifier is reported only once ../AVR-ADC-functions.c:6: error: for each function it appears in.) ../AVR-ADC-functions.c:6: error: 'ADPS1' undeclared (first use in this function) ../AVR-ADC-functions.c:6: error: 'ADPS0' undeclared (first use in this function) ../AVR-ADC-functions.c:8: error: 'ADMUX' undeclared (first use in this function) ../AVR-ADC-functions.c:8: error: 'REFS0' undeclared (first use in this function) ../AVR-ADC-functions.c:9: error: 'ADLAR' undeclared (first use in this function) ../AVR-ADC-functions.c:18: error: 'MUX2' undeclared (first use in this function) ../AVR-ADC-functions.c:18: error: 'MUX1' undeclared (first use in this function) ../AVR-ADC-functions.c:18: error: 'MUX0' undeclared (first use in this function) ../AVR-ADC-functions.c:20: error: 'ADEN' undeclared (first use in this function) ../AVR-ADC-functions.c: In function 'getAdcValue': ../AVR-ADC-functions.c:25: error: 'ADCSRA' undeclared (first use in this function) ../AVR-ADC-functions.c:25: error: 'ADSC' undeclared (first use in this function) ../AVR-ADC-functions.c:27: error: 'ADIF' undeclared (first use in this function) ../AVR-ADC-functions.c:31: error: 'ADCW' undeclared (first use in this function) ../AVR-ADC-functions.c: In function 'disableADC': ../AVR-ADC-functions.c:36: error: 'ADCSRA' undeclared (first use in this function) ../AVR-ADC-functions.c:36: error: 'ADEN' undeclared (first use in this function) make: *** [AVR-ADC-functions.o] Error 1 Build failed with 18 errors and 0 warnings...
I don't understand why these registers are unknown. They are clearly stated on page 258 of the datasheet.
Does anyone know why this broke?
Thanks.
AVR Studio 4.14.589
GCC Compiler
Windows 2000