SPI Info

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Freaks,

I havn't used SPI before, so correct me if i'm wrong. Ther are two (or more) devices, with a single master, and several slaves. An individual slave is selected via the /CS pin (enabling it), before the master sends the data.

Now, the part I want to know: As far as I know, the slave cannot send data to the master directly - it has to have its data "shifted out" by sending data to it from the master - so to recieve from the slave, the master has to send somthing.

If this is true, how does the device process the input before sending it's output - if the shift registers were directly linked, woudn't there be no time to process? Also, is there any way to send a "request for information" signal from the master at set intervals so it can both send and recieve information?

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Dean,

In most cases the Master send some kind of start byte to the slave. that can be a command or something. The command can be a data request,. To this first byte the slave responds with a byte ( a status byte or 0xFF, ...). Next the master shifts out a second byte and now the slave transmits the requested data.

I'll try to explain with a simple time chart:

      ____                                             ____
/SS :     \-------------------------------------//----/

MOSI: ------[ CMD ] --------------[ 0xFF ] -----//---------
  
MISO: -------[ Status ] ----------- [ Data ]----//---------


Hope that helps.

Hava a look at my web page -> http://www.tobiscorner.at.tf

Last Edited: Sat. Jul 10, 2004 - 10:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A slave can only respond to a command from the master via the SPI bus.

But if it's possible with your devices (e.g. with 2 micro's) you can use an extra signal from the slave to the master which generates an interrupt on the master device, which will then 'ask' the slave what it wants to tell.

Else you have to ask the slave frequently if it wants to tell you something.

SPI is mostly used for devices which does not have to do anything by them selves, only respond to a request, like sensors and memory.
That's why they don't have such a functionality built in.

If it's possible you may consider using I2C instead.
With this protocol a slave can also ask the master something, and it does not require a slave select line.
But I suppose the device you're using only has SPI :(

Hope this helps.

For more info abut SPI: http://www.embedded.com/story/OE...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SPI slave devices come in a wide variety so you need to look at the data sheet of each one to determine how best to operate it. Normally communication with a SPI slave starts with the master shifting out a series of bits where the first few bits define the command to be performed. For example, with a serial EEPROM a read consists of the read instruction followed by the address that is to be read. There is a small bit of time for the slave to decode the address and make the data available, but compared to the overall timing of the SPI transaction, the slave can make the data available in the bit time following the last bit of the address. Other devices can be more complex. For example, the MAX3100 (a SPI based UART) can generate an interrupt when it has received data over the serial line or when it is ready to transmit another byte of data. It's also a 16 bit device which means that you have to enable the chip select, do two 8 bit SPI operations back to back and then disable the chip select. The first thing that needs to be done is to do a read to find why it generated the interrupt. This means writing two dummy bytes to the device to pump out the 16 bit status and data register (writing two bytes of zero tells the device to only do a read). Once you know the status you know if new data has come in over the serial line (which was also embedded in the read data) or if the device is ready to transmit another byte of data, in which case you can follow up with another SPI operation that transmits the data.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the spi devices are all 'output devices' like d/a converters or latches or something, no problem... just need a separate cs for each one.... BUT.... when the devices are 'input devices' like a/d converters and LS165 shift registers used for reading inputs, etc, then the MISO lines from each device must be dealt with... you cant wire or them all togethrer unless the cs to that device makes its MISO go hi impedance. The fix is to run the MISO thru an LS126 that is enabled by the CS to that device.....

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wanted to know for my "Laser Challenge" project (see projects forum). I'm looking for a two-way communication using only 4 wires (including power and ground).

My AVR has hardware SPI, plus software I2C - neither of which fits my requirements. I was thinking some sort of RS-485, but have a bridge rectifier connected to the two data lines to pull DC voltage to power the gun device. would this work? It'd be a great true two-wire communication system.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

abcminiuser wrote:
I wanted to know for my "Laser Challenge" project (see projects forum). I'm looking for a two-way communication using only 4 wires (including power and ground).

I haven't really followed the Laser Challenge thread but since you mention 4 wires including power and ground, how about USB? If you have a UART available on your AVR, there are some relatively inexpensive chips that will that speak UART on one end and USB on the other. There is another thread on USB chips going on right now.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It has to be communication between the master micro in the suit, and the micro in the gun. I need a 4-wire comm because I'd like to use a 1m "curly cord" like in telephone handsets to prevent the gun-suit linking wire from getting in the way.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, that would be +5, ground, and the twi/i2c..... thats bidirectional and everything... how come you dont want to use that again?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RS-485 is normally just 2 wires, for half duples operation. with the line turned around for replies. Thus Power+ Ground + 2 wires for 485 = 4 wires total. :D

Laurence Boyd II

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just go with a 2 wire RS-232 using the UART. 5V, Gnd, TX, RX, easy as it gets. If you want to try and save a couple bucks and your distances are short, you could get away without the RS-232 part (the voltage level converter chips) and go with straight UART to UART. Dont worry about any of the flow control lines, you can just build it into your protocol if you really need it.

Vern

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree that use UART directly when the distance is not too long.
Now I am working on SPI communiction between two MCU (master is a 16bit MCU and salve is MEGA16). i decide to use the following policy:
Master initialize slave by driving /SS low,send data package,wait a certain time for slave to process command data and prepare replay data,
master send several 0xff(idle byte) to give slave clock, drive /ss high when complete.
There are 2 questions i am not sure:
1.when does MEGA16 write relay datas into SPDR?
2.Could the /SS line be always connected to GND to save one i/o port of master?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suppose you mean the /CS pin.
Yes, that one can be always grounded.

JP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
There are 2 questions i am not sure:
1.when does MEGA16 write relay datas into SPDR?
2.Could the /SS line be always connected to GND to save one i/o port of master?

ad 1: After it gets the command to do so.
ad 2: If you only have 1 device connected to the SPI bus, /SS can be driven low all the time.

Hava a look at my web page -> http://www.tobiscorner.at.tf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm, about bidirectional SPI, have a look at this:

https://www.avrfreaks.net/Tools/s...

Maybe you can use it.

JP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops, it uses an extra line.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might want to ask yourself some questions.

- what will be the needed data speed? This depends upon the protocol and the amount of communication you want to do, as well as the required reaction time.

- What do you want the protocol to do? half duplex/ full duplex? Polling or interrupt?

- if you know all those things you are probably able to rule out some options.

Personally I like RS422 as it is robust and simple, but this needs 6 wires (2 pairs of data and power). You can also do RS485 (half duplex RS422). Very nice and not too difficult.

Maybe you can also get away with just liking the micros without the interface chip. But if one of both units is detachable you might get ESD problems.