0

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.

Update: making ADC handler empty does not resolve the problem, neither SPI nor printing to Serial works.

  • First thought was to poll the ADC and not use interrupts. But if you need it that fast, well. My second thought is to rewrite the interrupt routine to handle both the ADC and the SPI. Guessing, only the last feature you instantiate is working. Are you setting up the ADC after you setup the SdFat? – st2000 Jul 14 at 11:48
  • @st2000: no, I'm setting up ADC first, then running SdFat code. If ADC interrupt is enabled by now, SD doesn't work. I don't have any sort of explicit SPI interrupt handling routine, it's either part of the SdFat lib or the Arduino framework itself, not sure yet. – Violet Giraffe Jul 14 at 12:07
  • My ADC interrupt can't be taking more than 30 cycles, I don't understand why it affects SPI in the first place. – Violet Giraffe Jul 14 at 12:08
  • @st2000: I made ADC handler body empty, but still neither SPI nor printing to Serial works. Is that supposed to happen? Any ideas why this might be? – Violet Giraffe Jul 14 at 12:41
  • 1
    @st2000: I understand, appreciate the suggestions. I'm sure this is doable in principle, I'll keep digging and will post an answer if I find a solution. – Violet Giraffe Jul 14 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.