SPI vs USI

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

Hi all

Just going through the range trying to choose the most appropriate AVR (8 bit) for a new design. I have a requirement for SPI to communicate with another device. I'm thinking of the Tiny24. Is there a difference between SPI and USI? I know it says the USI is compatible with SPI mode 0 and 1. Is there anything I should be looking out for? I've only used other AVRs with dedicated SPI ports (at far as comms go).

My app requires 1 x SPI, 4 x I/Os, 1 x timer, 3 x ADC, and not much memory.

Cheers - Matt

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

Quote:
Is there a difference between SPI and USI?.
USI is just a bit better than bit banged SPI. But it can be pressed into service.
Bit banged SPI is pretty easy too.

Anything with a real SPI starts with a Mega48 unfortunately.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
Anything with a real SPI starts with a Mega48 unfortunately.

The Tiny261 (and 461/861) seem to have a "real SPI" according to the atmel parametric product table, while the other tiny's have a USI. However the 261 datasheet lists it as a USI.

Slightly confusing, but I am going to assume that the 261 will work in SPI mode for me. Nothing in the datasheet seems to suggest otherwise.

Matt

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

Go with the data sheet, the ATtiny261 does not have a SPI module and it does have a USI module. The USI requires software in order to act like a SPI.

AVR319: Using the USI module for SPI communication:

http://www.atmel.com/dyn/resourc...

http://www.atmel.com/dyn/resourc...

There are other USI possibilities like a UART or I2C listed on the applications page:

http://www.atmel.com/dyn/product...

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

Thanks guys, I think I have it worked out now (at least until I physically try it!).

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

The simulator in AVR Studio 4 Rev 4.14 still has no support for the USI port.

Basically you make it into an SPI by writing a loop to shift out the bits or unrolling the loop into a linear stream to shift out the bits. The code is in the datasheets for the ATtiny24 and the ATtiny261. Check it out.

The reason they did this is so the same hardwar can do I2C as well. Pretty clever actually.

I don't know if a USI implementing a slave device can get its data into the appropriate register before the shift clocks come in from the master. I have a TEAC transport where the master waits for an acknowledge to SS*(Slave Select) before sending the first byte. I think this is kind of essential for implementing a slave device.

We never have time to do it right,
but we always have time to do it over

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

I hope this is the appropriate thread to ask about using the Tiny261 as an 8 bit slave SPI port.

These parts seem to me to be inexpensive, available in DIP, can sense if any of the 8 bits on port A change and only then read the port, decode the data, generate an output to be used as an interrupt to be used by the SPI master (ATmega8535), and send data to it.

What I wonder about is can several slaves be connected at the same time? I did not find the equivalent of an SPI slave chip enable on the Tiny261. How can it be made to not pay attention to data intended for another slave?

Luckily, I just want to read the ports. I still wonder if more than one Tiny261 could be used as a bi-directional port.

John

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

App note AVR319 says:

Quote:
The USI Three-wire mode is compliant with the Serial Peripheral Interface (SPI) mode 0 and 1, but does not have the slave select (SS) pin functionality. However, this feature can be implemented in software if necessary.

So it looks like it's up to you to implement it - which presumably means keeping the pins tristated with USI disabled until the line you have picked to be _SS is seen to go low.

Cliff

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

Thanks Cliff. I missed the app note.

John

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

Quote:

These parts seem to me to be inexpensive, available in DIP, can sense if any of the 8 bits on port A change and only then read the port, decode the data, generate an output to be used as an interrupt to be used by the SPI master (ATmega8535), and send data to it.

Devil's advocate: It sounds like an awful lot of trouble and complexity to go through, versus just having the "main" processor read a port.

Also, from your description you will have an extra line to tell the "master" that new data is ready. Why not make the '8535 the SPI slave in that case?

How fast/often are these inputs changing? (are these user inputs such as switches?) How fast does the reaction time need to be?

I'm leading up to polling & debouncing on the '8535 if the objection is that there are no pin-change interrupts on that model. Another obvious step is to use a Mega164 instead which will have pin-change interrupts.

The described system is not going to have an "instant" response, anyway.

If at all critical, I'd feel a lot better about reading the data directly. Or at least send the data byte, and then a checksum or inverted byte to check for integrity.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Can someone tell me precisely how to implement the SS functionality in an ATtiny2313 configured as a slave for SPI communication protocol. My project needs a single master multiple slave communication protocol. I know it can be done in hardware pretty easily but I wanted to know how it can be done in software.

Bittu Sarkar
Dept. of Computer Science & Engg.
Indian Institute of Technology, Kharagpur

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

Quote:
how to implement the SS functionality
The 2313 does NOT have an SPI and therefore no /SS.

Please start another thread specific to your problem.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly