Initializing SD card in SPI issues

守給你的承諾、 提交于 2019-11-28 07:42:55
Sembazuru

OK... I found my problem. For anyone else who runs into this issue, it is important to remember to send an extra 0xFF after getting responses. This gives the card an extra eight clock cycles to prepare itself for the next command. Some cards don't seem to need it (the Transcends that I'm using for example), but others require it.

I actually put a simple loop at the beginning of my 'write command' routine that sends 0xFF until it gets 0xFF as a response just so I don't have to go to all the different places where I read responses to make sure I put an extra send 0xFF. Because as far as the SD card is (usually) concerned in SPI mode, if there are no clock cycles coming in, time stands still.

One thing that I noted and have yet to find an answer for (but so far it isn't hurting anything), after I read the 16 bytes of the CSR, there seem to be an additional 2 bytes of non-0xFF that comes out... Is that a CRC16? Odd since the CSR has a CRC built in...

If you enabled CRC (with CMD59), then yes, data blocks will have CRC16 appended.

For more info see "Physical Layer Simplified Specification Version 2.00", chapters "Bus Transfer Protection" and "Data Read".

This is important: I've had very much trouble with SD/MMC card, until I found out that I had to select an operating voltage. You do so, by sending ACMD41 with the bit set for the voltage you're supplying the card with. Note: Only a single bit may be selected. If you don't select a voltage or select more than one, it will KEEP looping in idle-state and never exit on some SD cards.

That is: If your ACMD41 keeps sending response 0x01, you have not selected a voltage. The voltage is in ACMD41's 32-bit parameter bits 23...8. For 3.2V ... 3.3V, this is bit 20, so for instance you could:

acmdSDAppOpCond[2] = (1 << (20 & 7));           /* 3.2V .. 3.3V */

That's hex-value 0x10, so your ACMD41 would look like this... 0x69 0x40 0x10 0x00 0x00 0xCD ...or if it's a SDSC card... 0x69 0x00 0x10 0x00 0x00 0x5F

Here's a short (and incomplete) table of the most common values:

Bit23: 3.5V..3.6V
Bit22: 3.4V..3.5V
Bit21: 3.3V..3.4V
Bit20: 3.2V..3.3V
Bit19: 3.1V..3.2V
Bit18: 3.0V..3.1V
Bit17: 2.9V..3.0V
Bit16: 2.8V..2.9V
Bit15: 2.7V..2.8V

You do NOT have to switch CS high at ANY point in time. You can keep it low ALL the time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!