xpt2046 + max6675 sharing SPI on a pi

216 views
Skip to first unread message

Marc Brevoort

unread,
Feb 7, 2017, 4:42:16 PM2/7/17
to Reading Hackspace
Hi,

So I've hooked up an XPT2046 touch screen to the raspberry pi and that works.
Video over HDMI, touch screen over SPI.

Before that I had a Max6675 hooked up to the SPI bus and that, too, worked like a charm.
An SPI bus can be shared by multiple devices so I thought I'd hook them up together.

As the pins of the pi are occupied by the touch screen, I've soldered pin headers
to the extension pads on the back of the display and I thought I'd hook them up together.
By the documentation the touch screen uses SPI 1 and so the thermocouple is on SPI 0.

The touch screen works beautifully as long as I don't hook up the MISO data pin of the
thermocouple. With the thermocouple hooked up it's jittering cursors galore.

I've tried either CS, neither work.

Measured the solder joints, they seem fine. Hooked the whole thing up to a scope.
Surprisingly I saw no clock on the SPI bus unless the touchscreen was touched.
There's an IRQ pin in use so I'm guessing the way it works is touch screen
touched -> IRQ sent -> SPI read from screen.

No matter what I do these two devices just don't seem to play nice with each
other. Just about running out of ideas, anything obvious I'm missing?

I probably have the option of hooking up the thermocouple to different GPIO pins,
but bitbanging seems a bit fussy and unelegant so I'd prefer to solve this the way
"nature" intended.

Best,
Marc

Ryan .

unread,
Feb 7, 2017, 4:43:32 PM2/7/17
to reading-...@googlegroups.com
Can you post up a complere wiring diagram and your code/config's?

--
You received this message because you are subscribed to the Google Groups "Reading Hackspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reading-hackspace+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Ibbotson

unread,
Feb 7, 2017, 6:56:59 PM2/7/17
to Reading Hackspace
Both devices should be able to co-exist on the SPI bus. The enable of the MISO does appear from datasheets to be controlled by the CS for both devices, so if your wiring is correct you should be able to select either, but most likely both is possible too.
I am more concerned with the software structure. Do both devices go through a common device driver which ensures that both devices are not CS at the same time in different threads? If you just bang out the CS for the MAX6675 without regard for an interrupt which might use the SPI bus and assert the other CS, then I expect problems.

Marc Brevoort

unread,
Feb 9, 2017, 2:27:15 AM2/9/17
to Reading Hackspace
The device drivers are independent of each other. However I have now established that the max6675 keeps spitting out data and seems to ignore the chip select pin altogether. This goes against the data sheet, so it might be a fake. So I guess I'll hook up the thermocouple to GPIO so it is fully isolated from the touch screen.

Ryan .

unread,
Feb 9, 2017, 10:35:45 AM2/9/17
to reading-...@googlegroups.com
So, you've put a scope on CS, CLK and MISO, and when CS is High, MISO still wiggles when it clocks?

On Thu, Feb 9, 2017 at 7:27 AM, Marc Brevoort <klei...@gmail.com> wrote:
The device drivers are independent of each other. However I have now established that the max6675 keeps spitting out data and seems to ignore the chip select pin altogether. This goes against the data sheet, so it might be a fake. So I guess I'll hook up the thermocouple to GPIO so it is fully isolated from the touch screen.

Marc Brevoort

unread,
Feb 11, 2017, 6:35:27 AM2/11/17
to Reading Hackspace
On Thursday, 9 February 2017 15:35:45 UTC, Ryan wrote:
So, you've put a scope on CS, CLK and MISO, and when CS is High, MISO still wiggles when it clocks?

I haven't put a scope on all three pins at the same time. Figured it wouldn't make sense for the SPI interface to have more than one ~CS enabled at the same time at any given time.

But I think I found the problem - Noise.

Right now I have hooked the MAX6675 up to three free GPIO pins, separate from the SPI interface, and bitbang to read the temperature. Initially the temperatures sent back were highly erratic (10.5C, 32.75C, 16.25C,...) indicating a noise issue. By coincidence I found out that when I tried measuring what was going on, the temperature readings went stable as soon as I connected the ground lead of my scope to the ground pin, so I clearly had a noise problem. This could also explain the poor behaviour on the SPI interface.

I went through the MAX6675 datasheet once again, which suggested a 0.1uF cap between the thermocouple leads, but this showed no significant improvement.

It also stated that pin T- had to be grounded, so I tried a wire bridge between T- and the ground pin of the tiny thermocouple breakout board (perhaps 2 cm away) and to my surprise the readings stabilised - I'd have expected the board layout itself would already catered for this. In any case I've soldered a short wire in place, which has much improved things. All of a sudden I have usable readings once again, and in addition I've learned how to use the GPIO pins - which is knowledge that'll come in handy in the near future.

Best,
Marc









20170211_112624-1.jpg
Reply all
Reply to author
Forward
0 new messages