LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6356 SPI programming HELP

I am using the USB 6356 for SPI control of two PGAs. The MOSI signal will select the gain on the PGAs. I understand that the 6356 does not have SPI protocol so much of the programming will be manual. I am wondering if anyone has any examples of using the 6356 (or similar) for SPI control. 

 

Thank you.

0 Kudos
Message 1 of 9
(4,123 Views)

There's a library of VIs that you can use for generating SPI Digital Waveforms available on NI's website. You should be able to perform a DAQmx Digital Write (Wfm) with the signals that are generated.

 


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 2 of 9
(4,117 Views)

Do I need to generate an SPI digital waveform to perform a DAQmx Digital Write, or can I instead just use the DAQmx Digital Write along with a DAQmx Create Channel (with lines specifying which channel I want to write to) and use an array of 16 bit data as an input to the DAQmx Digital Write?

0 Kudos
Message 3 of 9
(4,100 Views)
0 Kudos
Message 4 of 9
(4,099 Views)

Absolutely. You can use a standard DAQmx Digital Write and specify an array of data that mimics SPI signals; the resulting control data will be the same as if you were to use the library. The only difference is that with the SPI Library I referenced, you could save yourself some time and avoid some potential mistakes if you were to generate these signals from scratch by constructing an array of low level binary. The main reason I've found people tend to use these VIs is "Why reinvent the wheel?", the SPI VIs should be capable of performing exactly the type of functionality you need for your project, without needing you to flesh out your own library of functions.

 

I had a similar goal to do with I2C Communication earlier last year; there was already an existing library for those too, but I went ahead and developed my own signals for my application instead. This was because I wanted more of a learning exercise than anything, but it allowed to implement more flexible albeit application specific control over exactly how I wanted my signals to be generated in the long term.

 

When I posted earlier about using the DAQmx Digital Write VI, I wasn't really giving you the full picture; channel allocations and timing would all need to be compensated for. In the block diagram you referenced, that would be a more precise implementation of how the Read and Write elements of the task would need to be configured.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 5 of 9
(4,092 Views)

Great!

 

I have created my SPI waveforms and then split them up and sent them to 5 different lines on my DAQmx (I have two CS lines). 

 

The slaves here are two PGAs and the MOSI line is setting the gain to one of 11 programmable gains; I have a Ring (drop-down menu) set up for the user to select the gain which is fed in to the MOSI data port on the SPI swap VI. My problem: I need to send an initial command to the slave to configure a pin on the slave (PGA), before I use the Ring to select the gain. How can I send an initial command on the MOSI line to "set" the slave, and then use my Ring to select/change the gain?

 

Thank you.

0 Kudos
Message 6 of 9
(4,027 Views)

So is your question about how to architect the code so that the "set slave" is conditionally executed?  Or are you wondering about what kind of signal is needed to set the slave?

 

There are many ways to approach conditional execution of code.  The "right" way really depends on the rest of your application.  
Do you need to execute the "set" before every transmission or only once?
Is it acceptable if the code conditionally executes the "set" command on its own, or would you prefer a method that involves more user interaction?

Does your code already make use of loops and/or event structures?  Or is it more of a single-shot program?

 

If the question is more about what kind of signal you need, we'll need a data sheet to look at.

 

Best regards,

Matthew H.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 9
(4,011 Views)

Yes, I am wondering about how to architect the code so that the "set slave" is conditionally executed. I know what kind of signal I need to send.

I only need to execute the "set" once. I would prefer the user be able to set the slave but if it is easier to just do it automatically, that is fine too.

My code does make use of T/F event structure. Right now the user presses "Set gain" every time the gain is changed on the user interface.

I guess the only way I see it now, I would need to generate an entirely different set of SDW waveforms to set the slave, and then another set of SDW waveforms to set the gain. This method doesn't seem efficient and really slows down the DAQ.

0 Kudos
Message 8 of 9
(4,004 Views)

I've attached a small example of code that approaches conditional execution from a strictly-programming point of view.  You indicated that you were already using Event Structures, so implementing/modifying the attached method shouldn't require a total refactoring of the code you have already.

conditionalExecute.png

Matthew H.
Applications Engineer
National Instruments
0 Kudos
Message 9 of 9
(3,983 Views)