Quick SPI Question on Attiny104

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

Hey everyone,

 

I am thinking about trying to use an Attiny817 as a master and an Attiny104 as a slave as a first-time SPI exercise.

The Attiny104's datasheet seems to indicate that there is no slave select pin for the 104. Does this mean that it is always regarded as the selected slave and I'd only have to connect the power, MISO, MOSI, and CLK wires?

 

Thanks for the help.

 

Here is a link to the 104's datasheet:

http://www.mouser.com/pdfdocs/At...

 

and here are some screenshots from that datasheet for more information:

 

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

It looks to me like the  Tiny104 has no hardware SPI except for UART in SPI mode. You will still need an SS, just implement its operation in software.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

ka7ehk

Hi Jim,

 

Thanks for the response.

What exactly is UART in SPI mode?

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

What exactly is UART in SPI mode?

You may need just to read up on that, section "16. USARTSPI - USART in SPI Mode" wink
 

It will also tell if the "Attiny104 as a slave" is possible in hardware.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Daisy, i think you're jumping ahead too much. If your idea is to use spi to connect a number of slaves to one master, then you need to consider how you achieve this. Say you have 8 slaves generating 4000 bytes per second. How do you propose to talk to these 8 devices in a reasonable time frame? How will you detect and cope with errors? Will you need to buffer the data in the slaves?
I suggest you get a pencil and paper and start sketching out the timing diagram. From that you'll get some numbers that should allow you to determine if you need to buffer the data and how much. That gives you an idea of the ram involved and this can influence your choice of microcontroller. Choosing the micro first then working backwards can push you into a corner.
Also consider hardware constraints - how long are the interconnecting wires going to be? Will the capacitance of the wiring limit my maximum speed?
What happens if a wire breaks or a slave fails? How will you detect this? What will you do when it happens? Blindly ignore it and have the system go stupid or decide if it is critical and safely shut down flagging an error?

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

Have you thaught of TWI?I2C (only 2 wires, being less likely to break; SPI needs a Slave Select wire per slave; wires can be slightly longer than with SPI) can be reasonably fast....

 

Edited : does your boss tell you which part should be bought/ preexist?

Last Edited: Thu. Jun 15, 2017 - 08:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My two cents - implementing slave side SPI can be a real pig, so start off with just the master side SPI and simply work with another device that uses SPI. Something like an ADC/ DAC/ some device that does something and uses an SPI interface to do that something.

The trouble with doing both slave and master at the time is that when you run into problems you don't know if it's the master or slave that's causing the problem. By working with a dedicated slave device first you know that the problem must be with your master code (or you're connections between master and slave, though this should be relatively straight forward)

 

PS I've noticed you talking about a modular design of sorts in another thread. If the end goal is for a modular system that you can add more slaves too and/ or remove slaves from with relative ease then you may want to look into I2C. You can have up to 128 different devices on the same two wires, and you can add and remove devices to that bus as you please with minimal problems. With SPI you either have to have a separate SS for each slave, or you daisy chain them, however you'll need to know how many slaves are in the chain at any one time in order to work with said chain. So you either need as many SS signals as you have slaves, or some very clever way of finding out how many slaves are connected to the SPI chain in software.

 

PPS I also noticed you talking about communicating directly with a PC over SPI, is this still part of the end goal?

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

implementing slave side SPI can be a real pig,

Particularly when the part one selects as a slave does NOT support slave mode.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly