01-16-2011 04:39 PM - edited 01-16-2011 04:43 PM
Hello,
i am new to the board, and hope maybe someone could give me some tips and thoughts for my "problem". My knowledge is CLAD atm, so please keep in mind I am still a LabVIEW noob than a pro. 😉 I have a NI 6537 I/O card in my PC, and I am using it with a CB-2162 connector block. My LabVIEW is version 2009.
What i want to know or what my problem is:
I want to send and receive data via SPI (a 16bit Stream, 4 Signals SDI, SDO, SCLK and CS) from a LabVIEW VI to a chip and also want to read from a chip. So like in all SPI interfaces, CS down, first read/write bit, 2 reserved bits, 5 address bits and 8 bits data. So I type a HEX number into my VI, and the software should send my value to the chip. I also want to handle positive or negativ edge of SLCK for example, as it depends on the chip. (I have timing diagrams and also analyzed them) So, this is what I want to do or what my goal is. I already tested the I/O card with the examples given in LabVIEW, all working fine. I have found out there is a special SPI library for this, but the more I step down the SUB-VIs of this library and functions, the more confused I am. 😞 So many details and settings, it is way too big for me.
Do you think it is easier to write an own SPI VI for my purposes, or am I quicker with taking the library functions?
Thank you for your help (if you can) and best regards
Chris
01-17-2011 05:19 AM
Do you not need a NI USB-8451 for this kind of work?
01-17-2011 06:04 AM - edited 01-17-2011 06:05 AM
Why should I? I connect the chip with the DIO pins of the board, 4 channels are needed (as said CS, CLK, SDI and SDO) and the software handling all I should write, that's my job.
I now started with adopting the NI example, but getting headache. The example works with the waveform, but as soon as I add my own datastream for writing, it does not work anymore. Could you tell me where my mistake is?
01-17-2011 07:32 AM
Hello Sierra Kilo,
The Screenshot of the Error in your last post possibly results from the value of "Sampels per Channel"
Since you are configuring a "Finite" Digital Output using a Hardwareclock, the minimum Value for "Sampels per Channel" is 2 not 1.
For 1 Sample there is no need for a Hardware timing since there is no Trigger configured as well.
When you alter "Sampels per Channel" to something greater than 2 please make shure that you use the correct polymorphic instance of DAQmx Write.
For Example use the Instance: "Digital 1D U8 1Chan NSamp"
I Hope this helps a bit!
Regards
Moritz M.
01-17-2011 07:33 AM - edited 01-17-2011 07:37 AM
@Moritz: Thanks for your help, I got a little advice and now built it other way.
Now trying to develop the rest of my goals= implementing the rest of the SPI services. All suggestions welcome. 😉
01-17-2011 08:37 AM
Hello again,
I now have a basic questions, maybe someone can help me with it please:
Is it possible to write the sample clock of my VI? I want to measure my sample clock from the SCB-2162 board with oscilloscope, but I could not find any pin or function which would allow me to do that? Is it possible or not?
Thanks Chris
01-17-2011 10:40 AM
In order to see the sample clock, you need to export it to one of the PFI lines. Look for the Export Signal function in the DAQmx - Task Config/Ctrl - DAQmx Signals palette. You can select the sample clock on one of the input lines, and select a PFI line in another input. Put this function in your code. When you run it, the sample clock will appear at the PFI line you selected. The PFI lines should be brought out to the terminal block.
In order to create SPI communications, you need to create a 2D array of data. Each row will contain the data bits of the four SPI lines. Column 0 can be the clock, column 1 can be DO, and col 2 can be CS. Use a separate port for DI so that when you create your tasks, one task is for output and the other is for input. You will need to wire the appropriate lines to your device. The clock will appear on the outgoing port on bit 0, DO on bit 1, CS on bit 2. Set your rows to send CS low first, then keep the CD bit low while you send clock and data. You need to keep sending clock in order to receive data from the device. You should receive the data on the incoming port bit 0. You will have to sort out the incoming data to look at only the bits that are actual receive bits. It all depends on the device you are communicating with.
Let me know if you need more help.
01-17-2011 07:52 PM
Hi Chris,
I have a few additional links that may help you with your particular application:
SPI Digital Waveform Reference Library
Serial Protocol Communication Reference Design for Digital Waveform Devices
DF - SPI Digital Waveform Library
01-18-2011 01:36 AM - edited 01-18-2011 01:38 AM
Thanks Kyle an tbob for your help, very much appreciated.
I already found this special SPI library before and installed it, but was not sure if it would fit my goals. I did not succeed in sending it out to check the waveform with an oscilloscope, but maybe I only made a simple mistake (?).
My goals are (or what I want to do with it is simply):
- SPI communication from Hardware (NI PCIe 6537 with SCB-2162) to a chip
- CS, SCLK, SDI and SDO
- I want to differ between rising edge and falling edge of the SCLK
- SCLK has to support up to several MHz, that's why we chose the 6537 card.
- SCLK has to be set manually
Would you suggest to program it myself or built it up with the given library of SPI?
Now trying to export the sample clock as described by tbob. 🙂
Thank you very much
Christoph
01-18-2011 02:16 AM
@tbob: I succeeded in displaying the sample clock, thanks for your advice!