I have an ATmega8 and an Arduino UNO and wanted them to communicate over the nrf24l01 module.
First I used the Arduino to programm the ATmega8 (I flashed a modified pingpair sketch which only receives and sends the data back) and the flashed the transmitter program to the Arduino UNO.
When I connect the Arduino to the PC and open the Serial Monitor it shows
0STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xf0f0f0f0e1
RX_PW_P0-6 = 0x08 0x08 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0f
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_HIGH
Now sending 84...failed.
Failed, response timed out.
Now sending 1357...failed.
Failed, response timed out.
Now sending 2627...failed.
Failed, response timed out.
Now sending 3898...failed.
Failed, response timed out.
Now sending 5169...failed.
Failed, response timed out.
Now sending 6438...failed.
Failed, response timed out.
As you can see it shows the startup details which I think seem to be ok but it always fails at sending.
I double checked all the connections, used a different 3.3v source and even used another nrf24l01 module but everytime it fails.
Maybe there is a mistake in the code?
TX-Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
Serial.begin(57600);
printf_begin();
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.startListening();
radio.printDetails();
}
void loop(void)
{
radio.stopListening();
unsigned long time = millis();
printf("Now sending %lu...",time);
bool ok = radio.write( &time, sizeof(unsigned long) );
if (ok)
printf("ok...");
else
printf("failed.\n\r");
radio.startListening();
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout )
if (millis() - started_waiting_at > 200 )
timeout = true;
if ( timeout )
{
printf("Failed, response timed out.\n\r");
}
else
{
unsigned long got_time;
radio.read( &got_time, sizeof(unsigned long) );
printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
}
delay(1000);
}
RX-Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9, 10);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
radio.begin();
radio.setRetries(15, 15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1, pipes[0]);
radio.startListening();
}
void loop(void)
{
if ( radio.available() )
{
unsigned long got_time;
bool done = false;
while (!done)
{
done = radio.read( &got_time, sizeof(unsigned long) );
delay(20);
}
radio.stopListening();
radio.write( &got_time, sizeof(unsigned long) );
radio.startListening();
}
}
I really appreciate any help