SDfilesystem example for WIZwiki-W7500
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
Prerequisite
SD Cards are widely used by loads of devices for storage; phones, mp3 players, pc's etc. That means they are a very cheap option for storing large amounts of non-volatile data (i.e. the data is not lost when the power is removed). They should be ideal for data logging and storing audio/images.
WIZwiki-W7500 have a SD card slot that can operate in its SPI interface.
This library is to allow SD card File System on WIZwiki-W7500 and updating MP3 files from server to SD card via FTP protocol.
To implement this function, you need a Platform board and SD card. Below are what we used.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
- SD card
Hardware Configuration
WIZwiki-W7500 Pin map
SPI1 for SD Card
SPI1 on WIZwiki-W7100 is for reading from or writing to SD card and pins for SPI1 are PB_0, PB_1, PB_2 and PB_3.
Software
SPI Initialization
main.cpp
SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed Cool Components workshop board
Make Directory and Open a Text File
main.cpp
// Make Directory mkdir("/sd/mydir", 0777); // File Open for writing FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); }
Write Text into File
main.cpp
fprintf(fp, "Hello fun SD Card World!");
Caution
This example can access SD File system and write Message into SD File system
main.cpp@2:7429829fd3cd, 2017-04-11 (annotated)
- Committer:
- jehoon
- Date:
- Tue Apr 11 01:29:01 2017 +0000
- Revision:
- 2:7429829fd3cd
- Parent:
- 1:d53e2a035111
update library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
mbed_official | 0:bdbd3d6fc5d5 | 3 | |
WizLeo | 1:d53e2a035111 | 4 | SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed Cool Components workshop board |
mbed_official | 0:bdbd3d6fc5d5 | 5 | |
mbed_official | 0:bdbd3d6fc5d5 | 6 | int main() { |
mbed_official | 0:bdbd3d6fc5d5 | 7 | printf("Hello World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 8 | |
mbed_official | 0:bdbd3d6fc5d5 | 9 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 10 | |
mbed_official | 0:bdbd3d6fc5d5 | 11 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 12 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 13 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 14 | } |
mbed_official | 0:bdbd3d6fc5d5 | 15 | fprintf(fp, "Hello fun SD Card World!"); |
mbed_official | 0:bdbd3d6fc5d5 | 16 | fclose(fp); |
mbed_official | 0:bdbd3d6fc5d5 | 17 | |
mbed_official | 0:bdbd3d6fc5d5 | 18 | printf("Goodbye World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 19 | } |