7 years, 10 months ago.


Hello, my Program define a Interrupt on p10. The program works properly. It reads in a subroutine a adconverter 4 byte withspiport(p5,p6,p7). In the moment where I would like to write to the sdcard library the bytes on the sdcard, will not interrupt the running. What can I do... Bernd

Question relating to:

I dont understand the question? You dont want it to generate an interrupt while writing to SDCard? Then simply detach the interrupt while doing that. (Dunno if InterruptIn has detach function, if not, attach a NULL pointer).

posted by Erik - 25 Jan 2013

Hello, the interupt was not work then the write operation works to the sdcard.. But I must read always the adconverter to do not lost datas.. Sorry for my englsih Bernd

posted by Bernd Boemer 25 Jan 2013

When you dont want to lose any ad values even while you are writing to the sd card then you can not disable the interrupt and you must store the values until the sd write operation has finished. The best solution is probably to use two buffers (each of them with room for 128 samples for example). The ad interrupt will store each sample in buffer A until it is full.The ad will then switch to buffer B and start filling that. While buffer B is being filled you have to write the content of buffer A to the sd card. This should be done in the main program and it must be finished before buffer B is full and the ad interrupt switches back to fill buffer A. The main can then write buffer B to the sd card while buffer A is filled and so on. This approach is known as ping-pong buffering.

posted by Wim Huiskamp 25 Jan 2013

That's exactly what I do. In the interrupt routine, the data bytes are read from the ad-converter and stored in buffer (A), when it is full is switched to buffer B and write operations for buffer A released. The buffer size is accurate 512 Bytes each Buffer. But if the writing operation begins on the sdcard, the interrupt is interrupted, so read no data. I have check it with my oscilloscope based on the CLK line of the two SPI ports ... Bernd

posted by Bernd Boemer 25 Jan 2013

You will have to use different spi ports for the ad converter and the sd card. Also make sure that sd card software is not disabling interrupts somehow.

posted by Wim Huiskamp 25 Jan 2013

Hello Wim, yes, I have to Spi ports in used. It seems that the sdcard lib this do, but i have not found the options where do I turn it off. Thanks for you answer.. Bernd

posted by Bernd Boemer 26 Jan 2013

Hello, I found my mistake in the program. The error was: I must read the adc in the ISR, not in the main with turn on a flag.


while(1) if adready readadc(); if flag flag=0; writetosdcard();



adready = 1; <


d0=spi_write; d1= spi_write; flag = 1; <

posted by Bernd Boemer 28 Jan 2013
Be the first to answer this question.