SPI clock pulse byte delay

Hi guys

I am currently in the process of trying to optimize the write times to an SD card using the SPI interface. While I have managed to increase the speed a fair bit using the clock divider and the libraries found on the Adafruit website I am having trouble pushing the rate much higher then 200KB/s per 512 bytes (excluding the delay / overhead between each 512 bytes being written).

I believe the write speed can be at least doubled again as there is quite a large delay between each set of 8 clock pulses generated for each byte. The image below shows more clearly what I mean. Regardless of what I set the clock divider to the delay stays the same: about 2 us or about 70% of the total time taken to write a single byte. In theory this delay could be shrunk down to 2 or 3 clock pulses in length without affecting data integrity. The problem is I do not know where this delay is coming from. I have looked through both the SPI header and cpp source files and cannot find it.

If any of you can point me in the right direction it would be greatly appreciated.

-Ben

BenW:
If any of you can point me in the right direction it would be greatly appreciated.

-Ben

Ben,

I wrote a new SPI library that might help you. It is a departure from the Single Byte Spi.transfer(); idea.

In my library you pass SPI a buffer which the ISR running the hardware directly access. It runs transfers at hardware speeds. If you are adjusting the dividers you would see a direct correlation.

If you are interested, send me a email (direct msg) and I'll send you my library. All I ask is for you to send me the results of your tests.

I use this library for MCP23s17(io Expanders), 23lc512 (SPI RAM), W25Q64FV(64Mb Flash).

I haven't taken the time to update SD to used it.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.