I need some help interfacing a Micro SD card with a Blackfin BF537 EZ-Kit Lite, which I've connected to the board via the SPI port. Using the example code, I can do some basic I/O with the SPI that I can read on a scope. At this point, I have a breakout board connected to the appropriate pins, but I don't know how to proceed with executing some read/write commands. Does anyone know of any VIs that implement SPI protocol to do this?
I have working code for accessing SD Cards over the SPI port. However this code doesn't work with all cards (I haven't been able to get a SanDisk Ultra II card to work). What exactly do you need (the functionality is included in a large project which I cannot give away, but I could give you some of the SD Card methods - any maybe also the FAT driver).
I assume the example you're referring to is the "SPI and UART.lvproj" found in the NI Example Finder. This gives the structure in which to perform read/write commands and the Blackfin SPI VIs should be enough to implement the SPI protocol. If you're looking for something specific to communicating with a Micro SD card, it looks like Markus can help you out. Are you generally just having some difficulty using the SPI VIs and need some assistance? Thanks.
Sorry I haven't responded for a while. I've been working on some various ideas with varying degrees of success. I've gotten the card to initialize in SPI mode, but I'm having issues with getting the proper ACMD41 response - I keep getting an improper command error as a result, followed by a series of CRC errors.
Markus: Could you tell me what SD card you've been working with? Perhaps working with a different model might help this process out.
Could you attach your code or a screenshot of your code as well as the SD Card your using and any appropriate links. That way we might be able to offer some suggestions to help you get this thing working.
Thanks a lot, Markus! I got your initialize protocol to work, and I believe that I'm successfully writing to the card. I haven't been able to get reading to work correctly, but you should be glad to know that everything I've done works so far with the SanDisk Ultra II in MMC protocol - I don't know why it works under that protocol and not SD.
I'm also trying to implement SD Card R/W over SPI, and have been somewhat successful. My problem is that my reads and writes are very slow (I wish I could get 8KB/s speeds!) and I continually lose the connection and have to re-init. I was wondering if you could let me know what parameters you are using to open and configure the SPI port? I am setting "Set Dataflow Method" to 2, "Set Master" to 1, "Set Clock Phase" to 0, and "Set Clock Polarity" to 0. I notice that you are using Phase and Polarity of 1, but I can't even get the SD Card to respond when I do this. I also can't get speeds of more than 1MHz, nevermind the 10MHz you seem to be getting.
* Set Transfer Init Mode = 1 * Set Baud Rate = 400000 (for SD-Card initialization, 25 MHz for SD-Card operation) * Set Clock Phase = 1 * Set Clock Polarity = 1 (SD-Cards should only work in 0/0 or 1/1, which may depend on the hardware interface) * Set LSB First = 0 * Set Word Size = 8 * Send Zeros = 0 * Set Master = 1
It is running in bidirectional interrupt mode, and dataflow method is set to 2.
If you can't get more than 1 MHz SPI clock, you should check the signals on the SD-Card. If they aren't clean, you will get performance or CRC problems.
Also note that I have deactivated the CRC checks on the SD-Card. For the commands you only need a valid CRC for CMD0, further commands are not checked for CRC per default (at least by the cards that work for me). I had CRC for data blocks activated, but the CRC calculation was *very* slow (somewhere around 500ms per 512 byte block) so I removed it for performance reasons.