Skip to main content
Rollback to Revision 1
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

It is better answer for some reseans in Enrf library you can not send data with write untill txbuf_len==0

size_t Enrf24::write(uint8_t c) {
if (txbuf_len == 32) { flush(); // Blocking OTA TX } txbuf[txbuf_len] = c; txbuf_len++; return 1; }

dont use purge then

txbuf_len = 0

this is for read dat

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
 // radio.autoAck(false);
}

void loop() {
  char inbuf[35];
  if (radio.read(inbuf))
  {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  } 
}

this is write for write data:

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}
int i=0;
void loop() {
  i++;
  Serial.print("Sending packet: ");
  Serial.println(i);
  radio.print("1234567890123456789012--------->");
  //radio.purge();
  delay(100);
}

It is better answer for some reseans in Enrf library you can not send data with write untill txbuf_len==0

size_t Enrf24::write(uint8_t c) {
if (txbuf_len == 32) { flush(); // Blocking OTA TX } txbuf[txbuf_len] = c; txbuf_len++; return 1; }

dont use purge then

txbuf_len = 0

this is for read dat

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
 // radio.autoAck(false);
}

void loop() {
  char inbuf[35];
  if (radio.read(inbuf))
  {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  } 
}

this is write for write data:

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}
int i=0;
void loop() {
  i++;
  Serial.print("Sending packet: ");
  Serial.println(i);
  radio.print("1234567890123456789012--------->");
  //radio.purge();
  delay(100);
}
this edite have best answer beauce i can improve codes
Source Link

It is better answer for some reseans in Enrf library you can not send data with write untill txbuf_len==0

size_t Enrf24::write(uint8_t c) {
if (txbuf_len == 32) { flush(); // Blocking OTA TX } txbuf[txbuf_len] = c; txbuf_len++; return 1; }

dont use purge then

txbuf_len = 0

this is for read dat

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
 // radio.autoAck(false);
}

void loop() {
  char inbuf[35];
  if (radio.read(inbuf))
  {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  } 
}

this is write for write data:

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}
int i=0;
void loop() {
  i++;
  Serial.print("Sending packet: ");
  Serial.println(i);
  radio.print("1234567890123456789012--------->");
  //radio.purge();
  delay(100);
}

It is better answer for some reseans in Enrf library you can not send data with write untill txbuf_len==0

size_t Enrf24::write(uint8_t c) {
if (txbuf_len == 32) { flush(); // Blocking OTA TX } txbuf[txbuf_len] = c; txbuf_len++; return 1; }

dont use purge then

txbuf_len = 0

this is for read dat

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
 // radio.autoAck(false);
}

void loop() {
  char inbuf[35];
  if (radio.read(inbuf))
  {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  } 
}

this is write for write data:

#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}
int i=0;
void loop() {
  i++;
  Serial.print("Sending packet: ");
  Serial.println(i);
  radio.print("1234567890123456789012--------->");
  //radio.purge();
  delay(100);
}
Source Link
jose can u c
  • 7k
  • 2
  • 17
  • 27

You did not say which library you are using, but based on the #includes, I am assuming http://maniacbug.github.io/RF24

This line in your receiver code:

  while (!radio.available(true));

does not make sense. You are passing true to the radio.available() function, but the function does not care about a parameter.

You probably mean something like:

while (!radio.available());

When you pass in a variable, you are calling a variant of the function that expects a pipe number to be given, and true is defined as 1. Your transmitter, however, is not sending on pipe number 1.