Discussion:
Implementing I2C or SPI with Pxi6508 in Labview
(too old to reply)
Tom W [DE]
2007-07-23 15:10:07 UTC
Permalink
Hi Migueles-
The communication might be rather slow because the 6508 provides software-timed operation, but there's no reason that this shouldn't work.  I mocked up an SPI example a while back that might help you get started (see attachment).
Hopefully this helps-Message Edited by Tom W [DE] on 07-23-2007 10:08 AM


6508 SPI emulation.vi:
http://forums.ni.com/attachments/ni/70/7193/1/6508 SPI emulation.vi
ILLGG
2007-11-06 20:10:14 UTC
Permalink
Hi Tom W:
         I am really interested in your 6508 spi emulation vi.  Howerer your vi version(8.2) is later than my Labview version (8.0). So I could not open it. Do you have some other similar examples written in 8.0 Labview version?  I  have a PCI-6221 and I want to control a digital potentiometer with 3-wire SPI serial interface. I  just begin to learn Labview and I don' know how to do this.  Thank you so much for your help. 
Tom W [DE]
2007-11-06 21:40:09 UTC
Permalink
Hi ILLGG-
Here's the same VI, saved for LabVIEW 8.0.


6508SPIemulation[8.0].vi:
http://forums.ni.com/attachments/ni/70/7713/1/6508SPIemulation[8.0].vi
ILLGG
2007-11-09 08:40:07 UTC
Permalink
Hi Tom W,
    Thank you for your 8.0 version of the example.  I am thinking of modify your code for my project. 
 I have the digital potentiometer AD 5290. I want to control it using Labview via PCI 6221(DAQ). It contains 3-wire digital interface
CS:Chip select input ,active low.
CLK: serial clock input . Positive edge triggered.
 SDI: 8-bit Serial data input. Shift in one bit at a time on positive clock CLK edges. MSB loaded first.
Can I have some advice on how to implement this? Thank you so much!
Tom W [DE]
2007-11-09 16:10:10 UTC
Permalink
Hi ILLGG-
The example should almost work as shown.  First, the "Data Out" line refers to the line you will use to shift data out to your peripheral.  In order to clock on the rising edge, you'll want to change the "SPIClk InitCondition" to False so that it will toggle high->low with each iteration of the loop.  The only other thing you'll need to add is the CS line- I would implement this by performing a single point write to a digital line before entering the loop and then another single point write to clear the CS line.
I have attached my VI, modified to include a single point CS update task.  Give this a try and let us know if you have other questions.
Thanks-Message Edited by Tom W [DE] on 11-09-2007 09:45 AM


6508SPIemulation[8.0]_MOD2.vi:
http://forums.ni.com/attachments/ni/70/7732/3/6508SPIemulation[8.0]_MOD2.vi
Tom W [DE]
2007-11-09 19:10:07 UTC
Permalink
Hi ILLGG-
That line is for the case where you might need to perform a bi-directional SPI operation.  In other words, where you clock in one bit to your peripheral on the rising edge of the clock and then clock out one bit on the falling edge.  In the case where you need to clock in your entire input sequence before reading a response (for example, if you're clocking an address or command into the peripheral) you would actually need to seperate the two operations into two seperate loops.  If you don't need that functionality you can simply remove it from the example.
Techiess
2007-11-12 10:10:10 UTC
Permalink
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
Techiess
Tom W [DE]
2007-11-12 14:40:07 UTC
Permalink
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.
ILLGG-
In order to modify the behavior of the "clock" line you may need to add another millisecond&nbsp;wait function&nbsp;after the second update to the clock task within the loop.&nbsp; 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.&nbsp; 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 <a href="http://sine.ni.com/nips/cds/view/p/lang/en/nid/202368" target="_blank">NI 8451</a>)
Techiess-
It's not possible to answer your question without knowing what type of protocol your microcontroller uses for communication.&nbsp; 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.&nbsp; It should hopefully be enough to get you started with your app.&nbsp; Please take a look and see if you can make modifications according to the requirements of your microcontroller.
Thanks-Message Edited by Tom W [DE] on 11-12-2007 08:27 AM
ILLGG
2007-11-13 19:40:06 UTC
Permalink
Hi Tom W:
&nbsp;
&nbsp;Thank you so much for your help. I modified a little bit of your example and it works!
&nbsp;
&nbsp; I like this forum and the people here!
&nbsp;
thanks,
Anna
tknp
2008-03-13 15:10:10 UTC
Permalink
Hi Tom,
I have a question that how can i write a C that can have a same functionality as this VI.
thanks,
tnk
Tom W [DE]
2008-03-13 17:40:21 UTC
Permalink
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.&nbsp; Here's the LabVIEW code:
<img src="Loading Image...">
The error cluster (green line) shows the proper order of execution.&nbsp; The subVIs that say Digital Output or Digital Input are DAQmx Create Virtual Channel calls.&nbsp; The subVIs with pencils and eyeglasses are DAQmx Write and DAQmx Read, respectively.&nbsp; The subVIs with yellow triangles and pencil erasers are DAQmx Start Task and DAQmx Clear Task, respectively.&nbsp;
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.&nbsp; The tunnels with solid squares represent constants that do not change from one loop iteration to the next.
&nbsp;
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 )&nbsp;to come up with something similar.&nbsp;
Hopefully this helps-Message Edited by Tom W [DE] on 03-13-2008 12:31 PM


untitled4.JPG:
http://forums.ni.com/attachments/ni/70/8389/1/untitled4.JPG
Tom W [DE]
2008-03-18 16:10:09 UTC
Permalink
Hi tknp-
Assuming you're using an NI 6508 device, you will not be able to perform a hardware-timed (clocked) generation.&nbsp; You can perform a continuous software-timed generation by simply playing a loop around the DAQmxWrite function.&nbsp; It is not necessary to call DAQmxStartTask and DAQmxStopTask inside the loop, and actually doing so would hurt the performance of your application.&nbsp; I don't have a C-based example, but it should be fairly simple and would look something like this pseudo-code:

DAQmxCreateTaskDAQmxCreateVirtualChannelDAQmxStartTaskwhile(!err){ &nbsp;&nbsp; err = DAQmxWriteDigitalLines} DAQmxStopTaskDAQmxClearTaskMessage Edited by Tom W [DE] on 03-18-2008 10:58 AM
tknp
2008-03-18 22:10:08 UTC
Permalink
Thanks Tom,
&nbsp;
I have more questions. Is " build digital data.vi "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 data.vi.
&nbsp;
thanks alot.
&nbsp;
tnk
tknp
2008-03-19 21:10:14 UTC
Permalink
Hi Tom,
Umm, i'm bit confused now.
I'd like to write a data as 01110 ... to a single channel , let's say port0, channel 0( data can be a serial of data, (data array)&nbsp;or it can be only active high or low )&nbsp;. it can run in continuous samples ( it continues&nbsp;looping back and output data&nbsp;until user stop&nbsp;or call the task stop&nbsp;vi)&nbsp;or finite samples with the clock&nbsp;source control the rate.
So, in&nbsp;labview, I call daqmx do create channel. vi with linetoassign = port0/line0, then daqmxtimingclock.vi with the clock soure, rate and sample mode. However, when i choose vi to&nbsp;write a single channel,&nbsp;multiple samples, i have error&nbsp;on&nbsp;1D u8 to 1D u32, exept&nbsp;choosing waveform. Same as if i choose single channel, single&nbsp;samples 1 line (error with buffer size),&nbsp;N line (error with # line different # of data )...
That is one the of question I asked "build digital data". Sorry, I'm not familiar with labview yet
thanks,
tnk
&nbsp;
&nbsp;

Loading...