Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI interface

Hello all,

I'm trying to implement an spi interface using the USB-6229 OEM card in matlab code (using the C functions by loading the dll into matlab).

I use the frequency generator to make a clock of 100kHz which I use as the sampling clock for the 3 digital output lines (CSN, SCK, SDI). I can manage the write operation via the DAQmxWriteDigitalU8 command.

However I have troubles finding a solution to do the read operation. So I have some questions.
Is it possible to use the SCK digital output as input for the sample clock of the read operation?
Another possibility is maybe to use the freqout as sample clock for the read operation, but then I wonder when this operation will start. Timing is of course imporant 'cause we wouldn't want to miss a sample. Can the CSN line be used as a trigger?

Are there any examples available for SPI interfaces (C or matlab code, no labview examples)?

Thx

Bert
0 Kudos
Message 1 of 13
(5,514 Views)
Maybe my explanation wasn't clear enough, so I will do another attempt.
The read operation of the spi is in fact a combination of writing and reading data. First the CSN, SCK and the SDI lines (SDI is the address of the wanted register) have to be written (8 SCK periods). The next 8 SCK periods I want to read the data from the SDO line. The CSN and SCK lines are then written at the same.

For the write operation I use the frequency generator (FREQOUT) as sample clock. When I use the FREQOUT as sample clock for the read operation, how do I know when the reading starts and the right samples are read? How can I configure the moment of sampling? Is it possible to configure it and are there maybe other methods/suggestions to do the read operation?


I also have a question about the frequency generator. I'm using the function DAQmxCreateCOPulseChanFreq to create a clock, but I can't make it faster than 100kHz (when I do the clock is always 630kHz). In the DAQ M-series user manual it's explained that the frequency generator can have 2 inputs: the 20MHz or the 100kHz clock. How can this be configured? I assume that in my case the 100kHz is used?
0 Kudos
Message 2 of 13
(5,495 Views)
Hi,

I would suggest you use one of your counters to generate the clock (sample clock) for the SPI protocol. This pulse generation can be digitally triggered, so you have control when it starts.

Input and output operations can then be clocked on this sample clock, right? How you have to do this in Matlab is not know to me, i can only give you examples in C from LabwindowsCVI.

I'm including an example to do continious digital pulse train generation, which is digitally triggered. Hope it helps you.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
Download All
0 Kudos
Message 3 of 13
(5,467 Views)
Hello,

Thx for the answer. The SPI communication is allready working fine. I connected the created SPI clock SCK externally to a PFI line and used it as sampling clock for the incoming data.

However I still have not figured out how I can generate frequencies higher than 100kHz with the frequency generator. According to the DAQ M series user manual it should be possible to choose between 2 input clocks (20MHz and 100kHz). In my case it seems to be connected to the 100kHz. How can I configure this?

thx

Bert
0 Kudos
Message 4 of 13
(5,462 Views)
Hi,

Perfect, nice to hear that the SPI communication works with use of an PFI line. For the question about the 20 MHz and 100 kHz frequency generation with the frequency generator. I will have to get back to you on this, i already verified that indeed according to the manual it should be possible to select the 20MHz devided by 2 and that this should be done similar like programming a normal counter but i have not been able to find any example on this. I found already some post on the forum and a link but that link was broken so i need to look into this a bit more. I will let you know when i find anything.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 5 of 13
(5,458 Views)
Hi,

I looked into it some more and have not found any good examples in C. I however have found an example in Labview. If you are interested in this, just let me know. What i can tell you is that it should work just like generating pulses with a normal counter and selecting the Dev1/freqout (or something else depending on your setup) channel as output channel.

So something linke DAQmxCreateCOPulseChanFreq(gTaskHandle,"Dev2/freqout","",DAQmx_Val_Hz,idle,0.0,freq,duty) could do the trick.
Then all you need to do is set the output terminal to a PFI or RTSI line. Normally something like
DAQmxConnectTerms ("Dev1/freqout", "Dev1/PFI0", DAQmx_Val_DoNotInvertPolarity); should do the trick, however i am not able to verify this
because i am lacking the hardware to do this. The example in labview only calculates a frequency starting from 10Mhz or 100kHz divided by the divisor
and that number will go to the frequency parameter of the create "counter output pulse" channel. So nothing fancy, but in C i can't find a good example anywhere and i can't verify things myself cause i have not got a 6229. Perhaps you could ask such a question also on the CVI forum because it has all to do with the correct C commands.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 6 of 13
(5,453 Views)
Hi Joris,

Thx for the fast replies.
I use the command exactly as you describe it in your post. The only difference is that I use the default output PFI line from the frequency generator (PFI14 for USB 6229 oem), but that should not make a difference I guess. The thing is that when I fill in a frequency higher than 100kHz the frequency is not what I expect. I tried for example to output a clock of 200kHz, but the clock I received on the scope is then 630kHz. I don't have a clue where that number comes from.
So I was wondering if the input for the frequency generator can be configured in some function. The function DAQmxCreateCOPulseChanFreq doesn't seem to have that feature. As you suggest, I'll make a topic in the CVI forum.

Thanks for your help,

Bert
0 Kudos
Message 7 of 13
(5,446 Views)
Hi,

I have one more thing you could try. I noticed when looking in MAX at the device routes from the USB 6229 that the freqout signal is on the "Dev1/FrequencyOutput" line try using that in your program (and change the Dev1 if necessary). I have tried getting the frequency output circuit to work but i haven't been succesful, even not in labview with some premade examples. So I think i am going to ask some help somewhere, cause i think the examples i have for labview are not good either. In the meantime try using the signalname above in your program and let me know what happens and also perhaps someone will reply on your other post.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 8 of 13
(5,427 Views)
Hi,

I have seen the light. Sorry it took me so long. The problem is that the 630 kHz signal you measure is the lowest frequency you can get with the 10 MHZ signal selected. Actually its a frequency of 625kHz that is the lowest with the 10 Mhz clock.

The frequency's you can have are 100kHz divided by 1 to 16 so from 100 kHz to 6,25kHz
and 100 Mhz divided by 1 to 16 so from 10 Mhz to 625kHz
This is caused by the fact that we have a 4 bit divider after the clock source like you can see in your manual.
This counter can have 1,2,3,4,...,15,16 as a value and will divide the clock by this amount.

If you want to have a signal of a frequency that is not within the possibility of the frequency generator, you will need to use an on board counter.
those have got more bits and thus can have more output frequency's. I hope this helps you, and I geuss you now understand what is happening.
Kind Regards,

Joris Donders
National Instruments
EMEIA GTM Lead for Semiconductor
www.ni.com/semiconductor
0 Kudos
Message 9 of 13
(5,422 Views)
Hi,

Thanks for the explanation!
Now it all makes sense. As I understand it, the input clock for the frequency generator is even automatically chosen, depending on the input frequency.
I just tried an input frequency of 1MHz, and indeed, 1MHz is seen on the scope!

Thanks a lot to clarify this issue for me.


Bert
Message 10 of 13
(5,409 Views)