nRF24L01 with PIC code

Hi. I use 2 nRF24L01 with 2 PIC18F2550, CCS C compiler. I make as the remote control. I wanna send a packet from the first 24L01 to the remote 24L01. Next, the remote 24L01 send back that packet to the first 24L01.

This first time I work with PIC and nRF24L01. Could you share with me code C to make my application. Maybe It is a base code to sent/ receive …help to complete the application.

Thank you !

Sorry, my English is not good !

I have some C18 test code here:

http://www.leonheller.com/Wireless%20Se … 24L01+.zip

leon_heller:
I have some C18 test code here:

http://www.leonheller.com/Wireless%20Se … 24L01+.zip

Thank you, Leon_heller !

Do you have the circuit and description for the codes.

:slight_smile:

Here is the schematic:

http://www.leonheller.com/Wireless%20Se … Sensor.pdf

What do you mean by “description for the codes”?

Hi Leon_heller,

I dont know where spi.h and timers.h are in the header. And can I use the 18F2550 with your code ? suitable ?

spi.h and timers.h are part of the C18 distribution. Read the documentation.

You should be able to use the 18F2550, but you might need to make a few changes.

Hi Leon_heller,

I try to run your code in my C18 compiler download from Microchip website.

In MPLAB I selected the device 18f24j11. and Build All, but BUILD FAILED:

Clean: Deleting intermediary and output files.
Clean: Deleted file "D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.o".
Clean: Done.
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mcc18.exe" -p=18F24J11 "test3.c" -fo="test3.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mplink.exe" /l"C:\Program Files\Microchip\mplabc18\v3.42\lib" "C:\Program Files\Microchip\mplabc18\v3.42\bin\LKR\18f24j11_g.lkr" "test3.o" "C:\Program Files\Microchip\mplabc18\v3.42\lib\p18lf24j11.lib" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test3.cof" /M"test3.map" /W
MPLINK 4.43, Linker
Device Database Version 1.8
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - Device not specified. Use /p option to specify a device.
Errors    : 1

Link step failed.

I dont know the reason. Can you help me ?

It looks like you are compiling a program called test3.c, which isn’t mine. Try compiling my programs.

The linker step has failed, I think you need to specify the device.

I copy your TX.c code into the program test3.c to test.

the device I selected in MPLAB is 18F24j11 as your code you use.

Look at the error message, you need to specify the device to the linker! The project builds OK for me without any problems:


Debug build of project `C:\PIC\18F\18F24J11\Wireless Sensor\Tx.mcp’ started.

Language tool versions: mpasmwin.exe v5.44, mplink.exe v4.42, mcc18.exe v3.41, mplib.exe v4.42

Preprocessor symbol `__DEBUG’ is defined.

Fri Jun 22 09:58:18 2012


Clean: Deleting intermediary and output files.

Clean: Deleted file “C:\PIC\18F\18F24J11\Wireless Sensor\Tx.o”.

Clean: Deleted file “C:\PIC\18F\18F24J11\Wireless Sensor\Tx.cof”.

Clean: Deleted file “C:\PIC\18F\18F24J11\Wireless Sensor\Tx.hex”.

Clean: Deleted file “C:\PIC\18F\18F24J11\Wireless Sensor\Tx.mcs”.

Clean: Done.

Executing: “C:\Program Files (x86)\Microchip\mplabc18\v3.41\bin\mcc18.exe” -p=18F24J11 “Tx.c” -fo=“Tx.o” -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-

Executing: “C:\Program Files (x86)\Microchip\mplabc18\v3.41\bin\mplink.exe” /p18F24J11 /l"C:\Program Files (x86)\Microchip\mplabc18\v3.40\lib" “Tx.o” /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"Tx.cof" /M"Tx.map" /W

MPLINK 4.42, Linker

Device Database Version 1.7

Copyright (c) 1998-2011 Microchip Technology Inc.

Errors : 0

MP2HEX 4.42, COFF to HEX File Converter

Copyright (c) 1998-2011 Microchip Technology Inc.

Errors : 0

Loaded C:\PIC\18F\18F24J11\Wireless Sensor\Tx.cof.


Debug build of project `C:\PIC\18F\18F24J11\Wireless Sensor\Tx.mcp’ succeeded.

Language tool versions: mpasmwin.exe v5.44, mplink.exe v4.42, mcc18.exe v3.41, mplib.exe v4.42

Preprocessor symbol `__DEBUG’ is defined.

Fri Jun 22 09:58:25 2012


BUILD SUCCEEDED

Hi Leon Heller,

I upgrade new version of MPLAB from v8.56 to v8.85 and I can run your code well. BUILD SUCCEEDED !!!

 Debug build of project `D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.mcp' started.
Language tool versions: mpasmwin.exe v5.45, mplink.exe v4.43, mcc18.exe v3.42, mplib.exe v4.43
Preprocessor symbol `__DEBUG' is defined.
Fri Jun 22 18:49:21 2012
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.o".
Clean: Deleted file "D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mcc18.exe" -p=18F24J11 "test3.c" -fo="test3.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\Program Files\Microchip\mplabc18\v3.42\bin\mplink.exe" /p18F24J11 /l"C:\Program Files\Microchip\mplabc18\v3.42\lib" "C:\Program Files\Microchip\mplabc18\v3.42\bin\LKR\18f24j11_g.lkr" "test3.o" "C:\Program Files\Microchip\mplabc18\v3.42\lib\p18lf24j11.lib" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test3.cof" /M"test3.map" /W
MPLINK 4.43, Linker
Device Database Version 1.8
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

MP2HEX 4.43, COFF to HEX File Converter
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

Loaded D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.cof.
----------------------------------------------------------------------
Debug build of project `D:\Mon hoc HK2-011-012\Luan van RF\Code PIC\Test3\test3.mcp' succeeded.
Language tool versions: mpasmwin.exe v5.45, mplink.exe v4.43, mcc18.exe v3.42, mplib.exe v4.43
Preprocessor symbol `__DEBUG' is defined.
Fri Jun 22 18:49:25 2012
----------------------------------------------------------------------
BUILD SUCCEEDED

In the header, Can I change #include <p18fcxxx.h> by #include <p18f24j11.h>? I try to run it and BUILD SUCCEEDED, also. Is it right !?

Thank you for answering my trouble. Hope to continuous receive your answer. :smiley:

Look at p18fcxxx.h and you will see that they do the same thing.

Hi Leon Heller,

I use external oscillator with 20 MHz crystal. And system clock is 48 MHz.

In the Pragmas I wrote 48 MHz below:

 #pragma config FOSC = HSPLL_HS
#pragma config PLLDIV = 4
#pragma config CPUDIV = OSC1_PLL2

And in the init (void). I need not write this as your code ?

// run internal oscillator at 8 MHz
   OSCCON = OSCCON | 0b01110000;
   while (!OSCCONbits.OSTS)   // wait for OSTS to go high

The Delay function

void dly(unsigned int c)
{
   INTCONbits.TMR0IF = 0;
   WriteTimer0(c);
   while (!INTCONbits.TMR0IF)
      ;

Could you tell me more How it un and calculate c . ex: c = 65000, ```
dly(65000); //delay 69 ms


Thank you !

Everything you need is in the data sheet.