LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Initialization with Labview

Hello-

 

I am attempting to communicate with my microSD card via SPI protocol. I am using a NI sbRIO 9637 with a mounted SD adapter (here's a link to the adapter itself). LabVIEW has a pre-built FPGA communication protocol for SPI. However, I do not have it purchased. Therefore, I must complete the protocol from scratch. I am currently not receiving the expected response from the card after sending the standard first command (CMD0). Instead of recieving the x01, I am recieving xFF. I have fit all the preliminary critera (~400kHz CLK frequency, 3.3Vdd). I will attach my vi and any help would be immensly appreciated as I am unable to get the card to communicate with me.

 

Thanks

Download All
0 Kudos
Message 1 of 4
(3,017 Views)

First, what are you trying to solve with a direct SPI from FPGA communication directly to an SDCard implementation that can't be solved by the native SDCard interface that is already included on the sbRIO-9637?  This seems like a lot of work when you could just use the File I/O VIs directly.  After getting your SPI IP to work properly, you will then be tasked with managing the file system and higher level disk driver, and generally, the SPI interface is one of the lower performance mechanisms for accessing an SDCard.  Of course, it is also the only method that doesn't require access to the SDCard spec and licensing.

 

My first step to debug your SPI IP would be to connect an oscilloscope or DAQ card to probe the communication lines to ensure all your clock edges and data lines are toggling appropriately.  Is your IP operating at the clock rate you expected? If you see the SDCard is outputting appropriate responses (not xFF), then look at your scratch SPI implementation for reasons why you may be sampling the data lines at the wrong times relative to the clock. SPI is not a tightly-defined standard interface, and polarity and phase of the data/clock lines is easy to get wrong.

 

An alternate approach is to reconsider the existing IP blocks that you already discounted. There are multiple SPI IP libraries available for LabVIEW FPGA, and I'm not aware of any that require an additional purchase, so that shouldn't stop you from considering them:

  • SPI IP engine - More difficult to understand for a new LabVIEW FPGA user, but follows IP best practices for separating IP from IO and is optimized for a Single-Cycle Timed Loop
  • SPI and I2C FPGA driver - More like an example program, closer to ready to run, and includes a host API to communicate with a SPI implementation from the RT user application

 

Spex
National Instruments

To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be has a 2x safety factor...
0 Kudos
Message 2 of 4
(2,947 Views)

Hello Spex,

First of all thank you for your response. I have already used the SDCard interface on the sbRIO. I am using an external adapter due to the speed increase. I am wondering what the response of 0xFF means. As there is only so much that goes into the program prior to sending CMD0. I have set up a scope and viewed all three signals. (SCLK, MISO, MOSI). They all appear to be triggering at the correct time. If desired, I can attach a photo of the scope output. Thanks for your help.

 

 

0 Kudos
Message 3 of 4
(2,915 Views)

Hello, 

 

I am currently attempting to write to, and then read from, a Kingston 4GB SDHC. I am doing this using a sbRIO-9637, I have configured the initialization so that I send CMD0(resp=x01),CMD8(resp=x01),CMD55(resp=x01),CMD41(x00). I get all the expected responses except for when I use a different SD HC card. It is also a microSDHC. The only difference is that it is Sandisk and 16GB capacity. However, they are both microSDHC. Could this capacity difference cause an error in intialization even though they are both "High Capacity" (HC) cards? 

 

Thanks

0 Kudos
Message 4 of 4
(2,951 Views)