This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Sample ADC and writting in SD over SPI

Hello,

I'm sampling the ADC using PPI like in the saadc example of the sdk12. For the ADC I use TIMER 1.

And I want to write those ADC values on a SD Card over SPI. For that I'm using the fatfs example (SPI0 is used, I think without DMA).

Sampling the ADC works and when I don't sample I can also write some test values on my SD Card. But as soon as I want to do both in combination it doesn't work anymore.

While debugging I see that the program doesn't leave the write function anymore, I think it's stuck in the default_wait_func function but I don't know why.

I'm using the nrf52 development board.

Does anyone has an idea?

I'm thankful for any advice.

Regards Lea

  • Are you calling the write function inside an interrupt (like the saadc done interrupt/callback)?

    In that case if SAADC and SPI0 is running on the same interrupt level the application will probably be stuck. Looks like the write function does not return until it has written all its data to the SD card. Also looks like SPI driver is set up as non-blocking/interrupt driven. This means that the write function will wait for SPI interrupt(s). If you wait for an interrupt in another interrupt at the same level, the code is stuck.

    The solution to this is to either set a variable in the interrupt and then check the variable in main and call the function if the variable is set or to use the scheduler (check out this tutorial).

  • Hi,

    I was facing the same issue, as I was writing to SD card in SAADC callback interrupt.So, as Ole mentioned, now I am setting one flag and checking the same in main function.[Here] (devzone.nordicsemi.com/.../) I have uploaded the code for writing to SD card.

    But here I am facing some issues like, The code getting restarted when it writes some kb's in SD card. Also Apart from the file into which i am writing data, multiple files are being generated.

    Does anyone has any idea about this?

Related