07-22-2012 05:25 PM
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?
This is what I did to make it read without having to send data.
this is the board I designed and am testing with.
Solved! Go to Solution.
07-22-2012 07:12 PM
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 --
07-23-2012 12:12 AM
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
07-23-2012 04:01 PM
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.
07-23-2012 04:40 PM
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
07-23-2012 05:39 PM
I think I got the conversion to work it's a bit convaluted but functional
Now it looks like I am not getting correct data out of the spi
07-23-2012 06:07 PM
I think you should be able to do this:
07-23-2012 06:51 PM
each type return a diffrent value but niether are correct.
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.
07-23-2012 11:11 PM
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.
07-23-2012 11:41 PM
I have a working sketch for sending serial data but I want to make the spi to access multiple max chips.
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);
};