sensor
Dependencies: BMP280 ELEC350-Practicals-FZ429 BME280
Diff: main.cpp
- Revision:
- 0:1ce5a958aaf8
- Child:
- 2:fad34c30dcc4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 20 11:29:41 2017 +0000 @@ -0,0 +1,67 @@ +/* Access an SD Card using SPI */ + + #include "mbed.h" + #include "SDBlockDevice.h" + #include "FATFileSystem.h" + + SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs + + uint8_t block[512] = "Hello World!\n"; + int main() +{ + printf("Initialise and write to a file\n"); + //FileSystemLike(*sd); + + + // call the SDBlockDevice instance initialisation method. + if ( 0 != sd.init()) { + printf("Init failed \n"); + return -1; + } + //FileSystemLike(*sd); + + FATFileSystem fs("sd", &sd); + + + FILE *fp = fopen("/sd/test.txt","w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + + //Put some text in the file... + fprintf(fp, "Martin Says Hi! One for the good guys\n"); + + //Tidy up here + fclose(fp); + sd.deinit(); + printf("All done...\n"); + + /* + printf("sd size: %llu\n", sd.size()); + printf("sd read size: %llu\n", sd.get_read_size()); + printf("sd program size: %llu\n", sd.get_program_size()); + printf("sd erase size: %llu\n", sd.get_erase_size()); + + // set the frequency + if ( 0 != sd.frequency(5000000)) { + printf("Error setting frequency \n"); + } + + 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); + } + } + + // call the SDBlockDevice instance de-initialisation method. + + sd.deinit(); + */ +} \ No newline at end of file