Noob With a Question about nRF2401

Hi
I'm pretty new to all this and am working with a nRF2401. The code I am using is below it receives what it's suppose to and turns an LED on if it receives the correct number. If I upload it with it sending "c" and then in ASCII it's 99, it works out the LED comes on. Then I upload the transmitting board to send an "o" and the receiving board continues to receive 99 until I reset the serial monitor on the receiving board... what am I doing wrong? How can I get it to receive the new transmission? is there a way to like tell it to wipe it's memory and start over each time it loops or something?

Thanks,
Zyan

Receiving board

int state = 0;
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
  Serial.begin(9600);
    pinMode(4, OUTPUT);  
  
  Mirf.spi = &MirfHardwareSpi;

  Mirf.init();

  Mirf.setRADDR((byte *)"serv1");
 
   Mirf.config();
  Mirf.payload = sizeof(int);
    
  Serial.println("Listening..."); 
}

void loop(){
   
  byte data[Mirf.payload];
  
   
 if(Mirf.dataReady()){
    
    do{
      Serial.println("Got packet");

int data;

Mirf.getData((byte *) &data);
Serial.println(data);
state = data;
    if (state == 99){
    digitalWrite(4, HIGH);
    }
    else
{
  digitalWrite(4, LOW);
}
  
    }while(!Mirf.rxFifoEmpty());

  }
 }

Transmitting Board

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
  Serial.begin(9600);

  Mirf.cePin = 7;
  Mirf.csnPin = 8;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  
   
  Mirf.setRADDR((byte *)"clie1");
  
  Mirf.payload = sizeof(int);

  Mirf.config();
  
  Serial.println("Beginning ... "); 
}

void loop(){
  
  Mirf.setTADDR((byte *)"serv1");
  
  Mirf.send((byte *)"c");
  
  while(Mirf.isSending()){
  }
  Serial.println("Finished sending");
  delay(10);
    }

Why don't you try mirf example?

You have added a do...while loop to ping_server example of Mirf.h library. What happen if you remove that code lines? You are sending just one character, so there is no need to check rxfifoBuffer.

And why do you use byte data[] and int data? If you can't think in different names for your variables, I can help you a little: temp, a, b, c, d, data1, data2,... :wink:

In the example, an array of byte is used because sent data is long type. You are sending an ASCII character (byte/char type), so you don't need that array, you only need byte data.

This is an unchecked code based in yours which maybe can help you:

void loop()
{
  byte data;

  if(Mirf.dataReady())
  {
    Serial.println("Got packet");
    Mirf.getData(&data);
    if (data == 99)
      digitalWrite(4, HIGH);
    else
      digitalWrite(4, LOW);
  }
}
void loop(){
  
  Mirf.setTADDR((byte *)"serv1");
  
  Mirf.send((byte *)"c");
  
  while(Mirf.isSending()){
  }
  Serial.println("Finished sending");
  delay(10);
    }

You are sending "c" indefinitely. Why are you surprised the other end receives it?