Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: SPI directly linking two devices for "DMA"

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Location
    France
    Posts
    4

    Lightbulb SPI directly linking two devices for "DMA"

    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 by Midimetric; 01-15-2014 at 10:08 AM.

  2. #2
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    894
    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?

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Location
    France
    Posts
    4
    Quote Originally Posted by christoph View Post
    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

    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.

  4. #4
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    894
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •