nRF24l01+ 2 slaves and 1 master solution

Hi,

I’m having problems with a proyect and need some help.
I have 1 master sending commands to 2 slaves at the same time. The idea is that works like a clock.
If a slave receives an ‘A’, responds and the other slave does nothing, if the second slave receives an ‘E’, then respond and the other slave does nothing.

The problem is the responses of the slaves are read by the master wrong.

The slave 1 is interpreted as slave 2 and vice versa.

I post the master’s code.

Thanks for the help!

// MASTER //

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define Slave1 0  // Ejecutar acción 1
#define Slave2 1  // Ejecutar acción 2
#define WAIT_1 2    // Delay antes de la acción 1
#define WAIT_2 3    // Delay antes de la acción 2

#define intervalo 1000 

byte EstadoActual = WAIT_1;
unsigned long Tiempo_Actual;


char payload[15];
//char payload2;
char payload2[15];

RF24 radio(9, 10); // CE, CSN


uint8_t addresses[][5] = {"AAAAA", "BAAAA"};


        
void setup() {
  

  Serial.begin(9600); 
  radio.begin(); 
 
  radio.setPALevel(RF24_PA_LOW);
  radio.setDataRate(RF24_2MBPS); 
  radio.setAutoAck(false);  


}

void loop() {



  static unsigned long Tiempo_Anterior = 0;
  Tiempo_Actual = millis();

  switch (EstadoActual){
  case WAIT_1:
  if (Tiempo_Actual - Tiempo_Anterior >= intervalo){
     EstadoActual = Slave1;
     }
  break;
  
  //-----------------------------TX 1 ----------------------------

  case Slave1:

  send_Slave1();
 
  
  Tiempo_Anterior = Tiempo_Actual;
  EstadoActual = WAIT_2;
  
  
  break;
  
  case WAIT_2:
  if (Tiempo_Actual - Tiempo_Anterior >= intervalo){
     EstadoActual = Slave2;
  }
  break;

  //-----------------------------TX 2 ----------------------------

  case Slave2:

  send_Slave2();
  
  
  Tiempo_Anterior = Tiempo_Actual;
  EstadoActual = WAIT_1;
  break;
   
   }

}



void send_Slave1() {
  radio.stopListening();
  radio.openWritingPipe(addresses[0]);
  radio.write(&"E", sizeof("E"));
  
  radio.openReadingPipe(1, addresses[1]);
  radio.startListening();
  radio.read(&payload, sizeof(payload)); 
  Serial.print("Slave 1 responde: ");
  Serial.println(payload);
}

    

void send_Slave2() {
  radio.stopListening();
  radio.openWritingPipe(addresses[0]);
  radio.write(&"A", sizeof("A"));  
 
  radio.openReadingPipe(1, addresses[1]);
  radio.startListening();
  radio.read(&payload2, sizeof(payload2));   
  Serial.print("Slave 2 responde: ");
  Serial.println(payload2); 
}

Reading from a device without checking that there is data available is too optimistic to work.

  radio.openReadingPipe(1, addresses[1]);
  radio.startListening();
  radio.read(&payload2, sizeof(payload2));

Why not get your slaves to include a character in their message that identifies which slave it comes from?

There is a master and 2-slaves example in this Simple nRF24L01+ Tutorial

...R