Electronic – in SPI, can MOSI and MISO be connected together

bidirectionaldatainputmicrocontrolleroutput

I'm using an 8051 series microcontroller, and documentation states that if I use serial mode 0, then its RXD pin can function as a bi-directional pin (both input and output) while TXD is strictly a clock.

I have an IC which have MOSI, MISO and clock pins. and I also use multiplexer/demultiplexer IC's as well.

I want to take advantage of the microcontroller RXD pin so I don't have to do alot of CPU time-wasting bit-banging routines for each device I want to control.

So is it acceptable to connect MOSI, MISO, and RXD pins together or should there be a resistor somewhere?

And Is it safe to connect an output of a demultiplexer (Example: 74hc151) to the 8051's RXD pin and to an input of a decoder (Example: 74HC138) or should I use resistors?

If resistors are required, what values would you suggest and why?

Best Answer

The answer is "it depends".

If your SPI slave tri-states its MISO pin when it isn't transmitting then there is no harm in connecting MISO and MOSI to an MCU that supports this feature. Whether the SPI slave does this or not should be spelled out in the device's datasheet but if it isn't, you can figure it out on your own:

  • leave the MISO line disconnected from the MCU
  • connect the MISO line to two resistors, one to +V and one to GND
  • the actual value of the resistors doesn't matter. They should have the same value, and any value between 1k and 10k would be fine for this experiment.
  • connect one channel of an oscilloscope to the MISO line, and another channel to the MOSI or CS# line.

Now have your MCU perform a normal SPI transaction with the device, one that the device would respond to. What you are looking for is the MISO signal level while the MCU is transmitting to the device. Due to the resistor bias network the MISO line should be sitting at approximately 1/2 the supply level. It may be slightly more or less depending on the device and the tolerance of your resistors, but you should see something not +V and not GND if the device is tri-stating its MISO line.

If the MISO line is at one of the rails and then starts toggling when the device responds then the device is not a good candidate for combining MISO and MOSI lines. This is because the device is actively driving the MISO line when it's not talking. This isn't wrong because SPI is a full-duplex communications system and each direction has it's own physical signal. The device expects to be the only driving element on that net so it's doing the right thing by maintaining a signal level.

If, however, the MISO line more or less sits halfway between the rails and then only toggles to the rails when it's sending its response then this device is capable of having its MISO and MOSI lines tied together. The datasheet may mention that a pull-up or pull-down resistor should be used on the MISO line, which is another hint that this is a device capable of tying the MISO and MOSI lines together.

Now to address something you've said:

I want to take advantage of the microcontroller RXD pin so I don't have to do alot of CPU time-wasting bit-banging routines for each device I want to control.

I recognize that you're using an 8051 but even then it's difficult to believe that your MCU will be doing much while the SPI transaction is active. Unless you're transmitting massive blocks of data, your SPI peripheral is dog-slow or your particular 8051 has an amazing serial port then you will likely have very little time between bytes to do anything. Even the fastest 8051s clock at about 50MHz, which is right around the maximum SPI clock frequency for most SPI slaves as well. Even if your specific 8051 is able of executing an instruction per clock you won't be getting more than 8-48 instructions per byte transferred over SPI (assuming your SPI port is operating at 6-50MHz). You are unlikely to save a lot of time or power by using the peripheral.

Related Topic