real honest
Dependencies: ELEC350-Practicals-FZ429
Fork of Task680solution-mbed-os-FZ429ZI by
main.cpp
- Committer:
- rubbehducky
- Date:
- 2018-01-07
- Revision:
- 5:49bcc61caa2c
- Parent:
- 4:958cfd74ef1c
File content as of revision 5:49bcc61caa2c:
/* Access an SD Card using SPI */ #include "mbed.h" #include "SDBlockDevice.h" #include "FATFileSystem.h" #include "sample_hardware.hpp" //SD Card Object SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs // Data type int main() { printf("Initialise\n"); //FileSystemLike(*sd); // call the SDBlockDevice instance initialisation method. if ( sd.init() != 0) { printf("Init failed \n"); errorCode(FATAL); } //Create a filing system for SD Card FATFileSystem fs("sd", &sd); // ************* // Open to WRITE // ************* printf("Write to a file\n"); FILE* fp = fopen("/sd/test.txt","a"); //Check file handle (stream) if (fp == NULL) { error("Could not open file for write\n"); errorCode(FATAL); } /* //Put some text in the file... //This if ( 0 == sd.program(block, 0, 512)) { fprintf(fp, "Welcome to ELEC350\n"); } */ if (onBoardSwitch == 1) { press = true; } if (press == true) { //Close File fclose(fp); //Close down SD card (flush buffers) sd.deinit(); //Let user know puts("You can now remove the SD Card\n"); for (unsigned int n=0; n<2; n++) { onBoardLED = 1; wait(0.2); onBoardLED = 0; wait(0.2); } //Flag to record the event ejected = true; } //Close the file fclose(fp); //Close down sd.deinit(); printf("All done...\n"); errorCode(OK); //Flash to indicate goodness while(true) { greenLED = 1; wait(0.5); greenLED = 0; wait(0.1); } } /* printf("sd erase size: %llu\n", sd.get_erase_size()); if ( 0 != sd.erase(0, sd.get_erase_size())) { printf("Error Erasing block \n"); } // Write some the data block to the device if ( 0 == sd.program(block, 0, 512)) { // read the data block from the device if ( 0 == sd.read(block, 0, 512)) { // print the contents of the block printf("%s", block); } } */