Hello all, I am stuck on a problem trying to read the MAX31855 Thermocouple Amplifier from Adafruit.
Product Page:Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade) : ID 269 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits
Data Sheet: http://www.adafruit.com/datasheets/MAX31855.pdf
(The SPI details are found on page 9 and 10)
The problem is if you look at the Adafruit library, it dosen't use the SPI.h library and rather simulates the SPI transfer using a for loop and a digitalRead() on the slave out pin. The reason for this seems to be the MAX31855 itself. This device has no MOSI function, so it dosent matter what you send it. Basically, you drive (and keep) the chip select pin low for 32 clock cycles to read the data. The 32 bit value returned as an unsigned long should be compatible with the current library. The other things to consider is the chip has a 5MHz max limit, the data is presented on the falling edge from MSB to LSB. I believe I have it setup correctly.
My end goal is to read thermocouple data and log it onto an SD card. So I need to use the hardware SPI to interface with it. I have tested it separately and it works well. I am an engineer by day, and hobbiest by night. So I am not an expert, I appreciate both your patience and your help.
Here is an example of my code. I think it is clear what I am trying to do, but isnt working. Just trying to read the raw binary data out in serial. If i grab the thermocouple and warm it up I should see digits 2 through 14 shifting proving its working.
#include <SPI.h>
int SlavePin1 = 4; //Thermocouple #1
void setup() {
Serial.begin(9600);
Serial.println("Starting Program");
//SPI Setup
SPI.begin(SlavePin1); // Setup SPI to use pin 4 as CS.
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SlavePin1,1); // Use SPI Mode 1 (CPOL = 0, CPHA = 1)
SPI.setClockDivider(SlavePin1, 21); // Set SPI Clock divider to 21.(4MHz)
Serial.println("SPI Variables Established");
digitalWrite(SlavePin1, HIGH); // Deselect MAX31855 chip
Serial.println("Deselect MAX318555 Chip");
}
void loop() {
Serial.println("Loop Started");
union {
byte byte1;
byte byte2;
byte byte3;
byte byte4;
unsigned long longResult;
} temperature;
digitalWrite(SlavePin1, LOW);
Serial.println("MAX31855 Selected");
// read all 4 bytes
temperature.byte1 = SPI.transfer (SlavePin1, 0xFF, SPI_CONTINUE);
delay(1);
Serial.println("Got byte 1");
temperature.byte2 = SPI.transfer (SlavePin1, 0xFF, SPI_CONTINUE);
delay(1);
Serial.println("Got byte 2");
temperature.byte3 = SPI.transfer (SlavePin1, 0xFF, SPI_CONTINUE);
delay(1);
Serial.println("Got byte 3");
temperature.byte4 = SPI.transfer (SlavePin1, 0xFF);
delay(1);
Serial.println("Got byte 4");
Serial.println (temperature, BIN);
delay(1000);
}