LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading SPI of MAX31855

Solved!
Go to solution

I am trying to read a MAX31855 SPI thermocouple. There is no input only an output I tried using read write but it never returned a result. I noticed that in SPISendRecive.vi that it used SPI Data to determine how many "Bytes to Read" from SendRevive.vi and pulled the wire and added a varible equal to the word size. I now get an output but the data isn't what I expected. anyone have some advice?

lab1.JPG

lab2.JPG

This is what I did to make it read without having to send data.

lab3.JPG

this is the board I designed and am testing with.

max31855.JPG

0 Kudos
Message 1 of 131
(54,288 Views)

Show your code.  I can't really tell what part you need help with.

I did however, read through the datasheet and made a VI that extracts the thermocouple temperature from the 32-bit data that you get from the sensor.

Let me know if you need any help with this.  If you show working code for the sensor I can add some more functions to this library to make it more complete.

-- Attachment Removed --

0 Kudos
Message 2 of 131
(17,703 Views)

this is what happens when I try to rebuild what you showed me in the vi's

I don't know how to convert the array to a normal number

lab4.JPG

0 Kudos
Message 3 of 131
(17,703 Views)

Don't try to rebuild my VIs.  You just use the "Extract TC Temp" VI in your code (that is why I locked them).  Save the whole archive (unzipped) to a local folder.  Then, you can simply drag the "Extract TC Temp.vi" into your block diagram.  But, first you must convert the U8 array that you get from SPI into a single U32.

I'll look into this further but feel free to try to figure it out if you can.

0 Kudos
Message 4 of 131
(17,703 Views)

ok I kind of got the numbers converted out of the array take a look at this and tell me what you think I am not getting a reading from your vi only 0C

lab5.JPG

0 Kudos
Message 5 of 131
(17,703 Views)

I think I got the conversion to work it's a bit convaluted but functional

lab6.JPG

Now it looks like I am not getting correct data out of the spi

0 Kudos
Message 6 of 131
(17,703 Views)

I think you should be able to do this:

[U8] to U32.png

0 Kudos
Message 7 of 131
(17,703 Views)

each type return a diffrent value but niether are correct.

lab7.JPG

what I am wondering now is if I am getting correct data from the MAX chip as I put a lighter under the thermocouple the value doesn't change accordingly.

0 Kudos
Message 8 of 131
(17,703 Views)

Maybe you need to check the error bits to see if there is actually an error.  It has a few different faults that it can detect.

Also, I would definitely recommend using a working Arduino library for this sensor and seeing if it is outputing the correct data or data that is the same as what you are currently seeing.  This will help find out if the issue lies somewhere within LabVIEW (and it's firmware) or if it's the sensor.

0 Kudos
Message 9 of 131
(17,703 Views)

I have a working sketch for sending serial data but I want to make the spi to access multiple max chips.

lab8.JPG

max31855.cpp

// this library is public domain. enjoy!

// Alec N., Control Connection

// Created August 2011

#include <WProgram.h>

#include "MAX31855.h"

MAX31855::MAX31855(int8_t SCLK, int8_t CS, int8_t MISO) {

  sclk = SCLK;

  cs = CS;

  miso = MISO;

  //define pin modes

  pinMode(cs, OUTPUT);

  pinMode(sclk, OUTPUT);

  pinMode(miso, INPUT);

  digitalWrite(cs, HIGH);

}

double MAX31855::readCelsius(void) {

  int16_t v;

  v = spiread16();

   //if fault bit set // return 2000deg

  if (v & 0x1)

            return 2000;   

  v&=0xfffc; // mask lower two bits

  return v / 16.0;

}

double MAX31855::readFarenheit(void) {

           return readCelsius() * 9.0/5.0 + 32;

}

double MAX31855::readCJC(void) {

  int16_t v;

  v = spiread32() & 0xfff0;

  return v / 256.0;

}

uint8_t MAX31855::readFaultCode(void) {

return (spiread32() & 0x7) ; // return low 3 bits  

 

}

uint32_t MAX31855::spiread32(void) {

  int i;

  uint16_t d = 0; // we only need last 16 bits, first 16 will be discarded

   digitalWrite(cs, LOW);

  for (i=31; i>=0; i--)

            {

                    digitalWrite(sclk, LOW);

                    if (digitalRead(miso))  

                              d |= (1 << i);

                    digitalWrite(sclk, HIGH);

            }

          digitalWrite(cs, HIGH);

  return d;

}

uint16_t MAX31855::spiread16(void) {

  int i;

  uint16_t d = 0;

  digitalWrite(cs, LOW);

  for (i=15; i>=0; i--)

  {

          digitalWrite(sclk, LOW);

          if (digitalRead(miso))

                    d |= (1 << i);

          digitalWrite(sclk, HIGH);

  }

  digitalWrite(cs, HIGH);

  return d;

}

bool MAX31855::readMAX31855(double *tempTC, double *tempCJC, bool *faultOpen, bool *faultShortGND, bool *faultShortVCC){

          int i;

          int16_t d = 0;

          int16_t v = 0;

          bool fault = false;

          digitalWrite(cs, LOW);

          for (i=15; i>=0; i--)

                    {

                    digitalWrite(sclk, LOW);

                    if (digitalRead(miso))

                              d |= (1 << i);

                    digitalWrite(sclk, HIGH);

                    }

          for (i=15; i>=0; i--)

                    {

                    digitalWrite(sclk, LOW);

                    if (digitalRead(miso))

                              v |= (1 << i);

                    digitalWrite(sclk, HIGH);

                    }

          digitalWrite(cs, HIGH);

 

          if (d & 0x1)

          {

                    fault=true;

                    *tempTC =9999;

          }

          else

          {

                     d&=0xfffc; // mask lower two bits

                     *tempTC = d / 16.0;

          }

 

          *faultOpen = (v & 0x1) ? true : false  ;

          *faultShortGND = ((v>>1) & 0x1) ? true : false;

          *faultShortVCC = ((v>>2) & 0x1) ? true : false;

          v = v & 0xfff0;// mask lower 4 bits

    *tempCJC = v / 256.0;

          return fault;

}

max31855.h

// this library is public domain. enjoy!

// Alec N., Control Connection 

#include <WProgram.h>

class MAX31855 {

public:

  MAX31855(int8_t SCLK, int8_t CS, int8_t MISO);

  bool readMAX31855(double *tempTC, double *tempCJC, bool *faultOpen, bool *faultShortGND, bool *faultShortVCC);

  double readCelsius(void);

  double readFarenheit(void);

  double readCJC(void);

  uint8_t readFaultCode(void);

private:

  int8_t sclk, miso, cs;

  uint32_t spiread32(void);

  uint16_t spiread16(void);

};

0 Kudos
Message 10 of 131
(17,703 Views)