LCD Graphic display ST7565R – SD Card

This time I’m going to focus on how to hook up SD memory card to a microcontroller. While working with microcontrollers there are a lot of situations where additional memory offered by those tiny cards is needed. Especially while working with LCD graphic display, where a lot of memory is required for storing huge bitmaps. I wouldn’t like to describe here how to work with SD Card in details, because I believe there’s no sense in duplicating something that can be easily found on the Internet. All of the necessary information can be found here and here. What I would like to do is to share problems that I encountered and my solutions to them. I think that the more tutorials on the Internet the better, because beginners may find it easier to introduce themselves into the topic. Personally, I value such tutorials a lot, where you can analyse some case and learn from it. Anyway, to hook up an SD card I used HD74LS07 buffer, which I happened to own. The use of buffer was necessary, because an SD card works at 3.3V voltage and I power my microcontroller with 5V. The schematic for the test circuit is shown below:


Rys.1 Schematic

When I finished building my circuit, I began to write a program to handle SD cards. I used popular library called Petit FAT . It is a lite version of FatFS library, designed especially for small 8 bit microcontrollers with small amount of RAM. I also used U8glib library to work with LCD graphic display. The assumptions for the program were simple. Hook up an SD card, check and display any possible errors that could occur, open the text file located on the card, read it, display it on the LCD and add the possibility to navigate through the text file with buttons.
I quickly encountered a problem, because Petit FAT library is made only to work with FAT file system and it doesn’t contain any functions to work with microcontrollers or other physical devices. What the library needs to be working properly is those functions which must be added by the user themselves.

Fortunately, the Petit FAT library author had provided a few examples of library implementation on different devices, including microcontrollers from AVR family. The examples can be downloaded here. The functions I mentioned earlier can be found in mmc.c. file. After a closer look we can notice that those functions are using other functions:

These are functions responsible for handling SPI bus which is used for communicating with SD card. Unfortunately, in the provided example those functions are written in Assembler, which I don’t know so I wasn’t able to modify them to work with my microcontroller. That’s why I decided to write those functions myself in C language. In the mmc.c. file such macros can be found:

We must modify them to work with our microcontroller. After doing that our library is ready to use. I described in earlier posts how to configure U8glib library, so now we can focus on writing a program. Below you can find the content of main.c file, however the whole project can be downloaded at the end of the article.

The given program isn’t too difficult, so I think that there wouldn’t be any problems with understanding it. I loaded a text file “plik.txt” in which I pasted a piece of letter from Zygmunt Krasiński, Polish poet to Delfina Potocka, his muse. Unfortunately fonts provided with U8glib library don’t have Polish diactric marks, that’s why sometimes instead of letters you can see some weird stuff.


With the use of the function:

We can use text cursor in the text file, so we can move the text with buttons. As an argument it takes a number of bytes, where the cursor is located counting from the beginning of the file. The rest of the functions are described on Petit FAT website.




Gdy odłączymy kartę pamięci wyświetli nam się błąd i nie zobaczymy zawartości pliku.


Here’s a short film presenting how it’s working:


File Size
Project Atmel Studio 6.2 2,25MB
LCD Graphic display ST7565R – SD Card
Bądź pierwszy i oceń!

One Comment

    5 June 2019 o 15:20

    Unquestionably believe that which you said. Your favorite reason appeared to be on the web the simplest thing to be aware of. I say to you, I definitely get irked while people consider worries that they just don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks


This site uses cookies to store information on your computer. Click for more details

Our site uses cookies to personalise site content and advertisement, to offer social network functions and to analyse traffic on our website. Information we gather about using our website are shared with our social media, advertisement and analytical partners. You can find more info on How Google uses data when you use our partners' sites or apps.