NRF24L01 with PIC12F1840 - Page 1
Forum section: electronics / general

author: Volta500
author_rank: Contributor
timestamp: March 18, 2013, 02:56:30 pm
content: Hello,I am doing a project where multiple NRF24L01 modules are connected to an equal number PICs. One PIC sends a packet and the second receives it and sends an acknowledgement to the first again to confirm receipt of the message.As a first test my idea was that one PIC reads a digital input, and when that state changes it transmits the new state to the second PIC, which then lights an LED according to that state.Now I do have a relatively good understanding of C, and I know the basics of PICs but I have no idea how to set up SPI. All information on the internet is with a PIC18F and using different compilers.By reading datasheets I have some idea of what has to happen, but still am a long way away from writing working code.If I would know how to set up SPI, set up NRF24L01 registers and transmit and receive data I could probably figure the rest out myself.I am using MBLAB X, Microchip XC8 compiler in free mode and PicKit 3 programmer/debugger.Preferred PIC is PIC12F1840 as it has hardware SPI, is quite powerful and are nice and small, and doesn't have a crapload of registers to learn.If someone could explain how to use SPI and maybe share some example code it would help me a great deal.Thank you

author: mariush
author_rank: Super Contributor
timestamp: March 18, 2013, 03:47:12 pm
content: The datasheet has all the information you need about SPI:http://ww1.microchip.com/downloads/en/DeviceDoc/41441B.pdfSee chapter 25, from page 211 and onwards, everything about SPI is explained.A good SPI tutorial is here (for pic18, but if you read the datasheet you can change registers and adapt the code for a PIC 12) :http://www.ermicro.com/blog/?p=1846

author: MikeK
author_rank: Super Contributor
timestamp: March 18, 2013, 04:57:23 pm
content: I have a project sitting on my desk at home with a couple of those RF modules. Might be different PICs, but the code is easily ported. I'll post it later. You don't have to use the SPI peripheral, though, as I'm certain the code I wrote doesn't.In the meantime, put it in the Googler. I know the example code I started with came from one of the interwebs.Mike

author: MikeK
author_rank: Super Contributor
timestamp: March 18, 2013, 09:34:52 pm
content: Here are two files to get you started. They're in an obscure language called JAL, but should be easy to port to whatever you're using. You'll need to change them to suit your needs.Mike

author: jeanmarc78
author_rank: Newbie
timestamp: March 27, 2013, 01:11:44 pm
content: Hello,You can find a very good tutorial with code examples for PIC18F an NRF24L01 at :http://blog.diyembedded.com/2007/06/tutorials-1-3-for-pic-completed.htmlIt should be quite easy to adapt them to the PIC12F1840.Best regardsJM

author: Teemo
author_rank: Regular Contributor
timestamp: March 27, 2013, 11:44:45 pm
content: It is really easy to use SPI. The peripheral does all the work for you.example initialization code in assembler.Code:bankselTRISAbcfTRISA,SPI_SDO_PINbcfTRISA,SPI_CLK_PINbanksel SSP1CON1movlwb'00100001';SPI clock 1MHz at 16Mhz PIC clockmovwfSSP1CON1bankselSSP1STATmovlwb'01000000'movwfSSP1STAT