Shop OBEX P1 Docs P2 Docs Learn Events
How do you read nrf24L01 registers? — Parallax Forums

How do you read nrf24L01 registers?

I tried to write a simple test to see if I was writing to an internal register of the nrf24l01+ module. Arduino users have a large library but it's not common among Propeller users. I'm hoping I don't 'have' to learn to read Arduino code.
The test returns '0'. I should get '$02'.
CON   'test reading internal registers nrf24L01

  _clkmode = xtal1 + pll16x                           
  _xinfreq = 5_000_000

  'Pins      
  SPI_SCK  = 5 
  SPI_MISO = 7            
  SPI_MOSI = 6
  SPI_CSN  = 4                            
  SPI_CE   = 3           
   
OBJ     
  SER  : "FullDuplexSerialPlus"                                          

VAR
  long mystery_var, talk_back

PUB Configure_TX

  SER.start(31, 30, 0, 57600)    
  waitcnt(clkfreq * 2 + cnt)
 
  dira[SPI_MOSI]~~    'master out slave in
  dira[SPI_MISO]~     'master in slave out
  dira[SPI_SCK]~~     'serial clock
  dira[SPI_CSN]~~     'chip select NOT
  dira[SPI_CE]~~      'chip enable
  outa[SPI_SCK]~
  outa[SPI_CSN]~~
       
  SPI_Write($20)   'write to config register $00
  SPI_Write($02)   'power up PTX
  SPI_Write($00)   'read config register command
  Read_Register    'looking for return data   

PRI SPI_Write(n) | idx    'mode 0
  'I want to read data in register $00                        
  talk_back~
  outa[SPI_CSN]~             
  repeat idx from 7 to 0    'MSB 1st
    outa[SPI_SCK]~~   
    outa[SPI_MOSI] := n >> (idx)
    talk_back += outa[SPI_MOSI] << (idx)
    mystery_var += outa[SPI_MISO] << (idx)   
    outa[SPI_SCK]~    
  outa[SPI_CSN]~~
   
  SER.bin(talk_back, 8)
  SER.tx(SER#CR)
  SER.bin(mystery_var, 9)
  SER.tx(SER#CR)   

PRI Read_Register  | idx

  repeat 2
    outa[SPI_CSN]~             
    repeat idx from 7 to 0    'MSB 1st
      outa[SPI_SCK]~~       
  '    talk_back += outa[SPI_MOSI] << (idx)
      mystery_var += outa[SPI_MISO] << (idx)   
      outa[SPI_SCK]~    
    outa[SPI_CSN]~~
     
    SER.bin(mystery_var, 12)
    SER.tx(SER#CR)
Sign In or Register to comment.