Using the function on GR-KURUMI, SD Card (SPI) Vol.
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.
１．The file name is not corresponding to long form, the file with long name is dealt with 8+3 form in a compulsory manner.
２．Small letters in file name or directory name is dealt with capital letters. Need to take care on comparison in proceeding program.
３．To reach the file in sub-directory, please access with “FULL PATH”.
４．As generaconpal information about SD Card format, SDFomatter is recommended instead of Windows.
The contents of "Temper.csv" file is as follows.
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
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
Playing music file in SD Card
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.
General hard engineer.. submitting his writing for technical magazine occasionally.