nRF24L01 - Testing
Without access to RF test equipment, testing is limited to using two modules and
confirming they are able to transmit and receive correctly.
Testing will require the use of a micro or two. As I have access to LPC2106
evalution boards, I may as well use them.
The nRF24L01 uses an SPI port for communication, which is handy, I can reuse the
SPI code used on the uCEthernet project. The only bits of code that I need to
write are the driver, which configures the device and allows me to read and
write packets and the application code.
Two variations of the test code are required, one for the transmitter and one
for the receiver. Both pieces of code will use a common nRF24L01 driver.
The driver was written quickly, as the intention was to use it only as a means
for testing the hardware. It was was written using the top down approach.
Reading the data sheet led me to believe the driver only required two public
funtions. The first function was an initialisation function, the second, a
function to send data and read data received from the nRF24L01 buffers.
The initialisation function is used to configure the module as either a primary
receiver or a primary transmitter. The function takes a structure that holds the
module type (RX, TX) and also the RX and TX addresses. The function then writes
to the relevant registers within the nRF24L01. Once completed the module should
be ready to transmit/receiver enhanced shock burst packets of variable length
(max 32 bytes).
The send function takes two arguments, structures txData and rxData, and returns
an error code.
The send function operates differently depending on what was passed into the
init function. In the case of the primary Tx, the application code should fill
the txData structure buffer with the data to transmit and also the length of the
data to send. The function will take the data and try to send it. It will then
poll the nRF24L01 to determine what has happened. If successful the function,
will check if any data has been received with the ACK packet, any data received
is stored in the rxData structure. If the packet fails to be acknowledged the
function returns, with an error code.
In the case of a primary Rx, the send funtion, will place the txData buffer into
the TX FIFO ready to be transmitted along with an ACK packet, remember the
primary Rx can not initiate comms. If the primary receiver has received data it
shall be placed in the rxData buffer.
The application code for the primary tx module, firstly initiases the module and
then attempts to transmit 32 bytes. If successful it lights an LED as a visual
indication that communications are working.
The application code for the primary Rx intitialises the nRF24L01, and waits for
the IRQ line to go low due to a received packet. It then reads data out of the
FIFO to ensure it does not fill up. For the test code I have not tried to send
data back with the ACK packet.
The code has been written in the Crossworks and Eclipse IDE. I will make it
available at the end of this project.
Initial tests, were a little worrying. I was able to successfully transmit and
receiver a packet ( @ 2 Mbits/s), unfortunately only over a distance of 2
meters!
This is when I could have really done with a spectrum analyser. Without the kit
I resorted to imperically changing the values in the matching network and seeing
how it effected the range.
Strangley the best results (with a chip antenna) were when I completley removed
C4. I could improve things further still by replacing the chip antenna with a
short length of wire! In both cases the range, was further that the limits of my
house (+10 meters and through walls), it may go further I just haven't
tried.
I will experiment a little further with some other chip antenna's at a later
date to see if I can improve on the orginal part. The good news though is that
the nRF24L01 module works!
Now, its time to refine the driver and getting it looking half decent. Ready for
an application...
Page 4