Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] SPI SD card addressing problem

Status
Not open for further replies.

ptjw

Junior Member level 3
Joined
Apr 29, 2011
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,597
hello,

i am using a SPARTAN 3A FPGA to interface with an SD card via SPI, i have gotten it to initialize (CMD0, ACMD41) and now i am trying to read a block of data from the card.

my problem is that the card does not send back any of the information i am requesting...but it is sending SOMETHING...

44_1308132021.jpg


this is the screenshot of the SD card i am using in winhex, i am trying to access the data on the config.txt file in the card. i typed in (ASCII) "2500000000..." and in winhex you can see that the hex values of the card is 32 35 30 30 30 30 30 which is correct.

the address of that data from what i can see is 00057000? i sent CMD17 (read block) to the SD card by sending "FF5100057000FF" and i get the reply 10 00 00 00 00 (in hex) etc etc which doesn't correspond to the data i have in the picture above...

is my address wrong? i should not be getting back any data at all if my SPI interface is wrong, the MISO pin goes to high after the card sends its data which i assume that means it goes to idle state so the interface does work..only that the data being sent to me is wrong...

anyone have any idea what could be the problem? thanks!
 

SDSC, somehow i'm getting weird responses from the card..i don't know if the way i obtain the address is correct?

thanks!
 

Are you sure the initialization is successfull?
Then are you sure that you are giving the argument of command as (required sector number * 512) ?

---------- Post added at 16:26 ---------- Previous post was at 16:19 ----------

from your command , the sector number is 696. Then are you sure that the starting sector number shown in the winhex for the config.txt file is the same as 696?
 

hello,

696 x 512 = 356352 in decimal which is 57000 in hex, this is the same address as the config.txt address shown in the picture above, am i correct?

i am sure the initialization is successful, after sending ACMD41 the SDcard replies with 0x00 then goes high (idle),

i send CMD17 by sending "FF5100057000FF" via the MOSI line and i get 0x00 then 0xFE and then i get the data..i only stored the first 2 bytes which i got 00010000 00000000 which is not what i expected because the data in config.txt from the picture above should be 0x32 which is 00110010 00110101

is "FF5100057000FF" the correct command to send? 0x51 is CMD17 and 00057000 is the address..
 

yes right....
Yes CMD17(single sector read) is also correct...
Then you are even getting the data read start token(0xFE) also!

So, now could you read the sector zero(MBR) by giving argument 00000000? Just verify if it is correct as seen in winhex.
 

okay nevermind i fixed it, turns out the address isn't 57000

i kept using the logical address which was 696 x 512 = 356352 = 0x57000 which is wrong

apparently the correct addressing for SD cards through SPI is to use the PHYSICAL address which through winhex i found was 833 for config.txt

i took 833 x 512 = 426496 = 0x68200 and this time i got back 32 35 30 30 30 etc instead of the random information i was accessing previously, thanks for your suggestions though, appreciate it!
 

is it!
I calculated the sector number from your command. That is why i asked you to verify the sector number corresponding to config.txt file shown in the winhex is 696. :)
So instead of 696 the 'sector number' shown corresponding to that config.txt file is 833..right?
 

it showed both physical sector and logical sector...i assumed logical sector was the one i should use because even the address of the data shown was in terms of logical sector (57000 instead of 68200), so yeah it was confusing but its all good now, thanks!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top