I’m chasing some intermittent problems with hardware that interfaces with NRF24L01 chips, so I’ve been reviewing my firmware. I found what seems to be a bug in the sample receiver code referenced on the web site, or a mis-statement in a referenced tutorial.
The Nordic products sold by SparkFun reference tutorials here:
Tutorial 0 says:
… R_RX_PAYLOAD. This
operation allows you to read the contents of the RX FIFO if you have received a packet
(when you are in RX mode), which is generally signaled by the RX_DR interrupt. Using
this operation is a little more involved than the others, because it requires you to also use
CE.
When you are receiving packets, CE is held high. Once you have received a
packet you MUST bring CE low to disable the receiver, and then you execute the
R_RX_PAYLOAD operation…
The Nordic FOB page refers to example receiver code (http://www.sparkfun.com/datasheets/Wire … er-v10.zip). Here’s the code for reading the RX payload:
//Reads the current RX buffer into the data array
//Forces an RX buffer flush
void receive_data(void)
{
cbi(RX_PORT, RX_CSN); //Stand by mode
rx_spi_byte(0x61); //Read RX Payload
data_array[0] = rx_spi_byte(0xFF);
data_array[1] = rx_spi_byte(0xFF);
data_array[2] = rx_spi_byte(0xFF);
data_array[3] = rx_spi_byte(0xFF);
sbi(RX_PORT, RX_CSN);
rx_send_byte(0xE2); //Flush RX FIFO
rx_send_command(0x27, 0x40); //Clear RF FIFO interrupt
sbi(RX_PORT, RX_CE); //Go back to receiving!
}
Note that while CE is set high at the end of the function, it is never set low. It’s not set low before calling this function either.
Is this a bug, or is it not really necessary to power off the RF front end to receive a payload? I can’t find anything in the NRF24L01 spec that says you must use CE to do a R_RX_PAYLOAD.
I’ve been using this code fragment for some time and it seems to work without bringing CE low to receive the payload. I now use two receivers for frequency diversity, so it would be convenient to just leave CE high while I read received payloads, selecting the receiver with the appropriate CSN input.
Thanks,
Dave Thomas