Hi, I'm struggling with a curious effect.
With modified examples of this forum I'm testing ADC of Due with register programming for a planned project.
- With one SW trigger I'd like to see ADC results from one or more enabled channels depending on the variable chan (in setup()).
- The converted data shall be stored to arrays via interrupt.
- Every interrupt shall store ADC_ISR, time in us and ADC_LCDR
- interrupts shall be fired by EOC of enabled channel(s) and by DRDY
- converted data shall be printed once within loop()
#define PRINT(s, v) \
{ \
Serial.print(F(s)); \
Serial.print(v); \
}
#define PRINTHEX(s, v) \
{ \
Serial.print(F(s)); \
Serial.print(v, HEX); \
}
#define TICPIN (7)
volatile uint8_t dcnt = 0;
volatile uint16_t dat[16];
volatile uint32_t disr[16], etim[16];
uint32_t stim;
volatile boolean tic=false;
void ADC_Handler() {
if (dcnt < 16) {
disr[dcnt] = ADC->ADC_ISR;
etim[dcnt] = micros();
dat[dcnt++] = (uint16_t)(ADC->ADC_LCDR);
}
tic != tic;
if (tic) digitalWrite(TICPIN, HIGH);
else digitalWrite(TICPIN, LOW);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial.println();
PRINT("Start ", __FILE__);
Serial.println();
pinMode(TICPIN, OUTPUT);
uint32_t chan = 0x81;
NVIC_EnableIRQ(ADC_IRQn);
ADC->ADC_CHDR = 0xFFFF ; // disable all channels
ADC->ADC_CHER = chan ; // enable channels according to cher
ADC->ADC_CGR = 0x15555555 ; // All gains set to x1
ADC->ADC_COR = 0x00000000 ; // All offsets off
ADC->ADC_MR = (ADC->ADC_MR & 0xFFFFFFF0); // no HW trigger
ADC->ADC_IDR = 0xFFFFFFFF;
ADC->ADC_IER = chan | (1<<24); // EOC of enabled channels and DRDY
ADC->ADC_EMR = ADC->ADC_EMR | (1 << 24); // set TAG: Channel no. in converted data
ADC->ADC_CR = 2; // start
PRINTHEX(" CHSR=0x", ADC->ADC_CHSR);
PRINTHEX(" MR=0x", ADC->ADC_MR);
PRINTHEX(" IMR=0x", ADC->ADC_IMR);
PRINT(" LCDR=", ADC->ADC_LCDR);
Serial.println();
Serial.println(F(" Zeit\tWert\tISR "));
Serial.println(stim);
delay(5);
}
void loop() {
// put your main code here, to run repeatedly:
if (dcnt) {
for (int i = 0; i < dcnt; i++) {
Serial.print(etim[i]); Serial.print("\t");
Serial.print(dat[i]); Serial.print("\t");
Serial.println(disr[i]);
}
dcnt=0;
}
}
Within setup() 4 register contents shall be printed. But Serial Monitor only shows
Start H:\Arduino\examples\sketch_jul16a\sketch_jul16a.ino
CHSR=0x81 MR=0x103
It seems that register ADC_MR is printed only partially and registers ADC_IMR and ADC_LCDR not at all. All following prints are blocked. No converted data are printed, but on an oscilloscope I can see a tic pulse from an interrupt.
Any tips are welcome to solve this mystery.