LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading SPI of MAX31855

Solved!
Go to solution

I have it sending data now. I had to chenge retval to max_retval in the print statement

/*********************************************************************************

** MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter

*********************************************************************************/

          case 0xFD:  // Init

                    MAX31855_Init(command[2], command[3], command[4]);

                    Serial.write('0');

                    break;

          case 0xFE:  // Read Raw Data

                    // Read raw data here.

                    max_retVal = MAX31855_readData();

                    Serial.write( (max_retVal >> 24) );

                    Serial.write( (max_retVal >> 16 & 0xFF) );

                    Serial.write( (max_retVal >> 8 & 0xFF) );

                    Serial.write( (max_retVal & 0xFF) );

                    break;

Also it reads on the hi to low transition so I fixed that in the code as well.

// MAX31855 Functions

void MAX31855_Init(unsigned char SO, unsigned char CS, unsigned char SCK)

{

          max_so = SO;

          max_cs = CS;

          max_sck = SCK;

 

          // MAX31855 data output pin

          pinMode(max_so, INPUT);

          // MAX31855 chip select input pin

          pinMode(max_cs, OUTPUT);

          // MAX31855 clock input pin

          pinMode(max_sck, OUTPUT);

 

          // Default output pins state

          digitalWrite(max_cs, HIGH);

          digitalWrite(max_sck, HIGH);

}

unsigned long MAX31855_readData()

{

          int bitCount;

          unsigned long data;

 

          // Clear data

          data = 0;

          // Select the MAX31855 chip

          digitalWrite(max_cs, LOW);

 

          // Shift in 32-bit of data

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

          {

                    digitalWrite(max_sck, LOW);

 

                    // If data bit is high

                    if (digitalRead(max_so))

                    {

                              // Need to type cast data type to unsigned long, else compiler will

                              // truncate to 16-bit

                              data |= ((unsigned long)1 << bitCount);

                    }

 

                    digitalWrite(max_sck, HIGH);

          }

 

          // Deselect MAX31855 chip

          digitalWrite(max_cs, HIGH);

 

          return(data);

}

0 Kudos
Message 21 of 130
(7,702 Views)

ug this took a while to figure out... but it works now

max10.JPG

0 Kudos
Message 22 of 130
(7,702 Views)

ok i've been tinkering a bit have a look at this I'm working on the error bits next

max11.JPG

0 Kudos
Message 23 of 130
(7,702 Views)

LeXLuther422 wrote:

ug this took a while to figure out... but it works now

max10.JPG

Why didn't you use my VIs?  They should work with your fixed version of the firmware.  It's much much simpler.

The max_retVal was my fault but the second thing you mention surprises me because I took it directly from the library.  I'll update the library later tonight.

0 Kudos
Message 24 of 130
(7,702 Views)

if you look i need to reorginize the bytes middle two for temp outside two for cjc

0 Kudos
Message 25 of 130
(7,702 Views)

In the library, I have one for the thermocouple temperature already.  I will create VIs for everything else shortly but didn't have the time (at the time) and would like to get the critical parts tested and working.

0 Kudos
Message 26 of 130
(7,702 Views)
Solution
Accepted by topic author LeXLuther422

With this setup it is doing everything even the errors

max12.JPG

max13.JPG

Download All
0 Kudos
Message 27 of 130
(7,702 Views)

This is what I ended up making my display look like

max14.JPG

0 Kudos
Message 28 of 130
(7,702 Views)

Please excuse that my feedback took a whole day, but it was only now that I had to build the actual circuit arround the MAX31855, and than checked everything twice and threefold to make sure that the reson for your program always returning 0°C was somewhere in the code, and not in my circuit - so that I don't "blame" your program by mistake; that would be paltry.

I'm afraid my contribution isn't nearly as profound as LexLuther's: there are no "errors" in the example VI, but it just reads in 0s...

I don't know how to help you any better - just tell me, please.

Thanks again for the great help!

0 Kudos
Message 29 of 130
(7,702 Views)

this is the base file I used and the vi's I used are available above in another post of mine.

EDIT: let me know if you want my latest vi with the display as picturd above.

0 Kudos
Message 30 of 130
(7,702 Views)