3 wire SPI interface

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3 wire SPI interface

5,818 Views
FC
Contributor III
Hi,
 
For the QG8, can you setup a 3 wire SPI (bidirectional data) similiar to  MICROWIRE? 
 
 
Labels (1)
0 Kudos
8 Replies

1,305 Views
peg
Senior Contributor IV

Hi FC,

Microwire (TM National Semiconductor) depending on the flavour is either one of two of the four modes available to SPI (TM Motorola Semiconductor).

So a Microwire peripheral will always work on an SPI port but a SPI peripheral may not work on a Microwire port.

Most parts these days (especially from Maxim) claim to be compatible with both.

Regards David

 

0 Kudos

1,305 Views
FC
Contributor III

For example,

Trying to setup an interface to the Maxim DS1302 RTC.  How would the bidirectional data be handled using the 9S08QG8 SPI?   

0 Kudos

1,305 Views
peg
Senior Contributor IV

Hi FC,

I think you might be able to use mode 0,0.

The main problem is that you need to flip direction exactly at the last SCK edge, because this same edge would start the reply from the 1302. Maybe you could time the direction from the start of the transfer and flip it slightly early.

You might be able to use the SPI after some experimentation or like rocco said just bit bang it.

Regards David

 

0 Kudos

1,305 Views
rocco
Senior Contributor II
Also, have you looked at the DS1306?

It is a similar part, but the non-standard 3-wire interface of the DS1302 is replaced with an SPI interface. Plug-n-play.
0 Kudos

1,305 Views
rocco
Senior Contributor II
Hi, FC:

I don't think you can use the SPI to talk to the DS1302. The protocol of the DS1302 is just too different.

The main issue that I see is with a read from the DS1302. When you issue a command to read, the eighth bit of the command is clocked in by the rising edge of the eight clock, but the first bit of the returned data is presented at the falling edge of that same clock. This means:

1) A read would take 15 clocks, instead of the 16 clocks that the SPI would generate.
2) The DS1302 would drive the data line before the SPI was finished driving the line, with the potential of destroying either part.
3) Any byte that you did read would by spread across two SPI transfers, shifted by one bit.

I think that the best way to communicate with the DS1302 would be to bit-bang it, like we have been doing for the I2C parts over the years.
0 Kudos

1,305 Views
bigmac
Specialist III

Hello,

It would seem possible to use the SPI facility for the DS1302, provided CPHA = 0 (and CPOL = 0). In the Dallas data sheet, it would appear that fig 3 for the single byte read may have an error with only 15 clock pulse shown - there would need to be a sixteenth clock for the MCU master to read the LS bit of the returned byte on its positive  edge, and this would be compatible with SPI.

For the CPHA = 0 operation, the MS bit of the returned data needs to be valid on the positive edge of the ninth clock pulse, so the data becoming output on the negative edge of the eighth clock pulse is correct.  To avoid the timing issues during the input-to-output transition of the data line at the DS1302 (a conflict might be present for a very short interval) I would suggest to include a series resistor in the line, say 4k7, to provide current limiting.

For MCU operation with a single data line (MOSI becomes MOMI),
SPIC2_SPCO = 1;

Prior to the command byte being sent,
SPIC2_BIDIROE = 1;  // For data output from MCU

Prior to receiving the return data byte (by sending a dummy byte),
SPIC2_BIDIROE = 0;  // For data input to MCU

Regards,
Mac

 

0 Kudos

1,305 Views
rocco
Senior Contributor II

bigmac wrote:
In the Dallas data sheet, it would appear that fig 3 for the single byte read may have an error with only 15 clock pulse shown . . .
Hi, Mac:
That's what I thought when I first saw it, but after reading the text and examining the timing diagrams, I realized it was correct. It really is a silly protocol, using only 15 clocks. But it makes for quick and easy bit-banging.

The series resistor is a good idea. Because of the obvious contention period, I did not check if it whether it would work with CPHA = 0.

But I still think the best approach is to use the SPI version, DS1306.
0 Kudos

1,305 Views
peg
Senior Contributor IV

Hi,

Of course unless the OP has a big box of 1302's gathering dust this is all academic.

You could use open-collector buffers as well!

I think you loose burst mode too with this 15 clocks business (or too messy if you can)

Another idea:

The OP is using QG8, it has I2C, so the DS1307 is possibly a better choice as you don't need the extra pin as with the SPI 1306.

Regards David

 

0 Kudos