I have already read some of the great tutorials on ADC-interrupt. So I was very excited to implement it. But I can't compile my code. It shows several errors. So I have to revert back to my old working code. I don't place here my entire code but two important functions. I guess I don't properly understand interrupt yet.
Working code:
void adc_init(void) { ADMUX |=(1<<REFS0); ADCSRA |=(0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADFR)|(1<<ADEN); } uint16_t adc_read(void) { ADCSRA |=(1<<ADSC); while(ADCSRA & (1<<ADSC)) { return(ADC); } }
Not working Interrupt implemented code:
uint16_t adc_read(void) { ADCSRA |=(1<<ADIE); sei(); ADCSRA |=(1<<ADSC); ISR(ADC_vect) { return(ADC); } }
uC=ATmega8L, uC freq=1MHz, Prescalar=8, AVR Studio 4.19
Plz tell me what I have done wrong when implementing interrupt?