Long Distance SPI

From Electriki
Revision as of 20:18, 23 May 2011 by Domen (talk | contribs) (talk long distance to me, baby!)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Schematic for the project
TMP124 and RS422 transceiver
signals travelled through this cable
SCK when it comes back to 3.3V levels, perfect

The problem

I wanted to have a temperature sensor on 20m of cable (powered through the same cable too), and, well... that's around the limit for RS232. Ethernet could do it, but then you need a smart sensor. Or RS4xx could also do it, but uart sensors are not really common, and I wanted to avoid extra MCU on sensor side. Direct I2C or SPI was just out of the question. Those busses usually work in <1m range.

Philips makes I2C extenders, so that would be a possibility, except they're quite expensive.

As far as I read, the RS422/RS485 transceivers don't actually do anything else than to transform "normal" signals to differential, so the idea poped to mind, "why not just use RS422 transceivers to handle long distance SPI?".

Solution

I decided to test this idea. I picked TMP124 SPI temperature sensor, because I had it here, and it only needs SCK and MISO for communication.

The RS422 transceiver was sn65hvd30, from TI, because they sent free samples, fast. :-)

Slave select line didn't have any special handling, only a small capacitor against ground to make it nicer (it had <0.5V of noise before that, so it should work anyways).

I put a nice 100uF capacitor on power lines, since otherwise the chips sucked enough power for Vcc to drop below 2V for a bit, and tmp124 didn't really agree to those conditions.

Notes

RS422 is limited by speed and distance. A simple rule: speed*distance < 1e8 MHz*m.

On 150m of cable, SCK will arrive at sensor delayed by >0.5us (150m/c), and then MISO for another >0.5us. This means that with 1MHz clock, the MISO on MCU would be delayed by more than one clock cycle (and this is in fact the value I got, temperature divided by two!). With a synchronous bus, you really don't have much of a choice, so I lowered clock to 100kHz, which works perfectly.

Domen 20:18, 23 May 2011 (UTC)