Hi all.
I have unsuccessfully searched the forums for a related topic. My apologies if this post is redundant.
I have two NRF24L01+ transceivers that talk to each other. The first NRF24L01+ (transmitter) is connected to a stand-alone Atmel ATTiny84, and the second NRF24L01+ (receiver) is connected to a Raspberry Pi B+. An infrared L.E.D. and infrared detector are also connected to the Atmel so that it reflects the beam status on PA0. An unbroken beam produces a logic 0 on PA0, and a broken beam produces a logic 1 on PA0.
The transceivers communicate with each other successfully, but I have noticed an anomaly that I greatly need to understand before I continue with my security project.
At issue is the fact that the RF24::write() function is supposed to return a logic 1 (true) when it succesfully sends a packet. However, there are instances when a packet is successfully transmitted but the RF24::write() function returns a logic 0 (false). After much debugging, I have narrowed down the code that causes the discrepancy. I need help understanding how the code affects the return value.
In this first code excerpt, the RF24::write() function returns 1 for the first four packet transmissions when the beam is broken. Then, it will always return 0 for future packets when the beam is broken, even though those packets are successfully transmitted from the ATTiny84-connected NRF24L01+ to the Raspberry Pi-connected NRF24L01+:
void loop()
{
if(!(IRpin_PIN & (1 << IRpin)))
{
digitalWrite(redLed, LOW);
}
else
{
digitalWrite(redLed, HIGH);
if(value=radio.write((void *) &value,8) == 1)
{
}
}
}
However, in this second code excerpt, the RF24::write() function will always return 1 upon a successful packet transmission when the beam is broken (which seems normal):
void loop(void)
{
if (!(IRpin_PIN & (1 << IRpin)))
{
digitalWrite(redLed, LOW);
}
else
{
digitalWrite(redLed, HIGH);
uint64_t gotByte;
unsigned long time = micros();
if(value=radio.write((void *) &value,8))
{
if(!radio.available())
{
printf("Got blank response. round-trip delay: %lu microseconds\n\r",micros()-time);
}
else
{
while(radio.available())
{
radio.read( &gotByte, 8);
printf("Got response %d, round-trip delay: %lu microseconds\n\r",gotByte,micros()-time);
counter1++;
if(counter1 < 0)
counter1 = 0;
}
}
}
else
{
++failed1;
if(failed1 < 0)
failed1 = 0;
printf("Sending failed for %d. Failure count = %d.\n\r", counter1, failed1);
}
}
}
I'm not sure if the lack of functionality in the first code example is influencing a 0 response from the RF24::write() function. I notice that, if I comment out the extra lines in the second code example so that it looks exactly like the first code example, the RF24::write() function in the second code example also returns 0 despite a successful packet transmission.
From researching this phenomenon on the Internet, the RF24::write() function returns 1 only if it receives an acknowledgement packet after transmitting. However, my coding and testing shows that packets are successfully being received despite the RF24::write() function's returning 0.
If anyone can assist me in figuring out this inconsistency, I would greatly appreciate it. My project depends highly on accurate packet transmission acknowledgement. Therefore, a successful transmission must be accurately reflected by a 1, and an unsuccessful transmission must accurately be reflected by a 0.
Thanks in advance.
-Z