Gadget Renesas

Linking Ideas and Electronics


Using the function on GR-KURUMI, SD Card (SPI) Vol.

GR-KURUMIの機能を使う アナログ入力(ADC)編


Handling SD Card with microcontroller


GR-KURUMI can handle SD Card easily.
Thanks to this nifty function, GR-KURUMI can keep a log data of sensor by itself without connection to the network.
Let’s log data on temperature and humidity.
Showing the code. A part of the code is omitted since it’s the same as HDC1000 sample.
※Using a SD card library, please keep in mind followings.
1.The file name is not corresponding to long form, the file with long name is dealt with 8+3 form in a compulsory manner.
2.Small letters in file name or directory name is dealt with capital letters. Need to take care on comparison in proceeding program.
3.To reach the file in sub-directory, please access with “FULL PATH”.
4.As generaconpal information about SD Card format, SDFomatter is recommended instead of Windows.

The contents of "Temper.csv" file is as follows.

2016/1/12 0:0:10,26.2c,45.5%
2016/1/12 0:0:20,24.8c,42.9%
2016/1/12 0:0:30,24.4c,40.4%
2016/1/12 0:0:40,24.1c,38.9%
2016/1/12 0:0:50,23.9c,37.9%
2016/1/12 0:1:0,23.9c,37.9%
2016/1/12 0:1:10,23.7c,37.8%
2016/1/12 0:1:20,23.6c,37.4%
2016/1/12 0:1:30,23.6c,37.2%
2016/1/12 0:1:40,23.6c,37.0%

Added mode is active in the case of opening the file for overwriting.
Remove the file in the case of deleting the previous contents and newly writing.


Reading SD Card

Reading the contents having written into SD Card earlier. Please refer to the code below.



Writing speed for SD Card


You may have been wondering how fast you can write SD Card.

Measured the time for writing a SD card with 1Mbyte-text. It took 10483ms, approximately 10s.

Hence, the speed is 100K byte per second. ※The efficiency should be good since the writing is executed after the data is buffered at 512byte.
If writing is executed per 1byte, the speed will be slower.

Showing the code used for the experiment.


Reading speed for SD Card


Also you may have been wondering how fast you can read SD Card.

Measured the time for reading SD Card with 1Mbyte-text.
As result, it took 3870ms.
The speed is 271Kbyte per second. ※ Get ready 512byte buffer. Reading is executed per block unit.

Showing the code used for experiment.


Playing music file in SD Card

image06 image07

Found that reading SD Card was going well above, let’s try to play music data stored in SD Card.
Recommended to use MP3 form for the music data, to use dedication decoder IC: VS1063A to play MP3 data.

The interface for decoder IC is SPI.
SD Card also use SPI, being afraind that a conflict happens between two.

GR-KURUMI is preparing library for using SPI.
SPI condition for decoder IC is under 5MHz on SCK.
Out of the four SPI modes, the one which fix the topology of SCK and data is mode 0.

Again, I'm afraind that the decoder IC has a conflict with SD Card on this change. The SPI has four kinds of mode while these should be collectively controlled. Program check to see the name of all files in SD Card, including in sub-directory, read the data file based on the extension of “.MP3” as mp3 file, send the data in line with decode IC.

Complete to play all mp3 files, it’ll be the end.

Confirm the operation without fail to start playing the music under this program.

Showing the code.

MVP information


General hard engineer.. submitting his writing for technical magazine occasionally.
twitter account:

Chobichan avatar

Follow him

All articles from @chobichan