Electronic – Timing between words in SPI

picspi

I'm trying to use a dsPIC33F to generate a data signal which must not be interrupted between words. It must be a continuous train of 240 bits. I am clocking the SPI using DMA with 16-bit words, but I am getting gaps in between the words. Is there anything I can do about this or am I stuck with it?

Now here's the odd thing! If I do it using a looping routine continuously writing to the SPI register, there are no gaps! So the DMA is creating these gaps somehow. It would be nice if I could reduce the CPU usage with DMA, as high CPU usage prevents other background tasks from executing.

Best Answer

I haven't used the dsPIC DMA engine yet, but this sounds surprising to me. When you say "continuously writing", does that mean in a loop waiting for the SPIxIF flag (or whatever it's called, not looking it up now)? I expect that's the same flag that is used to signal the DMA engine to transfer the next word.

If you're not waiting for SPIxIF, then you're just jamming data into the SPI buffer and the output bits aren't predictable. Perhaps there is a inherent gap between words. What is the SPI clock rate in terms of instruction cycles per clock?

SPI is inherently synchronous, so a small gap shouldn't cause problems. Unless you're trying to use the SPI peripheral for other than SPI, your requirement doesn't make sense.