Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 5 months ago.
How can I get a library for a SD card reader ?
Hi to all, I'm working on NUCLEO-L073RZ Board with a digital accelerometer (ADXL355) linked by SPI bus; now I'm wondering if it is possible to save the accelerometer data on a SD card, so I'd like to know how can I get a library for interfacing the reader. Please, could anyone help me ? regards
3 Answers
7 years, 5 months ago.
Good working example is under this author's directory https://os.mbed.com/users/neilt6/code/ The one you need is called SDFileSystem_HelloWorld
7 years, 5 months ago.
Use mbed OS. It has built in filesystem APIs. I'd start here for documentation - https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/storage/storage_index/
7 years, 5 months ago.
This is the specific library for SD cards if it helps: https://github.com/armmbed/sd-driver
Here's a quick example (assuming you have formatted the sd card, you should be able to format FAT on your computer):
SDBlockDevice sd(spi, pins, go, here); FATFileSystem fs("fs"); int main() { sd.init(); fs.mount(&sd); FILE* fd = fopen("/fs/hi.txt", "w"); fprintf(fd, "hello!"); fclose(fd); sd.deinit(); fs.unmount(); }
Here's a full example with all of the error handling (you will need to change the block device to SDBlockDevice): https://github.com/ARMmbed/mbed-os-example-fat-filesystem