From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Components

cancel
Showing results for 
Search instead for 
Did you mean: 

[Deprecated] SPI Digital Waveform Library

Hi alanxie -

 

Have you read the Freescale document referenced at the beginning of the whitepaper? In section 1.4.3, it defines the CPHA=0 and CPHA=1 transmission formats explicitly and should provide answers to your questions. Additional information about timing is available in the Wikipedia article on the bus.

 

Also, here is the text of the VI documentation for "Timing info (ns).ctl":

 

"Contains bus timing parameters.  All values are in units of nanoseconds, expept for SCLK Freq, which is in units of Hertz.  Contents:
MOSI Setup - The data setup tiame for a bit written on the MOSI line
SCLK Freq - The frequency of serial clock pulses while transmitting bits
SCLK Hold - The "hold time" of the serial clock. This  is the length of time that the clock is held for the slave device to be able to sample a bit written to the MOSI line.  For example, when CPHA = 0 and CPOL = 0, this is the clock "high" time.  When CPHA = 0 and CPOL = 1, this is the clock "low" time.
CS Lead - The time between assertion of a chip-select line and the first serial clock edge
CS Trail - The time between the last serial clock edge and deassertion of the chip-select line
CS Idle - The time between subsequent assertions of a chip-select line"

David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 101 of 200
(3,756 Views)

Hello everyone,

 

I need to send 133 byte to a slave device. I am using the Digital Waveform library. I already read that the high-level Vi "send" transmitts only up to 64 bit and that I have to use the

low-level-Vis to build my own "send.vi". I took the high-level.vi as a reference but still wasn`t able to build a proper transmission.

I would be very grateful for any help...

 

Regards,

Katja

0 Kudos
Message 102 of 200
(3,741 Views)

Hi Katjk -

 

Here's an implementation that allows any number of bits per message. It takes an array of Digital Values Ring, which you can create from the connector on the VI. The length of the input array determines the length, in bits, of the message. It includes optional logic to do a sanity check on the input arrays; you may want to use that logic the first time you run a vector through the VI, then skip it afterward to make the VI run faster.

 

Here's a screenshot of the code in LV 2010, though the attachment was saved for LV 8.2:

 

swap_any_length.png

 

When you look inside the LLB to drop this function on the palette, always grab the top-level VI. The first time you drop it, there'll be a search for your copy of SDW in user.lib, and probably some warnings that the dependency paths have changed.

David Staab, CLA
Staff Systems Engineer
National Instruments
Message 103 of 200
(3,722 Views)

Dear David, thank you so much for your reply!

I inserted the "Swap-any-length.vi" instead of the "Send-Mosi".vi into the DAQmx-CorrelatedDIO program.

The MOSI data takes an array of digital values ring. Does it mean I have to set all the bits manually that I want to transmit?( Ich have to transmit 133 byte!)

Is there any possibility to type in hexvalues?

 

Regards,

Katja

0 Kudos
Message 104 of 200
(3,708 Views)

Hi Katja -

 

I left that to you as a coding challenge. Smiley Wink The VI I shared can be used in anyone's application. To make it more convenient for your software, you'll have to take your preferred instance of the "Interpret Data" VI and wrap it in a FOR loop to make it correctly interpret an array of integers. Since 1064 bits only divides evenly into an array of U8s, I recommend using the Byte instance of the VI to make it easier on yourself.

David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 105 of 200
(3,693 Views)

Hi David..thanks so much for your help!

I am able now to send any number of bits.....

I just have one last question....I need to make a pause( ms) of after a certain number of bits and then continue the transmission.

Could you give me a hint how to manage that?

 

Thanks in advance, 

Katja

0 Kudos
Message 106 of 200
(3,670 Views)

Hi Katja -

 

There could be lots of ways to do that, depending on exactly how your application has to behave. A pause of several milliseconds can be tough, because if you try to do it using waveform data you could create buffering problems for your program with really large waveforms, and if you try to do it with a retriggerable counter task the jitter of the Windows OS could affect the accuracy of your pause length.

 

Since you're doing correlated DIO on a DAQmx device, I would start by looking at the example programs in the NI Example Finder under "Hardware Input and Output > DAQmx > Generating Digital Pulses". Any of those code snippets can be used to create custom clocking behavior in place of the counter/timer code in the Serial Protocol Waveform examples. For instance, the Gen Dig Pulse-Retriggerable.vi example shows how to create a finite pulse train that can be regenerated over and over again. If you can find a way to provide that start trigger from a dependable source, it should let you define the behavior you need.

 

If you still can't figure it out, try posting in the Multifunction DAQ forum for help writing DAQmx code that works exactly the way you need it to. The people who monitor that forum are much better with DAQmx devices than I am these days.

David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 107 of 200
(3,666 Views)

Hi David,

 

I am new with LabVIEW and am trying to use this library in my first project. Can you tell me if this works with a nRIO that uses a NI 9401 module?

 

Also, in reading the article concerning this library I am uinsure about what the requirements are for SPI Timing and Bus Confgiuration. They look like clusters but what is the data that they are expected to contain?

 

Thanks,

Brian

0 Kudos
Message 108 of 200
(3,656 Views)

Hi Brian -

 

No, this library only works with Digital Waveform devices that use the NI-DAQmx or NI-HSDIO drivers. (Digital DAQ cards and High-Speed DIO cards.) The 9401 is a CompactRIO module, so you'll have to use a LVFPGA example to get SPI running on that platform. Try this one: http://zone.ni.com/devzone/cda/tut/p/id/9117

 

If you have questions about using your cRIO system, I would post them in the appropriate forum here: http://forums.ni.com/t5/Real-Time-Measurement-and/bd-p/280

 

Incidentally, the SPI Timing and Bus Configuration clusters are explained a few posts up in the thread, here: http://forums.ni.com/t5/Components/SPI-Digital-Waveform-Library/m-p/1559382/message-uid/1559382/high...

 

(Sorry about the dumb URLs. The post reply form freaked out and stopped creating hyperlinks for me, and I don't have the patience to edit the HTML directly. Smiley Happy)

David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 109 of 200
(3,648 Views)

Okay, thanks David. Actually I also found a SPI example that should work with the cRIO but this one seemed much cleaner and simpler!

 

Brian

0 Kudos
Message 110 of 200
(3,643 Views)