1
\$\begingroup\$

I'm reading BMP images with hundreds of kB's raw from an SD card and parse/write the image data to a TFT LCD with an AVR MCU with 2kB RAM.

Reading a single block of 512 bytes with CMD17, passing it to the display, reading the next block and so on works fine but I'd like to see if it goes faster when reading multiple blocks with a single CMD18 instead:

  • start reading multiple blocks (CMD18)
  • read one block of 512 bytes
  • (deselect SD card)
  • parse user data and send it to display
  • (select SD card)
  • read next block...
  • when done, stop reading (CMD12)

I am deselecting the SD card in the SPI bus when sending image data to the display so it won't receive the commands and data meant for the display. However, it doesn't seem to be a good idea to deselect the SD card during execution of a command.

The spec says about CMD7:

Command toggles a card between the stand-by and transfer states or between the programming and disconnect states.

But instead of sending two CMD7 per block (including waiting for the card to be no longer busy), reading a single block with one CMD17 should be more efficient? Any other options?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ What do you consider as other options? Switching the MCU to something more suitable for the task, or having two SPI bused, or hardware changes to mux the single SPI bus to two devices so that you can pause SPI transactions while transferring on other device? If you can do it by reading single blocks, it might be simplest. \$\endgroup\$
    – Justme
    Commented Mar 30 at 11:30
  • \$\begingroup\$ I'm perfectly fine with reading single blocks, just wanted to make sure I don't overlook something. I'm more curious than experienced :-) \$\endgroup\$ Commented Mar 30 at 11:33
  • \$\begingroup\$ Instead of deselecting the CS pin to stop the SPI communication, you could implement a queue where one task for getting the data from the SD, another for popping the data from the queue to the display. \$\endgroup\$
    – hcheung
    Commented Apr 5 at 1:27
  • 1
    \$\begingroup\$ You didnt write which type of AVR you are using. Some AVR MCUs (At least Atmega328) have USART capable to run in SPI mode. Using this USART you can write to display and read from SD "simultaneously". Moreover USART is equiped with buffer which can also improve transfer speed. You can also use Atmega328PB with two SPI perihperals... \$\endgroup\$ Commented Apr 21 at 19:39
  • \$\begingroup\$ @MichalDudka Actually I am currently using an ATmega328 and using USART in SPI mode is a nice idea. I'll also have a look for the 328PB. Thanks! \$\endgroup\$ Commented Apr 23 at 9:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.