LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Arduino MEGA 2560 + LabView

Hello everybody.

I am doing a student project.

I have my Arduino Mega 2560 card and I am using it with LabView.

I have two devices with SPI comunication.

I don't know how to manager them from LabView. I have seen some block diagrams but I don't understand them.

I have to use 2 CS pins, 1 MOSI and 1 SCK.

How must I design my block diagram?

Thank to anybody who can help me.

Greetings from Colombia.

0 Kudos
Message 1 of 16
(10,628 Views)

What specifically don't you understand?  What sensors are you using?

0 Kudos
Message 2 of 16
(5,805 Views)

Well.

It's the first time that I work with SPI.

I am making a processing unit for a student projet.

My unit has to give SPI comunication for amplifiers of programmable gain.

I must have one MOSI and two CS.

The amplifiers need 16 serial bit when CS active.

CS must be inactive when the last one bit is passed.

According to Arduino web, Arduino Mega 2560 has

pin 50 (MISO)

pin 51 (MOSI)

pin 52 (SCK)

pin 53 (SS)

When I use LIFA+Arduino Mega, als Will my MOSI be Pin 51?

Can I program other pins as CS?

I tried this Block Diagram

https://decibel.ni.com/content/thread/19217

and

I don't understand for what is the block which I show in the Capture.png

For example, I'd like to send signals like in the Dibujo1.png

Thank you.Dibujo1.pngCaptura.PNGCaptura2.PNG

0 Kudos
Message 3 of 16
(5,805 Views)

The clock and communication pins are fixed (afaik).  The CS (chip select) pin can be any digital pin, you need one for each SPI device.  The CS pin tells the device that it is active and should listen and respond to the communication on the communication lines.

The SPI Read/Write VI sends data to the device connected to the CS pin specified (by the wire to the CS terminal) and then will read data back.

Without knowing the specific device (or having working Arduino code that you have confirmed works; both would be preferred), it will be hard to tell you much more than the standard SPI protocol that you can find via google.

0 Kudos
Message 4 of 16
(5,805 Views)

ok, I get it...CS pin can be any DIO pin.

but

for the Block Diagram, I can't understand how I can say to Labview that I want to send for example 100010001000100.

0 Kudos
Message 5 of 16
(5,805 Views)

To send 0100 0100 0100 0100 to the device, you would put 68 as the first and second elements of the SPI Data array.

But, again, I can't say that any of my advice is helpful without knowing what device you are working with.

0 Kudos
Message 6 of 16
(5,805 Views)

My work group and I are using PGA112 and PGA113.

So, I would have to write those datos at SPI Data?

And should I change the word size (actually 1) for 2 ?Captura.PNG

0 Kudos
Message 7 of 16
(5,805 Views)

According to the datasheet, "If there are not even-numbered increments of 16 clocks (that is, 16, 32, 64, and so forth) between CS going low (falling edge) and CS going high (rising edge), the device takes no action."  This means that you need to send at least 16 bits (2 bytes) per SPI Write command.

The other thing that I notice is that 0100 0100 0100 0100 is not a valid command.

I've started a library for these devices based on the datasheet.  The only function that I've implemented is writing the gain value.  Use it and see what you think and let me know if it works. 

0 Kudos
Message 8 of 16
(5,805 Views)

Hey! Thank you.

You have helped me to understand a lot of things.

Of course.

I am going to test them tomorrow and then I write you.

0 Kudos
Message 9 of 16
(5,805 Views)

Hello.

I did the proof today.

I check SPI data on pin 51 and only the last 8 most significant bits are transmitted.

The CS is a good signal only in when is configured in pin 53.

The SCK signal has 8 cycles...those cycles has a total period of 5 ms.

I tried to change the SCK but I always got 8 cycles.

I did some configurations on array element but I couldn't send 16 bits.

I changed world size but always "Message Error: number of bits to send must be divided by word size" was shown.

0 Kudos
Message 10 of 16
(5,805 Views)