我的收发器工作正常,因为来自maniacbug的RF24主库的代码工作正常。但我试图学习自己编程,所以我决定来回发送一些整数。它们似乎不起作用。串行监视器打印不同的整数。 TX代码是 -
#include<SPI.h>
#include"nRF24L01.h"
#include"RF24.h"
//#include"printf.h"
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
const unsigned int transmit =1995;
//unsigned int get = 1;
void setup(void)
{
Serial.begin(9600);
//printf_begin();
Serial.println("lets begin the operation");
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
//Serial.print("now get is ");
//Serial.println(get);
//radio.startListening();
//radio.printDetails();
}
void loop(void)
{
//printf("starting the transmission\n");
Serial.println("starting the transmission");
radio.stopListening();
bool ok = radio.write( &transmit, 8 );
if(ok)
//printf("ok....transmission successful !!!");
Serial.println("ok...transmission successful..!!");
else
//printf("faioed to tramsmitt\n");
Serial.println("failed to transmit");
radio.startListening();
unsigned int get;
bool ok2 = radio.read( &get, 8);
if(ok2)
{
//printf("received the packet successfully\n");
Serial.println("received the packet successfully");
//printf("received package is %u\n",get);
Serial.print("received package is ");
Serial.println(get);
}
else
//printf("failed to receive\n");
Serial.println("failed to receive");
delay(1000);
}
RX码是 -
#include<SPI.h>
#include"nRF24L01.h"
#include"RF24.h"
//#include"printf.h"
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
unsigned int transmit = 2014;
//unsigned int get = 0;
void setup(void)
{
Serial.begin(9600);
//printf_begin();
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
//radio.startListening();
//radio.printDetails();
}
void loop(void)
{
radio.startListening();
unsigned int get;
bool ok = radio.read(&get,8);
if(ok)
{
//printf("received successfully\n");
Serial.println("received successfully");
//printf("received payload = %u\n",get);
Serial.print("received payload is ");
Serial.println(get);
}
else
//printf("failed to receive\n");
Serial.println("failed to receive");
radio.stopListening();
//unsigned int transmit = 2014;
bool ok2 = radio.write( &transmit,8 );
if(ok)
//printf("ok....transmission successful !!!");
Serial.println("ok...transmission successful..!!");
else
//printf("faioed to tramsmitt\n");
Serial.println("failed to transmit");
delay(1000);
}
甚至printf.h头文件在我编写代码时似乎不起作用,但它们在库示例中工作得很好。
答案 0 :(得分:1)
检查串行窗口的波特率,大多数9600波特产生问题。尝试检查57600波特率