I have an ESP8266 as the master for my project and arduino nano for the slaves.
I've already managed to get my master to talk to my exclave.
My slaves must send information to the master at all times. For example, 1 is used to control the menu and the other for limit switches, so they can send messages to the master at any time.
If the master runs in a loop to interrogate slave 1, then slave 2, then slave 3, this will be done quickly, but how can I be sure I haven't lost any information? Is it possible for the slave to know that it's being interrogated and only respond at that moment?
It's on this functional part that I'm not sure how to proceed, as the master doesn't always communicate with the slaves.
That's what I thought, but how do I ensure that my slaves send the message at the right time?
So I put the information in a variable that waits for the master to query it before sending it.
The master needs to have the fastest possible loop so as not to lose any information from the slaves.
Is this right?
That's the whole purpose of the chip select (aka slave select) pin. The master takes the a CS pin LOW and whichever slave that pin connects to knows that it can respond.
The slave cannot send data to the master. It can only respond. The master has to clock the data. So even if the master has nothing to say, it must send a 0 byte or something in order to clock the byte back from the slave.
The usual paradigm is to send a control byte and then wait for a few micros while the slave handles it and then send 0's until you have all the data back.