I can't get the interrupt to work. I wrote a sketch based on the @susan-parker sketch (above) to read in single mode. I put these 2 lines in Setup():
attachInterrupt(2, ADC_ISR, FALLING); // This IRQ will be assigned to Slot 05...
*ICU_IELSR05 = 0x029; // HiJack Slot 05 IELSR05 for ADC140_ADI
My ISR is void ADC_ISR(), and my ADC setup is the same as Susan's, although I don't really want to use averaging mode. I did not set up or use the DAC, and I dis not manipulate the digital pins. The ISR is never called, but I can read ADC140_ADDR00 and get correct values, like in Susan's code.
I put this variable in my sketch:
volatile bool bInterrupted = false;
and set it to true in the ISR. The variable never becomes true.
I decided to run Susan's ino. It compiled and uploaded OK, but the output sent to Serial was bizarre:
0 - 1E
Firmware name: "C:\Users\jshor\AppData\Local\arduino\sketches\04EBAC79990481F95B99CFEFB25CA7A4/R4_LED_Matrix.ino", compiled on: Dec 30 2024
Fault on interrupt or bare metal(no OS) environment
===== Thread stack information =====
addr: 20007e10 data: 00008c8a
addr: 20007e14 data: 200003e4
... more address dumps, 60 in all
addr: 20007ef8 data: 00007895
addr: 20007efc data: 00002599
====================================
=================== Registers information ====================
R0 : ffffffff R1 : 000000c2 R2 : 40006000 R3 : 0006e900
R12: 00000001 LR : ffffffe9 PC : 00004fe8 PSR: 21000212
==============================================================
Bus fault is caused by precise data access violation
The bus fault occurred address is ffffffff
Show more call stack info by run: addr2line -e "C:\Users\jshor\AppData\Local\arduino\sketches\04EBAC79990481F95B99CFEFB25CA7A4/R4_LED_Matrix.ino".elf -a -f 00004fe8 00008c8a 000097ce 00008c8a 0000ff4c 000097ce 00009806 00004276 0000a194 0000a1d6 00004302 0000789e 00007894
R4_LED_Matrix.ino is a sketch I wrote to learn the LED matrix; it's a complete mystery to me why it is referred to. The path given is not my sketchbook, but there actually was a copy of R4_LED_Matrix.ino in that folder with the 32-digit hexadecimal name.
That went away when I commented out the call to print_icu_event_links(). I now got correct readings, but still no interrupt. I added the bInterrupted variable and used it like before, and it never went to true.
There is an undocumented function named analogAttachIrq() in the analog.h core file. I called it like this:
analogAttachIrq((ADCIrqCbk_f)ADC_ISR, ADC_IRQ_SCAN_END, 12);
and got this when I clicked the Verify button:
C:\Users\jshor\AppData\Local\arduino\sketches\02054CCE147800E620F3EE18C110BA20\sketch\R4_Tests.ino.cpp.o: In function `setup':
D:\Software\Arduino\_SketchBook\R4_Tests/R4_Tests.ino:18: undefined reference to `analogAttachIrq(void (*)(unsigned char), ADCIrqType_t, unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
I added an unsigned char parameter to my ISR and got the same result. There is another reference to an unrelated sketch, and I have no idea what an "undefined reference" is.
Does anyone know what any of this means?
I really would like to try the continuous mode of the ADC, but I can't do it without the interrupt. Does anyone know how to set the ISR and make it work?
I apologize for the length of this, but I wanted to explain fully so someone might be able to figure it out.