Author Topic: NRF24L01 with PIC12F1840  (Read 13725 times)

0 Members and 1 Guest are viewing this topic.

Offline Volta500Topic starter

  • Contributor
  • Posts: 18
  • Country: nl
NRF24L01 with PIC12F1840
« on: March 18, 2013, 02:56:30 pm »
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
 

Online mariush

  • Super Contributor
  • ***
  • Posts: 4983
  • Country: ro
  • .
Re: NRF24L01 with PIC12F1840
« Reply #1 on: March 18, 2013, 03:47:12 pm »
The datasheet has all the information you need about SPI:

http://ww1.microchip.com/downloads/en/DeviceDoc/41441B.pdf

See 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
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: NRF24L01 with PIC12F1840
« Reply #2 on: March 18, 2013, 04:57:23 pm »
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
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: NRF24L01 with PIC12F1840
« Reply #3 on: March 18, 2013, 09:34:52 pm »
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
 

Offline jeanmarc78

  • Newbie
  • Posts: 1
Re: NRF24L01 with PIC12F1840
« Reply #4 on: March 27, 2013, 01:11:44 pm »
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.html

It should be quite easy to adapt them to the PIC12F1840.

Best regards
  JM
 

Offline Teemo

  • Regular Contributor
  • *
  • Posts: 58
  • Country: ee
Re: NRF24L01 with PIC12F1840
« Reply #5 on: March 27, 2013, 11:44:45 pm »
It is really easy to use SPI. The peripheral does all the work for you.

example initialization code in assembler.
Code: [Select]
banksel TRISA
bcf TRISA,SPI_SDO_PIN
bcf TRISA,SPI_CLK_PIN
banksel SSP1CON1
movlw b'00100001' ;SPI clock 1MHz at 16Mhz PIC clock
movwf SSP1CON1
banksel SSP1STAT
movlw b'01000000'
movwf SSP1STAT
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf