I'm hoping to start a project that involves multiple MCU's communicating with each other different controller values, clock speeds, etc. My hope is to somehow figure out a way for a way for a "master" MCU to "ping" other MCU's on the same bus and then dynamically assign "location" addresses.
Think of it like this: The master unit is connected to a slave unit( I'll call it S1), sending all types of data. I then plug another slave unit(S2) into the same bus. Either by an automatic refresh, or a triggered refresh, the master unit detects the new unit on the bus, and recognizes the type of device it is. it then assigns a name to the unit according to what is next available to give(address S1 is used, so I'll name this slave S2...)
Could I do this with either 12C or SPI? UART?
I know this might be a bit confusing, and I'll admit that I'm still a bit new to all this, so If I am overlooking anything please don't hesitate to let me know! Also, if there is an obvious way to do this that my newbie understand is missing, I apologize.
The only one of the above being a bus is I2C. The other's are point-to-point connections (UART) or bus lines together with point-to-point lines (SPI uses a different slave select line for every slave connected). Even I2C uses fixed addresses for every slave so your auto-detect feature probably won't work. All this interfaces are designed to be used locally (short cables).
If you use an Ethernet network you get most of the features you like, you can auto-detect your slaves and you're not so limited in the distance between your MCUs. But you need more than just your Arduinos, some sort of router with a DHCP server should be in the network to allow you auto-detection.
I found a different I2C library with a scan() function that reports the address of all connected devices. I'm hoping that it won't be too difficult to do a timed "scan" every few seconds, and that I can then deal with the new device addresses accordingly. If I can't get the autoscan part working, I'll just install a button that triggers scan(). Either way it's a start I think...here is the library incase anyone wants to see it:
I know that SPI can select different units via a different SS signal going to each slave. Another little idea I had was sending the same SS signal to all units, but controlling which slave was "listening" by using a separate serial signal sent to all units, and telling particular units to switch their SS pin High/Low. Off the top of my head this sounds like a timing nightmare, but this way I can daisy chain the sync inputs. Thoughts?
I am vaguely aware that I was able to do this via a network adapter, but I would rather not add that many components at this time. Hopefully I will get the I2C line to do what I need it too, and go from there.
The I2C scan is done by calling up each available address and registering who's answering. Please keep in mind that I2C is not made as a plug and unplug bus. You have to keep the bus capacitance low and you maybe have to change the pull-ups if you connect more devices. Wires have to be relatively short.
Your idea with the SPI will probably not work because the master is controlling the SS pin not the slave, theoretically you can establish a new protocol on the SPI but then you have almost an I2C.