/*############################################################# Program Name : ex4_F446RE_SDCardLoggerRead Author : Grant Phillips Date Modified : 19/09/2016 Compiler : ARMmbed Tested On : NUCLEO-F446RE Description : Example program that demonstrates the use of a SDCard with the NUCLEO board. The file that was created in ex3_F446RE_SDCardLoggerWrite is openend and read line by line. Requirements : * NUCLEO-F446RE Board Circuit : * The SDCard connected as: VCC - +3V or +5V (depending on module) GND - GND SS/CS - PB_6 MOSI - PB_5 (SPI3_MOSI) MISO - PB_4 (SPI3_MISO) SCK - PB_3 (SPI3_SCK) ##############################################################*/ #include "mbed.h" #include "SDFileSystem.h" //Niel Thiessen's library Serial pc(SERIAL_TX, SERIAL_RX); //to use the PC as a console (display output) DigitalOut myled(LED1); //LED to indicate system operation SDFileSystem sd(PB_5, PB_4, PB_3, PB_6, "sd"); //create a SDFileSystem object // mosi, miso, sck , cs , name int main() { int temp; char date[32]; //string for storing the date read char timeofday[32]; //string for storing the time read pc.printf("ex4_F446RE_SDCardLoggerRead\n\n"); printf("Reading from SD card...\n"); FILE *fp = fopen("/sd/log.txt", "r"); //open a file for reading ("r") if(fp == NULL) { //if error opening printf("Could not open file for reading!\n"); } else { pc.printf("The contents of the file is:\n"); while(fscanf(fp, "%s %s %d", date, timeofday, &temp) != EOF) { //read the date string, time string, and analog integer value //from the next line the file and repeat until the EOF pc.printf("%s %s: %d\n", date, timeofday, temp); } fclose(fp); //close the file } while(1) { myled = !myled; //flash led wait(0.1); } }