SPI directly linking two devices for "DMA"

Status
Not open for further replies.

Midimetric

New member
Hello,

I have toyed with the Teensy 3.1, a color TFT and an SD card reader.
When loading a bitmap from the card and displaying it on the TFT, it seems I lost a lot of time just to manage the transfer of bytes...

Here is a pseudo code of what I actually do:

read 480 bytes from a sector (remaining 32 bytes of the sector are ignored because the bitmap is already saved in a TFT compatible format, i.E. one line per sector):

- allocate a buffer uint16_t buffer[240]
- spi select SD
- spi out -> read command, sector #
- spi in <- 0x00, 0x00
- loop 240 times (using 4 words fifo as in spi4teensy library)
... - spi out -> 0x0000
... - spi in <- 16 bits data goes to *buffer++
- spi unselect SD

write a line on the tft ( 240 x 16 bits pixels )

- select CMD line
- select TFT spi
- spi out -> set columns 0 to 239, set lines y to y, write command
- spi in <- 0x00,0x00... (ignored)
- unselect TFT spi

- unselect CMD line
- select TFT spi
- loop 240 times (using 4 words fifo as in spi4teensy library)
... - spi out -> pixel data from *buffer++
... - spi in <- 0x0000 ignored
- spi unselect TFT


This is working fine, even at full spi speed (24MHz ?) but i feel like there a lot of "zeros" transfered and ignored both ways...
My question is, does it seems feasible to temporarily connect the SDO from the SD card to the SDI of the TFT ?
This would be done with some CD40xxx switch.

The pseudo-code would then become :

- select CMD line
- select TFT spi
- spi out -> set columns 0 to 239, set line y to y, write command
- spi in <- 0x00,0x00... (ignored)
- unselect TFT spi
- unselect CMD line

- spi select SD
- spi out -> read command, sector #
- spi in <- 0x00, 0x00


- spi select TFT
- activate the switch connecting SD SDO to TFT SDI and disconnect Teensy MOSI from TFT SDI

- loop 240 times
... - spi out -> 0x0000
... => SD SDO pushes value directly to TFT SDI
... - spi in <- 16 bits data ignored
- spi unselect SD
- spi unselect TFT


In effect, I just skip writting to a buffer then pushing the buffer to the TFT !
FPS is doubled !

Does it make sense ?
 
Last edited:
If you can properly manage the different hardware connections, it should work. But why do you need "fps" for a bitmap? Is it a bitmap video or some kind of animation?
 
But why do you need "fps" for a bitmap? Is it a bitmap video or some kind of animation?

Not sure about the final application. For now it is just a personal challenge of achieving the best SD to TFT transfer.
I know i am crazy about speed :eek:

The best I can do to load a 320x240 65K colors bitmap is around 250ms. That is too slow to consider any video or animation yet.
So I wonder if there could be some hardware workaround.
 
Let's see... 320*240+16 bits for f_SCK = 12 MHz is 320*240*16/12e6 = 0.1024 seconds. I picked 12 MHz because this is the fastest speed I could reliably work with on a breadboard. Feel free to increase that (I don't know if you're breadboarding or if you're using a PCB), but even with 24 MHz you won't get any faster than 0.0512 s (~ 51 ms) with a direct link between SD MISO -> TFT MOSI. If that's fast enough for you, give it a try.

Otherwise I wouldn't bother and just read the data into a buffer using SPI and then transfer it to the TFT. Using DMA it won't take much longer than 102 ms with f_SCK = 24MHz or 204 ms with f_SCK = 12 MHz.
 
Status
Not open for further replies.
Back
Top