Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: ADC Polling
PostPosted: Mon Oct 10, 2011 6:20 pm 
Offline

Joined: Wed Sep 21, 2011 3:41 pm
Posts: 5
Hello All,

I am attempting to write a simple adc polling function (the atmel examples use interrupts which I don't want to use), and it's not working. Here's essentially what I am doing

<code>
uint32 adc_get_data(uint32 channel)
{
uint32 data;
ADC_EnableChannel(AT91C_BASE_ADC, channel);
ADC_StartConversion(AT91C_BASE_ADC);
while((adc->ADC_SR & (1 << channel)) != (1 << channel)); // wait for conv to finish

data = ADC_GetConvertedData(AT91C_BASE_ADC, channel);
ADC_DisableChannel(AT91C_BASE_ADC, channel);
return data;
}

int main()
{
/** all inits and configs **/
while(TRUE)
{
data = adc_get_data(ADC_CHANNEL_5);
printf("%d\n\r", data); // serial dbgu port configured
}
}

</code>

However, on the serial port, I'm reading all zeros. what am I doing wrong?

I appreciate your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: chasmopolitan, Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron