Skip to content

Instantly share code, notes, and snippets.

@TAUTIC
Created July 27, 2011 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TAUTIC/1109516 to your computer and use it in GitHub Desktop.
Save TAUTIC/1109516 to your computer and use it in GitHub Desktop.
Test code for running 2 MAX31855 Breakout Boards on a ChipKIT UNO32
const int CH1 = 4; // Channel 1 CS
const int CH2 = 5; // Channel 2 CS
const int mDataPin = 6; // SO
const int mClockPin = 7; // SCK
void setup() {
Serial.begin(9600);
pinMode(CH1, OUTPUT); //CS is an Output
pinMode(CH2, OUTPUT); //CS is an Output
pinMode(mDataPin, INPUT); //SO is an Input
pinMode(mClockPin, OUTPUT); //SCK is an Output
digitalWrite(CH1, 1);
digitalWrite(CH2, 1);
digitalWrite(mClockPin, 0);
}
void loop ()
{
// Output temperature from the two boards in the format of: [CH1],[CH2]\n
// Example: 123.45,678.90\n
Serial.print(getTemp(CH1));
Serial.print(",");
Serial.print(getTemp(CH2));
Serial.print("\n");
delay(1000); // Delay 1 seconds, so we get new readings sent to the terminal once per second
}
float getTemp(int ch)
{
unsigned long value = 0;
float temp = 0;
char bita;
digitalWrite(ch, 0);
for (int i = 0; i < 32; i++) //Get 32 bits from the MAX31855 - see datasheet for specifics.
{
digitalWrite(mClockPin, 1); //set clock pin low
bita = digitalRead(mDataPin);
if (bita==1) value = value | 1; // If bit ==1 set lowest bit in value
digitalWrite(mClockPin, 0);
if (i != 31) value = value << 1;// If we're not done yet, shift bits left by 1 to make room for next loop
}
digitalWrite(ch, 1);
value = value >> 18; //shift out all but tc temp data and sign bit
temp = (((value * 0.25) * 9) / 5) + 32; //Convert to Degrees F
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment