SPI on two Wires (a la TC77)

Hello all,

I was wondering about mixing two wire SPI devices with three wire devices. I've never used a SPI device that handles both data in and out with the same wire. Is there any thing I should be aware of when combining both types of devices on the same bus? This will be interfaced with a PIC MCU.

Thanks,

John

Reply to
jecottrell65
Loading thread data ...

It powers up in run mode, so you can just use it as a read-only device (chip select, bang out the 13 temperature bits, deselect) and ignore the shutdown and id commands. Looks just like an LM71 in that respect, except that the LM71 has 14 temperature bits.

I consider that to be a 3-wire (read-only) interface: cs, clock, data.

Here's my LM71 code, 68K assembly:

.SBTTL . RTEMP : READ THE LM71 TEMP SENSOR

; WE READ 14 BITS FROM THE LM71, INTO D4 13:0, AND SIGN-EXTEND ; BIT 13 INTO 15:14. THE RESULT IS A 2'S COMP TEMPERATURE IN ; DEGREES C * 32, WHICH WE THEN SCALE TO DEGC * 10

; PORT D BITS ARE B5 LM71 CS- PIN 70 ; B2 SCLOCK PIN 67 ; B0 SDIN PIN 65

RTEMP: MOVEM.L D1 D4 D5 D7 A0, -(SP) ; SAVE GOODIES

MOVEA.W # PORTD, A0 ; NAVIGATE TO PORT, MATEY MOVE.W # 2, D1 ; NAME THE SPI CLOCK BIT BCLR.B D1, (A0) ; AND MAKE SURE CLOCK LINE IS LOW.

BCLR.B # 5, (A0) ; CHIP SELECT THE NASTY LITTLE BEAST

CLR.L D4 ; NUKE FUTURE DATA MOVE.W # 14-1, D7 ; NEED A BIT COUNTER, TOO

LMOP: MOVE.B (A0), D5 ; READ THE PORT AND SHIFT RIGHT 1 BIT LSR.B # 1, D5 ; WHICH PUTS SERIAL DATA INTO X-BIT ROXL.W # 1, D4 ; SHIFT THAT INTO DATA REG

BSET.B D1, (A0) ; PUMP CLOCK UP BCLR.B D1, (A0) ; AND DOWN.

DBF D7, LMOP ; - DO 14 BITS -

BSET.B # 5, (A0) ; CHIP DESELECT

BTST.L # 13, D4 ; WAS SIGN BIT SET? BEQ.S TSCAT ; NO, GO SCALE ORI.W # B15+B14, D4 ; YES, SIGN EXTEND

; NOW FRACTIONAL MULTIPLY D4 BY 10/32 TO GET DEGS C * 10

K10 = 20480 ; 10/32, AS A FRACTIONAL

TSCAT: MULS.W # K10, D4 ; DO MULT SWAP.W D4 ; AND MAKE THAT FRACTIONAL MOVE.W D4, TEMPC.W ; AND STASH IN RAM

MOVEM.L (SP)+, D1 D4 D5 D7 A0 ; UNSAVE GOODIES RTS

John

Reply to
John Larkin

John,

Thanks for the reply and the info. Your reply allows me to put my question into perspective and maybe clarify it a bit.

I'm assuming that there is no chance of bad things (or confusion) happening on the SPI bus to other hardware as long as they are not chip selected? And I assume that the TC77 data pin should probably go to the SDI pin on the PIC since it is 'mostly' a read only device?

Thanks also for the code... unfortunately my limited cognitive ability reduces me to using C. I have looked for reference material to start learning the basics of ASM but haven't had much luck... could you recommend something in the reading department?

John

Reply to
jecottrell65

Right. If a chip isn't selected, it's off the bus and its data lines won't interfere with any others. So just connect the data pin of the TC77 to the serial input pin of your uP.

I program embedded stuff in assembly because I like it, but C is probably a better choice for most people. The chip manufacturer should have the basic appnotes on the chip architecture and instruction set, and there are lots of supplementary books around, from Amazon and Opamp and Powell's and such. It is useful to know the machine codes even if you program in C, so you can "see through" the compiler and have an idea of what it compiles effciently and what it doesn't. I'm just now doing a product that can time out 10 seconds to 1 picosecond resolution, so I'm doing a lot of 64-bit math, and doing that fast is something a compiler might not be good at. I'm doing a 64x32 fractional multiply in a couple of microseconds, and I can imagine some C library taking a hundred times as long.

Some machines are dogs to program in assembly, and that includes the x86 and PIC architectures.

John

Reply to
John Larkin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.