SPI problem with Thermocouple Shield

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
hardy59
Posts: 3
Joined: Sat May 12, 2012 7:13 pm

SPI problem with Thermocouple Shield

Post by hardy59 » Sat May 12, 2012 9:09 pm

Hi !
I fail to operate an Arduino thermocouple shield (by McLEng, s.b.) with my EtherTen, but only when using the ethernet library!
To me it looks like an SPI conflict/problem, but I am not an expert with neither Arduino nor SPI.

When the ethernet code in my sketch is commented out, the system runs nicely and prints correct temperature readouts to the serial console.

When the ethernet code is active, everything else works nicely (DHCP and the web server too), only the readouts of the thermo shield are wrong (always 0°C). However, the function call MAX31855::read(...) for reading the temperature does not return an error (only false, more precisely null values for the temperature).

I hoped to avoid SPI trouble by using the EtherTen instead of an Arduino/Ethernet-shield stack, which is know for its SPI bug.

Any hint or advice is appreciated very much!

Cheers,
Hardy

PS: This is the link to the thermocouple shield: http://ryanjmclaughlin.com/wiki/Arduino ... ple_Shield

PPS: I changed the CS pin for the thermocouple shield to digital #5 (with hard- and software).

User avatar
jonoxer
Freetronics Staff
Freetronics Staff
Posts: 298
Joined: Sat Oct 15, 2011 11:31 am
Location: Melbourne, Australia
Contact:

Re: SPI problem with Thermocouple Shield

Post by jonoxer » Sun May 13, 2012 10:28 am

I haven't tried that hardware myself (I don't have that shield or a MAX6675) but it looks to me like there may be a problem combining the driver library with the Ethernet library - or anything else that uses SPI, actually.

The datasheet for the MAX6675 says that it implements a "Simple SPI-Compatible Serial Interface", which to me suggests that it's a partial implementation of SPI but not a full one. For example, it doesn't use MOSI at all, only MISO, so communications with the MAX6675 are read-only. Basically, you enable the chip using the CS (Chip Select) line and it just starts spitting data at you. It *looks* like the intention is that it can share a bus with real SPI devices, so I assume that if you de-assert CS it'll shut up and leave the bus for other devices to communicate.

There are two driver libraries I've seen so far, and neither of them use the Arduino SPI features: they directly manipulate the pins.

So my assumption (not having tested it, as I mentioned) is that the MAX6675 library is stomping on pins used by the SPI library and vice versa because they don't know about each other. Getting them to work together may not be that easy.

Which library are you using? The ones I've seen so far are:

https://github.com/ryanjmclaughlin/MAX6675-Library
https://github.com/adafruit/MAX6675-library
--
Jon

cef
Freetronics Staff
Freetronics Staff
Posts: 106
Joined: Wed Nov 09, 2011 12:53 am

Re: SPI problem with Thermocouple Shield

Post by cef » Sun May 13, 2012 1:11 pm

Something of note here:

One of the 3D printer electronics designs (RAMPS) allows for the use of an SD card and a Max 6675 on the same SPI interface. I haven't looked at any of the actual code in use for it (Marlin or Sprinter firmware specifically). Might also be worth a look thru that code if you're after inspiration.

Note: RAMPS is designed for a Mega layout, so the pins will of course be different.

hardy59
Posts: 3
Joined: Sat May 12, 2012 7:13 pm

Re: SPI problem with Thermocouple Shield

Post by hardy59 » Sun May 13, 2012 1:27 pm

@jonoxer
Thanks for looking into that and for giving advice!

Actually I am using the MAX31855 library by Ryan McLaughlin et. al., but this won't make a big difference I believe. Here is the link: https://github.com/ryanjmclaughlin/MAX31855_Library. Since v2.0 of his thermocouple shields, Ryan changed from MAX6675 to MAX31855.

When I look into the code, I don't see any reference to the Arduino SPI library (which I guess would be easy to identify by an "#include <SPI.h>"). The CS line is always manipulated directly with digitalWrite(CSPIN, HIGH/LOW).
On the other hand the Arduino ethernet library seems to stick to the "standard" and does make use of the SPI library (at least I found the aforementioned include statement in the W5100.h).

You must be absolutely right with your assumptions!
I would guess that if the MAX31855 library could be rewritten so that it would use the Arduino SPI library instead of directly manipulating the lines, both libs would cooperate nicely.

Hardy

hardy59
Posts: 3
Joined: Sat May 12, 2012 7:13 pm

Re: SPI problem with Thermocouple Shield

Post by hardy59 » Sun May 13, 2012 9:39 pm

@cef
That's good to know, thanks for that inspiration!
- Hardy

Post Reply