I'm working on a pet project that requires ADC, SD card (SPI interface, SdFat library) and a display in the future (also SPI).
I have put together a piece of code that initializes ADC at the highest clock frequency and uses ADC_IER_DRDY interrupt and double buffering.
I have also put together a piece of code based on one of SdFat examples that inits SD card and benchmarks its speed.
On its own, each piece works just fine. But combined together, it breaks if I enable the ADC interrupt. It causes SdFat to stall, not sure where (I don't have a debugger). Simply disabling the interrupt is enough to let SdFat work just fine, but I need both. I have also set ADC IRQ priority to 0 and most other IRQs to 1, but removing
NVIC_SetPriority calls does not solve the problem.
Any advice on how to make both ADC and SPI work, with ADC IRQ priority so that I don't miss samples? I also tried lowering SPI speed from full to 1/16th (SdFat lib has a convenient parameter for this), didn't help.
The code is not long, but a bit too much for inlining into the question, here are Github links.
- main.cpp and ADC stuff - just commenting the highlighted line fixes SPI.
- SD card stuff. Of note: sometimes it prints "chipselect: 10", sometimes not even that.
Update: making ADC handler empty does not resolve the problem, neither SPI nor printing to Serial works.