Hello,
I have trouble streaming data from the selected channels of my Arduino DUE to serial port of Arduino IDE(baud rate 115200). To put it simply I just want 2 channels to stream values at a total rate of 100kHz, given that baud rate is set to 115200 in serial monitor. So each channel is sampling at 50kHz. But im having a hard time figuring out setting this up.The 3 resources I have found are:
ATMEL SAM3X8E datasheet - ADC is page 1317:
http://ww1.microchip.com/downloads/en/devicedoc/atmel-11057-32-bit-cortex-m3-microcontroller-sam3x-sam3a_datasheet.pdf
Example1-
https://forum.arduino.cc/index.php?topic=520133.0
Example2-
Ive been able to stream data using the code from hackaday just fine(after altering somethings).
#define ADC_MR * (volatile unsigned int *) (0x400C0004) /*adc mode word*/
#define ADC_CR * (volatile unsigned int *) (0x400C0000) /*write a 2 to start convertion*/
#define ADC_ISR * (volatile unsigned int *) (0x400C0030) /*status reg -- bit 24 is data ready*/
#define ADC_ISR_DRDY 0x01000000
#define ADC_START 2
#define ADC_LCDR * (volatile unsigned int *) (0x400C0020) /*last converted low 12 bits*/
#define ADC_DATA 0x00000FFF
// analog stuff
uint32_t analogInPin5 = A5;
int analog_data[1024];
uint32_t ulValue = 0;
uint32_t ulChannel;
static int _readResolution = 10;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(3000);
ADC_MR |= 0x00000100 ; // ADC full speed
Serial.println("a5=");
Serial.println(analogInPin5);
delay(2000);
// init the ADC
if (analogInPin5 < A0) analogInPin5 += A0;
delay(2000);
ulChannel = g_APinDescription[analogInPin5].ulADCChannelNumber ;
// Serial.println("ulChannel=");
// Serial.println(ulChannel);
adc_enable_channel( ADC, (adc_channel_num_t)ulChannel );
}
void loop() {
// put your main code here, to run repeatedly:
ADC_CR = ADC_START ;
for (int i=0; i<1024; i++){
// Wait for end of conversion
while (!(ADC_ISR & ADC_ISR_DRDY));
// Read the value
analog_data[i] = ADC_LCDR & ADC_DATA ;
// start next
ADC_CR = ADC_START ;
Serial.println(analog_data[i]);
}
}
But when trying to enable A1(aka channel 6) and A0(aka channel 7) to allow 2 channels to be sampled in free-run mode(aka ,no trigger is required to begin sampling), and adjusting the samplerate of the ADC, I have problems. Does anyone have any other sources I could go off of? Ive found the "magic words" that arduino uses to communicate to the SAM3X8E in my arduino folder....but some help would rock.