Some thoughts about caveats with TFT_eSPI combined with SD card sharing same SPI bus #1885
Frank-Bemelman
started this conversation in
Alerts
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi folks!
I am currently toying with an ESP32 with a TFT and SD card reader. Since I need a lot of pins as it is, I connected them both to the same SPI bus (MOSI/MISO) and only use seperate pins for the CS of the devices.
Usually, you won't use the two devices at the exact same moment. But I also run the asyncwebserver where I can get a directory of the SD card, While the webserver retrieves the list of files on the SD card, and the main loop updating the TFT screen, often corrupts the reading of the ongoing SD card reads.
The fix for the moment, is to wait for the SD is not in use, before starting a TFT write, and vice verca. Luckily all my TFT stuff is concentrated in one place and I inserted a while/wait and continue when it is 'safe'. Something like this:
I do that before each call that actually sends or reads data to/from the TFT.
Similar, where I use the SD functions:
In my case, it fixed all of my fun project weird behaviour. I did try to skim through the relevant libraries how CS is treated because I thought that might be an ideal place to insert those while/waits. But I didn't try anything there, because that was all a bit too deep for me. These while/waits are in practice not blocking code situations and should not hang for very long. Waiting until the SD or TFT is finished with whatever it was busy with, should not take forever(;;)....
Another issue I had was with the SD card reader module. Many have already noticed before, that the MISO is not tristated. My module actually had a tristate driver, but the design does not use it as such. A small modifcation made the MISO tristate as it should be. This is only important if you share the MISO with the TFT. Or, if you don't plan to read anything back from the display, not using sprites etc,
it does not matter. Just leave the MISO from the TFT disconnected.
Bottom line being, if you don't really need the pins for other purposes, don't share the SPI bus, but connect your TFT and SD card to VSPI and HSPI.
Cheers,
Frank
Beta Was this translation helpful? Give feedback.
All reactions