I've searched google and this forum but it seems no-one else is working with many Arduinos connected together via SPI.
I'd like to have one master Arduino node and many (say 32) Arduino's connected to that master via SPI. They are all SPI slaves and they all would be running the exact same software.
The question I have is simple: How do I allocate each slave Arduino with a unique address if they are all running the same .elf?
If each slave was running different software, I would hardcode the address of each slave in each project and all would work ok, but this simple problem is stumping me.
A few other ways to pose the same question:
- how can I get each slave to retrieve a unique address from the master node?
- how can I get each slave to self-allocate a unique address?
- how can I send each slave a unique address from the master node before it has an SPI address allocated to it?
All help will be greatly appreciated!
Write a unique address in EEPROM of each Arduino. Then write your code to fetch that address upon startup.
SPI doesn't use an address, it uses CS.
Try having a 4 bit address bus between Arduinos, decode it with a 1 of 4, like a 74139 or 74155, you can make one from 7400 quad NAND gates.
(Thinking out loud, disclaimer, never did this myself)
You could cross-breed SPI and I2C. I2C allows addressing up to 100+ slaves.
set one slave as the active one. The Arduino sets its own CS pin HIGH after the appropriate I2C request.
send ‘big’ data with high speed over SPI back and forth
deselect slave. The Arduino sets its own CS pin LOW after the appropriate I2C request (or time out !)
go to 1
should work, but it depends on your timing requirements
how can I get each slave to retrieve a unique address from the master node?
how can I get each slave to self-allocate a unique address?
how can I send each slave a unique address from the master node before it has an SPI address allocated to it?
All this is moot until you explain how you are going to connect them, because SPI is not by nature an addressing bus and if you use logic to get 32 CS signals then the Arduinos don't need to know any address in the first place.
And just how large is this system - how long are the cables going to be? SPI is designed for use on a single circuit board and not for long cable runs - you might have to consider using RS485 or similar as the wire-protocol and SPI over RS485 isn’t very practical with its 3 signals plus CS-per-slave.
Sorry for this. I meant to say I2C (not SPI). As has been pointed out, I2C has a master-slave topology.
I'm sure this will change your replies. Again I apologize for the confusion.
I'm going to create a new Topic for this because the title is misleading.
Again sorry for the confusion.
Yep, that makes a difference :)