LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MAX31685 Interface on myRIO

Solved!
Go to solution

I just simplified your code. However, it does the same.

0 Kudos
Message 11 of 29
(1,695 Views)

I'm trying to communicate with an Adafruit 31865 thermistor chip using the USB-8451 SPI DAQ and getting nothing but 0xFF as a response.  I've read the NI tutorial on SPI communication and spilled over the Adafruit chip specs without any luck.  I've attached the code I'm using.  I pulled it almost straight out of the NI tutorial and made it as explicit as possible.  I've tried setting the phase, polarity etc. as my understanding from the Adafruit documentation and then just brute forced every combination. No luck.  I ever only get 0xFF as a reply.  I get the correct number of bytes, but just 0xFF.  I've tried creating a SPI script instead of using the NI provided VI and I get the same results.  Any ideas?

Download All
0 Kudos
Message 12 of 29
(1,655 Views)

Hello,

 

I'm trying to work withe the Adafruit MAX 31865 chip using the NI USB-8451 SPI DAQ and getting nowhere.  I've tried using the LabVIEW example read/write programs and modifying them as I thought to.  I tried implementing your sequence but all I get as a response is 0xFF.  Any idea what I may be doing wrong?  I've tried every combination of polarity and phase.  Nothing is working.

0 Kudos
Message 13 of 29
(1,624 Views)

HI, I cannot open your vi file because I have the Labview version 15 . Please, save it in version 15 if you want me to see it.

0 Kudos
Message 14 of 29
(1,617 Views)

I've attached the code in LabVIEW 15.  In addition to this approach, I tried the method basically straight out of the NI SPI tutorial using the basic SPI read/write VI provided.

 

Thanks

0 Kudos
Message 15 of 29
(1,608 Views)

Hi,

are you sure the connections are right?
can you send a diagram of the connections made?

0 Kudos
Message 16 of 29
(1,606 Views)

NI USB 8451                 Adafruit 31865

GND                              GND

+5V                                VIN

CS0                                CS

SDO                               SDO

SDI                                SDI

SCLK                             CLK

 

I've checked for conductivity and power.  Everything seems good (5V reads 5V, 3.3V reads 3.3V).  I've tried two Adafruit boards.  According to Adafruit tech support, the board draw 2-3 mA and the NI USB 5V port can provide 20 mA.

0 Kudos
Message 17 of 29
(1,600 Views)

Please do not use Stacked Sequences!  In fact, unless you are doing FPGA code, you almost never need the Sequence structure.  Use the Error Line to serialize your VIs.

 

It also really helps to think hierarchically and plan sub-VIs to "hide the messy details".  Here are three illustrations of sub-VIs I created for the 8451 to handle A/D conversion on a different chip.  I'm only presenting "pictures", but with explanations that explain how it works and what you might want to change.

 

Do you know about VIG's (stands for Virtual Instrument Global, a "do once and remember for future use" routine)?  This VIG "finds" the 845x device, sets up SPI, and returns (for subsequent use) the Device Reference and the SPI Configuration Reference.  This is called "NI-845x SPI Refs" (you'll see it as a blue box on later pictures).

NI-845x SPI Refs.png

Notice the "First Call?" function that runs the outer Case structure when you first call this VIG.  The little blue sub-VI "Find SPI Master" is pretty simple-minded -- it queries VISA for any device whose names starts with USB and if it finds exactly 1, it says "This must be the SPI Master".  You could easily substitute a Constant Device Reference here.  Notice that this sets up the SPI configuration and does it once (because First Call? is only true once).

 

SPI A-to-D Setup.png

Before doing A/D conversion, you have to configure the A/D Chip.  For my chip, this requires a one-byte command (which I build out of bits, why not?).  Since the SPI Read/Write requires an Array input, I make the single Byte into a 1-Byte Array, when send it to SPI Read/Write.  Note that the Close Reference is not necessary.

 

SPI A-to-D Read.png

To read from the A/D, you need to send two "Commands" -- a Convert command (which is, in my device, another single-byte command, which you can see I put in the appropriate bits by doing left-shifts using the power-of-2 function), followed by a "Read", produced by writing as many bytes as you expect to read back, and then reading them back.  

 

I hope this suggests a clearer way of constructing your code to do similar things with your SPI A/D chip.  Again, do not use Stacked sequences without Error Lines -- it makes following the logic difficult.  Do use sub-VIs to "hide the messy details".

 

Bob Schor

0 Kudos
Message 18 of 29
(1,600 Views)

Hi, I have never used NI USB 8451 yet. However, with myRIO I connect MOSI on myRIO with SDI on MAX31685 and MISO on myRIO with SDO on MAX31685. In addition, the above post of @BOB_Schor should help you to change your vi.

0 Kudos
Message 19 of 29
(1,574 Views)

Problem found.  I interpreted the pins on the slave device as being referenced to the master device; hence, the line marked SDO on the slave was to be connected to the SDO line on the master and the SDI line on the slave was to be connected to the SDI line on the master.  That's not the convention.  SDO connects to SDI and SDI to SDO which makes sense once one knows what frame of reference is being used.

 

NI USB 8451                 Adafruit 31865

GND                              GND                          

CS0                                CS

SDO                               SDI

SDI                                SDO

SCLK                             CLK

0 Kudos
Message 20 of 29
(1,526 Views)