Hardware Reference
In-Depth Information
4
5 void setup()
6 {
7 Serial.begin(9600);
8
9 // Initialize the bus for a device on pin 10
10 SPI.begin(slaveSelectPin);
11 }
12
13 void loop()
14 {
15 // Read in 4 bytes of data
16 byte data1 = SPI.transfer(slaveSelectPin, 0, SPI_CONTINUE);
17 byte data2 = SPI.transfer(slaveSelectPin, 0, SPI_CONTINUE);
18 byte data3 = SPI.transfer(slaveSelectPin, 0, SPI_CONTINUE);
19 byte data4 = SPI.transfer(slaveSelectPin, 0, SPI_LAST); // Stop
20
21 // Create two 16-bit variables
22 word temp1 = word(data1, data2);
23 word temp2 = word(data3, data4);
24
25 // Is the reading negative?
26 bool neg = false;
27 if (temp1 & 0x8000)
28 {
29 neg = true;
30 }
31
32 // Is the MAX31855 reporting an error?
33 if (temp1 & 0x1)
34 {
35 Serial.println("Thermocouple error!");
36 if (temp2 & 0x1)
37 Serial.println("Open circuit");
38 if (temp2 & 0x2)
39 Serial.println("VCC Short");
40 if (temp2 & 0x4)
41 Serial.println("GND short");
42 }
43
44 // Keep only the bits that interest us
45 temp1 &= 0x7FFC;
46
47 // Shift the data
48 temp1 >>= 2;
49
50 // Create a celcius variable, the value of the thermocouple temp
51 double celsius = temp1;
52
53 // The thermocouple returns values in 0.25 degrees celsius
continues
Search WWH ::




Custom Search