I am using FatFS. After solving card initialization problem I am trying to read sector 0, but the card returns junk data.
This is my read operation:
I see that the card replied with 0x00 which means that it is read to deliver data.
Of course my zeroth sector dumped with a USB card reader looks correctly:
This is my debug log (CMD numbers are in hex):
388:mmc_disk_initialize: SPI initialized
366:send_cmd_INTERNAL: call 401 Cmd 00 response 01
403:mmc_disk_initialize: CMD0 okay
366:send_cmd_INTERNAL: call 405 Cmd 08 response 01
406:mmc_disk_initialize: CMD8 okay - this is an SDv2 card
409:mmc_disk_initialize: CMD8 response 000001AA
413:mmc_disk_initialize: Waiting for leaving idle state
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 01
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 01
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 01
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 01
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 01
366:send_cmd_INTERNAL: call 309 Cmd 37 response 01
366:send_cmd_INTERNAL: call 415 Cmd 29 response 00
419:mmc_disk_initialize: Checking CCS bit in OCR
366:send_cmd_INTERNAL: call 420 Cmd 3A response 00
423:mmc_disk_initialize: CMD58 response 80FF8000
452:mmc_disk_initialize: Init okay
40:disk_initialize: status = 0
58:disk_read_INTERNAL: Call from 27
366:send_cmd_INTERNAL: call 494 Cmd 11 response 00
60:disk_read_INTERNAL: buf=20001588 sector=0 count=1
27:test_task1: Read result 0
28:test_task1: dump len 512
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FE000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
0000000000000000001B3DAFBF000080
0101008311F4FD3E000000C2EF3A0000
00000000000000000000000000000000
00000000000000000000000000000000
- My debug data is 100% consistent with logic analyzer traffic.
- Initialization is the same as in FatFS reference driver, only SPI layer is changed, so I would expect the initialization to fail if something was wrong with SPI itself
- SPI clock is around 150kHz
- Card returns the same junk every time, another card returns another junk reliably
- I am sending 2 dummy bytes with CS high between commands
What should I check/change to make read command work reliably?
Best Answer
What you read om the µC is the MBR (Master Boot Record) with the partition table. This data you cannot read on a OS like windows without admin privileges! The USB card reader data clearly shows the first sector of the "drive" (partiton)- which is not sector 0 (zero).
Some hex editors can show your the MBR if started as an admin - but you must use the correct physical device, which has no drive letter.