Hi there,
I am currently having problems with my homebrew code to send data via an nRF24L01+ module. I want to write my own, lightweight library, which just sends without acknowledge packets and on the other end only receives, for this module and am currently trying to solve an issue with transmitting data. The interrupt for "data sent" will not trigger whenever I write data to the TX FIFO. I can write to the registers and read from them, so the SPI setup shouldn't be the problem here. I have attached some code which I am currently using to debug and an image of the state diagram from the data sheet. Maybe my configuration of the module is just wrong but here it comes:
#include <SPI.h>
#include <nRF24L01.h>
//declaration of variables
int CSNpin = 10;
int CEpin = 9;
int IRQ = 2;
//packet to send
byte packet[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, };
volatile bool isSent = 0;
void myISR(){
//reset IRQ flag in status
spiTransfer((STATUS | W_REGISTER), {0x7E}, 1);
//set sent status to true
isSent = 1;
//let LED light up
digitalWrite(LED_BUILTIN, HIGH);
//force CE pin low
digitalWrite(CEpin, LOW);
}
void spiTransfer(byte registry, byte data[], int _length) {
digitalWrite(CSNpin, LOW);
SPI.transfer(registry);
if(_length < 0){
byte* intermediate = data;
SPI.transfer(intermediate, -1*_length);
}else if(_length != 0){
SPI.transfer(data, _length);
}else{
SPI.transfer(data);
}
digitalWrite(CSNpin, HIGH);
}
void setup() {
//set in and output pin modes
pinMode(CEpin, OUTPUT);
pinMode(CSNpin, OUTPUT);
pinMode(IRQ, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
//begin SPI with normal settings
SPI.begin();
//de-select radio and set chip-enable to 0
digitalWrite(CEpin, LOW);
digitalWrite(CSNpin, HIGH);
//give the chip time to power up
delay(500);
spiTransfer((EN_AA | W_REGISTER), {0x00}, 1); //disable all auto-achnowledge pipes
spiTransfer((CONFIG | W_REGISTER), {0x52}, 1); //configure as TX and disable all IRQs instead of data sent
spiTransfer((FEATURE | W_REGISTER), {0x01}, 1); //enable W_TX_PAYLOAD_NO_ACK command word
delay(5);
//set an interrupt pin to be IRQ and to call my ISR
attachInterrupt(digitalPinToInterrupt(IRQ), myISR, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
//transfer the payload, which is packet in this case to the TX FIFO and disable auto-acknowledge for this packet
spiTransfer(W_TX_PAYLOAD_NO_ACK, packet, -32);
//set sent status false
isSent = 0;
//while packet is not sent pulse the CE pin to make module send next entry in TX FIFO
while(isSent == 0){
digitalWrite(CEpin, HIGH);
delayMicroseconds(15);
digitalWrite(CEpin, LOW);
delay(500);
}
delay(500);
digitalWrite(LED_BUILTIN, LOW);
}
Here a link to the full datasheet:
Thanks everyone for reading.