astronouth7303
Member
I'm trying to get a MAX6675 thermocouple break-out board working with a Teensy 3.1. However, when I try to read the data from the device, it only reads 0. I don't have a bus pirate/etc to diagnose this.
Datasheet
The code for readThermo is based on a blog post I found, updated for SPI Transactions. Some googling and examination of the datasheet suggests that this code is essentially correct, but I shouldn't be getting 0 back with every read.
Datasheet
Code:
#include <SPI.h>
#define CS 10
const SPISettings thermo_settings(4000000, MSBFIRST, SPI_MODE1);
uint16_t readThermo() {
SPI.beginTransaction(thermo_settings);
digitalWrite(CS, LOW);
delayMicroseconds(1); // Wait 100ns
uint8_t msb = SPI.transfer(0);
uint8_t lsb = SPI.transfer(0);
digitalWrite(CS, HIGH);
SPI.endTransaction();
return (msb << 8) | lsb;
}
void setup()
{
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
SPI.begin();
}
void loop()
{
static uint8_t count = 0;
uint16_t raw = readThermo();
uint8_t status = raw & 0b111;
Serial.print(count, HEX);
Serial.print(" ");
Serial.println(raw, BIN);
count++;
delay(100);
}
The code for readThermo is based on a blog post I found, updated for SPI Transactions. Some googling and examination of the datasheet suggests that this code is essentially correct, but I shouldn't be getting 0 back with every read.