hi

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by Ishwar anjana

main.cpp

Committer:
Ishwar_Anjana
Date:
2017-12-25
Revision:
4:eaaeb93c0117
Parent:
2:e0071aaa133c

File content as of revision 4:eaaeb93c0117:

#include "mbed.h"
#include "SDFileSystem.h"
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include "SPI.h"

Serial pc(USBTX, USBRX);

SPI spi(D11, D12, D13); // mosi, miso, sclk
DigitalOut cs(D9);

char hello[14] = "Hello World \n";
typedef unsigned char BYTE;

 
SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board


int main() {
    pc.baud (115200);
    printf("Hello World!\n\r");   
    cs = 1;
    spi.format(8,0);
    spi.frequency(1000000);
                                                                                          
    printf("Reading files!\n\r");
    
    
 //////////////////////////////////////////////////////////////////////////////
const char *filePath = "/sd/logo.raw";
char mystring [100];

FILE *pFile = fopen (filePath , "r");
   
if (pFile == NULL) 
{
   printf ("Error opening file");
   while(1);
}

printf("pFile is: %d \n", pFile);

  //   while ( fgets (mystring , 100 , pFile) != NULL )
  int index=0;
     while ( index< 8191 )
     {
        index++;
        fread (mystring, 1, 4 , pFile );
        //cs = 0;
        for(int i=0; i< 4; i = i+2)
        {
            //spi.write(mystring[i]);
            printf("%d, %02X",index, mystring[i]);
            printf("%02X\n",mystring[i+1]);
            wait_us(100);
        }
       // wait_us(2000);
       // cs = 1;
       // wait_us(1000);
    }
   
    printf("done with reading and closing files\n\r");
    fclose (pFile);
    }