Digital I/O

Showing results for 
Search instead for 
Did you mean: 

Implementing I2C or SPI with Pxi6508 in Labview

Hi Tom W:
     I looked at the signal from the oscilloscope. I found the low time for the clock  is very short (around 80-100 microseconds) compared with high time (because the high time is set to hold as 5 milliseconds ). Also the low time is not exactly the same.  I am not sure if it matters? Thank you so much.
0 Kudos
Message 11 of 36
Hello Tom and ILLGG,

I also want to do the SPI communication using 6509.But in my case master is a Microcontroller.

I want to do it like this.
1.Microcontroller send a data stream to the 6509 line.
2.6509 receives this data and stores it.
3.6509 send back the data to the microcontroller.
4.microcontroller receives the data.
5.Micriocontroller send the data to the 6509 and 6509 receives it through VISA read.
After that labview compares the data received and previously stored data and displays a message.

please help me for doing this.

Thanks & Regards
0 Kudos
Message 12 of 36

Hi Guys-

Please keep in mind that this is only an example; you will have to modify it to match the requirements of your application.


In order to modify the behavior of the "clock" line you may need to add another millisecond wait function after the second update to the clock task within the loop.  The timing from one iteration to the next could vary because everything is done with software timing- the mS wait function is not precise because it relies on the Windows system timer.  If you need more precise timing then you will have to use a device that supports hardware-timed digital operations or a device that is meant specifically for SPI communications (for example, the NI 8451)


It's not possible to answer your question without knowing what type of protocol your microcontroller uses for communication.  Nevertheless, the example linked in this thread shows how to create software-timed clock pulses and how to shift data out via the 650x digital lines.  It should hopefully be enough to get you started with your app.  Please take a look and see if you can make modifications according to the requirements of your microcontroller.


Message Edited by Tom W [DE] on 11-12-2007 08:27 AM
Tom W
National Instruments
0 Kudos
Message 13 of 36
Hi Tom W:
 Thank you so much for your help. I modified a little bit of your example and it works!
  I like this forum and the people here!
0 Kudos
Message 14 of 36

Hi Tom,

I have a question that how can i write a C that can have a same functionality as this VI.



0 Kudos
Message 15 of 36

Hi tnk-

I never had a chance to code up my example in C, but it should be easy enough to do by looking at the LabVIEW VI.  Here's the LabVIEW code:

The error cluster (green line) shows the proper order of execution.  The subVIs that say Digital Output or Digital Input are DAQmx Create Virtual Channel calls.  The subVIs with pencils and eyeglasses are DAQmx Write and DAQmx Read, respectively.  The subVIs with yellow triangles and pencil erasers are DAQmx Start Task and DAQmx Clear Task, respectively. 

The large square in the middle of the code is a For loop, and the inputs and outputs are indexed through a point at a time by the tunnels (squares on edges of For loop) that have an empty square in the middle.  The tunnels with solid squares represent constants that do not change from one loop iteration to the next.


You should be able to use this image and the existing DAQmx examples for static digital input and output ( C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital ) to come up with something similar. 

Hopefully this helps-

Message Edited by Tom W [DE] on 03-13-2008 12:31 PM
Tom W
National Instruments
Message 16 of 36
Thanks Tom,
I'm still working on this. I have another question, that can i write continuous samples to a single DO line using daqmxDigitalwriteline? Do you have any samples vi?
thanks again
0 Kudos
Message 17 of 36

Hi tknp-

Assuming you're using an NI 6508 device, you will not be able to perform a hardware-timed (clocked) generation.  You can perform a continuous software-timed generation by simply playing a loop around the DAQmxWrite function.  It is not necessary to call DAQmxStartTask and DAQmxStopTask inside the loop, and actually doing so would hurt the performance of your application.  I don't have a C-based example, but it should be fairly simple and would look something like this pseudo-code:

   err = DAQmxWriteDigitalLines

Message Edited by Tom W [DE] on 03-18-2008 10:58 AM
Tom W
National Instruments
0 Kudos
Message 18 of 36
Thanks Tom,
I have more questions. Is " build digital "also available in NI build in C function? if it is not, do you have any advice that i can create a C function act as tha build digital
thanks alot.
0 Kudos
Message 19 of 36
Hi tnk-
The Build Digital Data function from LabVIEW is only intended for use with the LabVIEW digital waveform datatype.  The DAQmx C API functions do not require the use of this datatype.  Instead, you can use numeric values (as with DAQmxWriteDigitalU8 and DAQmxWriteDigitalU32) or arrays of values (as with DAQmxWriteDigitalLines) in the DAQmx C API.

Message Edited by Tom W [DE] on 03-18-2008 05:20 PM
Tom W
National Instruments
0 Kudos
Message 20 of 36