how to assign analog pin A7 (AD0) in arduino due

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have this code which works fine on pin A0 (AD7) but I want to use pin A7 (AD0), how do I do this.

 

 

int myArray[20000];
void setup()

Serial.begin(9600);
{
 
  REG_ADC_MR = 0x10380180;                     
  ADC -> ADC_CHER = 0x80;                        // enable ADC on pin A0

}

void getData()
{
for(int i = 0; i < 20000; i++) {
    
  
    while((ADC->ADC_ISR & 0x80)==0);             // wait for conversion
   
    myArray[i] = ADC->ADC_CDR[7];                         // read value A0
                         
  }  
}

void loop() {

 
  Serial.println(myArray[100]);

}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excuse me, but your post shows 3 (2+1) functions :

setup, loop (both are automagically invoked by main() arduino provides....)

 

and

getData

I noticed getData is never invoked from setup ...

and never  from loop...

How can it work?

Did Arduino improve its/his/her magical skills?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well it's worse than that. He actually has:

void setup()
Serial.begin(9600);
{
 
  REG_ADC_MR = 0x10380180;                     
  ADC -> ADC_CHER = 0x80;                        // enable ADC on pin A0

}

That Serial.begin() is mis-placed and therefore un-compilable. presumably this was supposed to be:

void setup()
{
 
  Serial.begin(9600);
  REG_ADC_MR = 0x10380180;                     
  ADC -> ADC_CHER = 0x80;                        // enable ADC on pin A0

}

So we can't be looking at "real" code here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I am glad ro know I only need ro buy glasses for opening brackets (if it were for getData, that would be terrible).

And are 32 bits magical constants  REG_ADC_MR necessary? beautiful/useful in the long term?