SPI communication: "interruption" possible?

Dear all,

I'm having some trouble getting to the right buildup of my code.

Project: arduino as external WAV player (10kHz, mono, 8bit) and display driver (nokia 5110), controlled through SPI
Reason: offload primary processor (arduino as well :P)

I have some elements working:

  • Arduino running as SPI slave on hardware SPI pins: done
  • Reading SD card using software SPI, driving external speaker (PWM): done
  • Getting images to Nokia 5110 display using software SPI: done

Since the sound is 10kHz, I have 100 us to do whatever I do to get my music playing, because after 100 us I'm up to do it again to get the 10 kHz frequency. Now reading a byte from a file and driving the speaker takes a bit under 50 us, and I'm driving that down. So this leaves another 50 us to send data to my display.

I'd like to do this as easy as possible, if possible without chopping up the nokia 5110 library. So I thought up this plan:

Hook up an interrupt to timer 1 @ 10kHz, have this interrupt read a byte from the sd card and drive the speaker, use 4 software SPI pins to do this.

Then in my main loop I use four different software SPI pins to talk to my display. This might mean that somewhere while instructing my display the processor jumps to the interrupt, plays a byte, and returns to the main loop where my display is being instructed.

The question: will this work?

Cheers,

Jack

The question: will this work?

The only way to know for certain is to try it.

I got into it and will phrase a more specific question in - hopefully - the right part of the forum.

(it is not working yet)

Except there's only 1 set of SPI hardware. What you are proposing will require bit-banging the other set of pins. Or using the USART in SPI mode, see section 21 of the datasheet. "21. USART in SPI Mode"

I'm banging the bits, the SD card library has a built in software spi function which does exactly this. I'll need the hardware spi because in the end the arduino will run as an spi slave.