Pages: [1]   Go Down
Author Topic: SD Libraries  (Read 922 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone, I am trying to figure out how the sample data logger program works in detail, specifically what commands and data are written to the SD MOSI port, what is read from the MOSO port. Referencing the library’s in the Arduino 0022 package which library files should I be looking at to see how the SD.begin(), SD.open(), println() and close() sends and receives data to the card’s spi port.


Thanks in advance 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SD.begin() and SD.open() are defined in SD.h and implemented in SD.cpp. close() is defined in File.cpp.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks I'm going to take a look at them now
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I must have phrased my question incorrectly. I understand that the SD.h file defines the open command for example:

File open(char *filename, uint8_t mode = FILE_READ);

but what I want to figure out is what bytes are written to the MOSI pin when your c code in the data logger program has the values:

File dataFile = SD.open(“datalog.txt”, FILE_WRITE)

I am not a software ninja (I am an EE) so if I missed something in the SD.h or SD.cpp file I apologize. I imagine the bytes written to the mosi port would be something like:

58 hex for example (CMD24 or CMD25 write command), a response on MOSO, then the data block with the ascii code for d a t a l o g . t x t and some other stuff.   

What I want to know is where is this defined, any help with what line in the file it is defined in would be greatly appreciated.
Logged

France
Offline Offline
Sr. Member
****
Karma: 2
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

may if you search in your arduino folder something like :

Sd2card.cpp ...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this looks promissing, thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your help Grag38. After looking at Sd2Card.ccp I figured out it is doing this:

1.Sets I/Os for card, MISO, MOSI, SCK, and chip SelectPin
2.Set CS high write 80 bit logic high MOSI (10 bytes 0xFF)
3.Set CS low
4.write CMD0
5.look for idle response R1 (0000_0001 8’b)
6.write CMD8 with argument 0x1AA
7.read last byte of the R7 response
8.if the last byte is 0xAA the card is SD_CARD_TYPE_SD2 (in our case it is)
9.Issue Acmd41 by first sending Cmd55
10.read last byte of the R7 response for both comands

This agrees with the SD physical layer spec document so that's great.

My next question is when the datalogger program executes the line:

File dataFile = SD.open("datalog.txt", FILE_WRITE);

I want to figure out what is going on in that level of detail. Which library or libraries should I look at to figure out how the text file is created, how the file name is assigned etc.

Thanks
Logged

Pages: [1]   Go Up
Jump to: