More NRF24L01+ questions on programming


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Red face More NRF24L01+ questions on programming

    Hi Guys ,
    I am looking at a module NRF24L01+ rf transceiver , which uses interface of SPI .
    Since the PIC i am using has no SPI, i have allocated i/o pins to connect it , and using shiftout/ shiftin to get data in/out

    this module spec states it requires that the SPI present data , LSBbyte to MSByte , with MSBit in each Byte first
    eg command D7 -D0 , LSB databyte d7-d0 , MSB databyte D15-d8

    however i am not completely sure what it expects in correct order given the above SPI requirement

    example - to configure a RX pipe0 address of 5 bytes ( its expecting 5 bytes) , i would think i would need to do the following in the order 1- 6 shown
    Or would i need to process all but the command byte in reverse order given eg 1 , then 6 to 2

    i guess the spec sheet has me a bit confused, any input on if i have interpreted this correct ( eg order 1-6) would be good

    http://www.nordicsemi.com/eng/Produc...Hz-RF/nRF24L01i have written code to do the following

    1. send the command byte = write_reg = $20
    2. send the register byte = RX_address_p0 = $0A
    3. Send byte 1 = "N" = $4E
    4. Send byte 2 = "E" = $45
    5 Send byte 3 = "T" = $54
    6 send byte 4 = "1" = $01
    7 send byte 5 = "4"= $04


    Code:
    
    Rf_Common_setup:
       
    '1. Set Address number of Bytes for all Pipes
    data_out[0]= Write_reg    ' Command 
    data_out(1)= Setup_aw     ' Setup Address width all pipes
    data_out[2]= $03          ' $00: illigal, $01: 3 bytes, $02: 4 bytes,$03: 5bytes
    num_byte=2
    gosub SPI_write
    
    '2a. ------ Rx Address for Pipe 0 ------
    data_out[0]= Write_reg   ' Command 
    data_out(1)= Rx_addr_p0  ' Rx address for pipe0
    data_out[2]= $4E         ' "N" '5 byte address
    data_out[3]= $45         ' "E"
    data_out[4]= $54         ' "T"
    data_out[5]= $01         ' "1"
    data_out[6]= $04         ' "4"
    num_byte=6
    gosub SPI_write
    
    return
    
    
    SPI_write: 
        SPI_X = 0               ' Ensure SPI_X = 0
        CSN = 0                                            ' Chip enable 
         For SPI_X = 0 to Num_byte                         ' loop for # byte
           Shiftout SI, SCK, MSBFIRST, [data_out(SPI_X)]   ' Send write enable command
         next SPI_X
        CSN = 1                                            ' Disable to execute command
       
      return

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: More NRF24L01+ questions on programming

    Hi,
    I've never used this device (yet - I've had a couple of tranceivers for a while but haven't gotten around to playing with them) but overall I'd say you're on the right track. The byte and bit order seems to be correct.

    However, if you look at the W_REGISTER command in the datasheet you'll see that it's stated as 001A AAAA where the five A's represents the adress. In your code you seem to have the command and the adress split into to separate bytes.

    I think you should do something like:
    Code:
    Data_Out[0] = Write_Reg + Setup_aw   ' Set adress width for all pipes
    Data_Out[1] = $03    ' $03=5bytes for all pipes
    Num_Byte = 1
    GOSUB SPI_WRITE
    
    Data_Out[0] = Write_Reg + RX_Adress_P0
    Data_Out[1] = "N"
    Data_Out[2] = "E"
    Data_Out[3] = "T"
    Data_Out[4] = "1"
    Data_Out[5] = "4"
    Num_Byte = 5
    GOSUB SPI_Write
    But again, that's just MY interpretation of the datasheet.

    /Henrik.

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: More NRF24L01+ questions on programming

    yep i think your correct , also reading more , i found a note saying LSByte of 5 bytes to be written to RX_Addr_p0 is written first , so if i want to give an address of "NET14" . then i would need to reverse the data out order of the example ?

    '2a. ------ Rx Address for Pipe 0 ------
    data_out[0]= Write_reg ' Command
    data_out(1)= Rx_addr_p0 ' Rx address for pipe0
    data_out[2]= $4E ' "N" '5 byte address
    data_out[3]= $45 ' "E"
    data_out[4]= $54 ' "T"
    data_out[5]= $01 ' "1"
    data_out[6]= $04 ' "4"
    num_byte=6
    gosub SPI_write

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts