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.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

generate SPI waveform with cDaq9174 and NI 9401 to test SPI communication with sbRIO9602

Hi all,

 

i've designed an ADC board that communicates through SPI bus and i have to interface it with a sbRIO 9602

implementing on FPGA SPI protocol.

 

Actually i'm waiting for manufacturer that will deliver me the PCB, so i want to test SPI communication with sbRIO and i'm wondering if it is possible to do a test using cDaq9174 with 9401 module to generate a sample waveform and read it through sbRIO.

 

For this purpose i want to ask you if is it already available a code for cDaq9174 that generate an SPI waveform

 

Thanks in advance.

 

 

0 Kudos
Message 1 of 11
(7,905 Views)

Hi Mariano76,

 

I think it is possible to use the NI 9401 in a CompactDAQ chassis to generate a simple SPI waveform.  You will need to use a hardware timed digital output waveform task.  Check out this library to efficiently generate the SPI digital waveform.  You may have difficulty if you are trying to implement both the MOSI and MISO signals on the same module, I'm not familiar enough with the capabilities of CompactDAQ to handle multiple functions with a single module.

 

SPI Digital Waveform Reference Library

 

Cheers,

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 11
(7,901 Views)

Hi Spex,

 

thanks for your answer, i really appreciate if you can give me an example of hardware timed waveform task, 'cause in LAbView 2012 installed examples i cannot find it, also i need an example of simple SPI waveform generation, maybe with an associated timing diagram so i can understand how to create it.

 

I'm a little bit confused in this field.

 

ThanksSmiley Happy

0 Kudos
Message 3 of 11
(7,880 Views)

Hi Mariano76,

 

I apologize that my memory failed me and my terminology didn't align exactly with how the DAQmx driver and example finder refers to the method I proposed.

 

The link I posted above: SPI Digital Waveform Reference Library,  is a set of example code that generates and interrprets SPI waveforms.  It includes documentation on how the library uses SPI waveform properties such as timing, polarity, and phase.

 

In regards to streaming those waveforms out through your DAQ device, the following link has more details on the higher level LabVIEW & DAQmx development techniques:  Serial Protocol Communication Reference Design for Digital Waveform Devices.  The approrpriate term that you would find in the LabVIEW example finder is "Correlated DIO".  Most DAQmx devices do not include a dedicated timing engine to time DIO tasks, so the correlated DIO method uses an alternate timing engine such as AI or counter/timer to time digital input or output tasks.

 

If you read the above references in detail, much of the code and explanation you will need to generate an SPI waveform is included.

 

Regards,

 

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 4 of 11
(7,871 Views)

Hi Spex,

 

Thanks, I'm trying to run DAQmx SPI - Correlated DIO.VI but i get an error:

 

Run CorrDIO Device Error -201133 occurred at DAQmx Start Task.vi:2

 

Possible reason(s):

 

Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route.

 

If possible, use DAQmx Control Task to reserve all tasks that use this device before committing any tasks that use this device. Otherwise, uncommit or unreserve the other task or disconnect the other route before attempting to configure the device for input or output.

 

Device: cDAQ1Mod4

Digital Port: 0

Lines: 0, 1, 2

 

Task Name: _unnamedTask<6>

 

 

0 Kudos
Message 5 of 11
(7,868 Views)

maybe this is related to the fact that lines in 9401 must be configured all as input or as output but not both of them?

 

i think also i don't need MISO line 'cause i want to generate SPI waveform and don't want to read any signal. 

 

0 Kudos
Message 6 of 11
(7,867 Views)

Hi,

 

i've found this document related to Error -201133. on 9401 but i cannot solve it in the way following link suggests:

 

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P6TtSAK&l=en-US

 

but anyway in DAQmx SPI Correlated DIO there are 3 tasks, 1 for digital input, 1 digital output and 1 for counter.. maybe is this the problem?

0 Kudos
Message 7 of 11
(7,851 Views)

Hi Mariano76,

 

The error message leads me to believe that the NI 9401 can only be configured as output or input in a CompactDAQ chassis.  I know when the module is in a CompactRIO chassis, the lower 4 bits can be configured in one direction, while the upper 4 bits can be configured in another.  I'm not sure if you attempt to use channels 0, 1, & 2 for CLK, MOSI, and CS, then attempt to use channel 5 or 7 or MISO, you may be able to get it to work.  

 

If you get the same error, then I would follow your hunch to remove all the MISO related portions of the DAQmx Code.  You mentioned that you only need to output the SPI signals, you are not trying to read anything back, so removing MISO should not cause a problem.

 

Also, I don't know how much your time is worth, when you need to get this testing done, and how much time you have spent trying to create this waveform, but I wanted to at least make sure you are aware of a dedicated product for performing SPI communication.  The USB-8451 and USB-8452 are devices specifically tailored for SPI master communication.  You may be able to resolve your programming issues before you could ship a USB-845x device.

 

Hope this helps.

 

Regards,

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 8 of 11
(7,850 Views)

Thanks for the info Spex,

 

but actually i cannot place an order of those items, despite they would be very useful for this task.

 

Just i want to know, this example is just "one shot" SPI waveform generation, what if i want to simulate a random reading of an ADC? 

 

Thanks

0 Kudos
Message 9 of 11
(7,837 Views)

You can use the NI 9401 as both input and output in a CompactDAQ chassis, much like in a CompactRIO. It is, as you've discovered, not quite as straightforward though.

 

The KB linked to earlier in the thread, Why Do I Get Error 201133 When Trying To Perform Bidirectional DI/O with My NI 9401 in DAQmx?, demonstrates the correct way to use the 9401 bidirectionally in DAQmx.

 

You can only change line directions while no tasks are using lines on the module. This means you have to create all your tasks, and explicitly reserve them before either task is started. (Normally reservation is implicit in the DAQmx state model.)

 

You will have to make sure that lines 0:3 are all input or all output, and lines 4:7 are all input or all output. You can't mix direction within each grouping.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 10 of 11
(7,772 Views)