You mean daisy chaining the slaves? That's certainly possible, provided the master knows how many bytes are sent by how many slaves.
But I have a doubt about the grounded select pins. Arduinos are typically too slow to provide data with the first transmission. The same applies to sensors or other devices with JIT data. Such nodes should be given a chance to prepare the data for transmission when selected, then a pause before the transmission itself, and finally a deselect.
At least SPI communication and multi-byte transmission should be tested with Arduinos as slaves. It may not work as expected.
But over here I am trying to have microcontrollers like arduino and esp8266 as slaves and masters but in the previous cases discussed, it is with a single microcontroller and sensor or io device
Not daisy chain. Just smart bus devices that all read the host messages. And if the host says for node 5 to report, then node 5 reports and the rest ignore that message except to watch for the next message start --- I would start messages with a start char(s) and ID.
Daisy chain though, intriguing.
Either way, I'd want to run SPI slower than default to give the chips more cycles between SPI byte arrivals.
How fast do the sensor reads have to be? That may kill some approaches.
SPI is very flexible.
My solution is to give the chips enough code to select themselves when the host message that they ALL read says which one should send data.
Going from a general example to what you need will take understanding the example down to every line of code. Your answers don't give me confidence that you can right now and you won't as long as there's a chance of getting out of that. Sorry but I won't string you along. If you have a deadline a week or more away, you might have a chance.
If I have a byte array, the name compiles to the address of the 1st element.
The first element address is name + 0 and the next is name + 1, or name[0] and name[1]. Having code with both zero and one basing is one step more confusing, easier to make mistakes.
How smart must these devices be that they can disable their MISO outputs while selected but not addressed? Is such an attempt supported by SPI hardware at all?
IMO I2C or ModBus work as you describe, but not SPI.
There is no need to disable MISO as long as only one device uses it at a time.
An AVR can be more complex than a shift register even while serving like one. SPI can run a byte at a time, doesn't HAVE to run bursts, it is very flexible and can broadcast.
Please explain how SPI slaves can "use" their MISO outputs at will. SPI requires that a selected slave turns on its MISO. So if you select all slaves at the same time...
Please explain how broadcast can work on SPI. How can a slave know whether to listen to and not respond at the same time to a transmission?
From AVR data sheet:
When configured as a Slave, the SPI interface will remain sleeping with MISO tri-stated as long as the SS pin is driven high.
...
data will not be shifted out by incoming clock pulses on the SCK pin until the SS pin is driven low.
With the SPI register sending and receiving each bit "at the same time"... yeah!
If they all but one send only LOW bits, that one can send HIGH or LOW can't it?
Otherwise yes, use select pins which... hehehe check this now
Suppose that the host selects one AVR and sends it a number then deselects it and the AVR (14 pin ATtiny) selects the sensor node if you don't have enough pins?
And for pins, a matrix circuit could use 6 pins to get up to 9 selects?
Oh. Damned details. I thought that the INPUTS are tri-state. But OUTPUT LOWs would eat OUTPUT HIGHs. Rats.
The OP will need to be shown how to iterate. OP, get one node working and that can be turned into 2+ nodes. To get one right gives working node code that goes beyond SPI.
I wonder if I2C is fast enough. I un-delayed some wire.h code and the request to data time was miserable.
How are you going to take care of the logic level differences between the devices. Connecting a 3.3volt-logic (ESP) processor to a 5volt-logic (Uno) is a recipe for releasing the magic smoke.
Leo..
You show not the faintest understanding of implementation and use of SPI with multiple nodes. All preceding contributions seem to be lost, not read nor understood.
Hi @DrDiettrich,
I am really sorry but I an new to this, and I am struggling to understand this even though I have basic understanding of SPI protocol. I request you to please help me out with this, and I am in to throughly understand the same as per your advice.