nRF_Read1Register

Purpose: Read the contents of one (1) nRF24L01+ Register.
Assumes:   nRF24L01+ Registers may are either one (1) BYTE or five (5) BYTEs wide; the Register index specified will set the read count.
Passed: R24 BYTE bRegIndex   index of the nRF24L01+ Register to read (0 to 23, 28, or 29)
R23:R22   BYTE *   bptrReply   pointer to the SRAM buffer for the 1-BYTE or 5-BYTE reply; 0x0000 specifies SRAM address 0, which is R0.
Returns: R25 BYTE bnRF_RegByte1   first (perhaps only) BYTE of the Register requested; 0xFF if no nRF is connected; 0x00 if one is attached but is not responding.
R24 BYTE bnRF_Reg7Read   value read back from the nRF24L01+ REG_7_STATUS while the Register request was being emitted.
R22 BYTE bCount number of BYTEs in the reply, which was set automatically, based on the Register index passed.
Alters: R23, the FLAGs (SREG), and the destination buffer
Example:  
.ORG 0x1000

   ADIW    R26, 0                 ; If there is a command line tail, skip past
   BREQ    ALocal_Ret             ;  the immediate exit
   MOVW    R30, R26               ; Save the pointer to the command tail
   MOVW    R24, R26               ; Set the command line tail pointer passed
   CALL    AParseValue            ; Get the first value specifed
   SBRS    R21, BIT_PV_VALID
Local_Ret: RET

   MOV     R26, R22               ; Save the index of the Register specified
   MOV     R24, R22               ; Same value for the Register index to pass
   MOVW    R22, R30               ; Reuse the command tail pointer as target

   CALL    AnRF_Read1Register     ; Return values = R25: Register's first BYTE,
   MOV     R27, R22               ;  R24: REG_7_STATUS, R22: count (1 or 5) and
   LDI     R25, ACSZ_Reg >> 8     ;  either 1 or 5 BYTEs in the target buffer
   LDI     R24, ACSZ_Reg & 0xFF   ; Point to the first string
   MOV     R22, R26               ; Transfer the index to R22 (the Hex BYTE to
   LDI     R19, ' '               ;  be printed after the string) and set a
   CALL    APrintDescAndHexBYTE   ;  single space as the separator
   LDI     R25, ACSZ_Val >> 8     ; The second string preceeds the first data
   LDI     R24, ACSZ_Val & 0xFF   ;  value
   LD      R22, Z+                ; Load the first Register contents data BYTE
   LDI     R19, '='               ;  returned and set the separator
   CALL    APrintDescAndHexBYTE

PrintLoop:
   DEC     R27                    ; Decrement the reply BYTE count returned in
   BREQ    ALocal_CRLF            ;  R22 and exit upon reaching zero
   LDI     R24, ','               ; Print the intermediate ", " between values
   CALL    APrint1CHARAnd1Space
   LD      R24, Z+                ; Read the next BYTE returned from the target
   CALL    APrint0xHexBYTE        ;  buffer and print its value
   RJMP    APrintLoop             ; Always loop back; the check is at the top

Local_CRLF:
   JMP     APrintNewLine          ; Be polite; advance to the next line

CSZ_Reg:  .STRING  "nRF Register"
CSZ_Val:  .STRING  " value"
Test it:
>N   ; Read the complete set of Register values
0x00 (0E) -> 0x7F = B01111111
0x01 (0E) -> 0x00 = B00000000
0x02 (0E) -> 0x3F = B00111111
0x03 (0E) -> 0x03 = B00000011
0x04 (0E) -> 0x34 = B00110100
0x05 (0E) -> 0x4E = B01001110
0x06 (0E) -> 0x06 = B00000110
0x07 (0E) -> 0x0E = B00001110
0x08 (0E) -> 0x00 = B00000000
0x09 (0E) -> 0x00 = B00000000
0x0A (0E) -> 0x32, 0x44, 0x65, 0x6D, 0x6F
0x0B (0E) -> 0x31, 0x44, 0x65, 0x6D, 0x6F
0x0C (0E) -> 0x33 = B00110011
0x0D (0E) -> 0x34 = B00110100
0x0E (0E) -> 0x35 = B00110101
0x0F (0E) -> 0x36 = B00110110
0x10 (0E) -> 0x32, 0x44, 0x65, 0x6D, 0x6F
0x11 (0E) -> 0x00 = B00000000
0x12 (0E) -> 0x00 = B00000000
0x13 (0E) -> 0x00 = B00000000
0x14 (0E) -> 0x00 = B00000000
0x15 (0E) -> 0x00 = B00000000
0x16 (0E) -> 0x00 = B00000000
0x17 (0E) -> 0x11 = B00010001
0x1C (0E) -> 0x3F = B00111111
0x1D (0E) -> 0x07 = B00000111
>                                   ; Logon to use the '@' command
m>@ 4096 0                       ; Using our demo routine, ...
nRF Register 0x00 value = 0x7F
m>@ 4096 1
nRF Register 0x01 value = 0x00
m>@ 4096 2
nRF Register 0x02 value = 0x3F
m>@ 4096 3
nRF Register 0x03 value = 0x03
m>@ 4096 7
nRF Register 0x07 value = 0x0E
m>@ 4096 10
nRF Register 0x0A value = 0x32, 0x44, 0x65, 0x6D, 0x6F
m>@ 4096 11
nRF Register 0x0B value = 0x31, 0x44, 0x65, 0x6D, 0x6F
m>@ 4096 12
nRF Register 0x0C value = 0x33
m>@ 4096 16
nRF Register 0x10 value = 0x32, 0x44, 0x65, 0x6D, 0x6F
m>@ 4096 17
nRF Register 0x11 value = 0x00
m>@ 4096 0x17
nRF Register 0x17 value = 0x11
m>
>           ; Only need to be logged on for the '@' commands
>N 0x17 ?   ; To read single nRF24L01+ Register from the command line:
0x17 (0E) -> 0x11 = B00010001
>                                                                                         
Notes:All nRF24L01+ Registers are 1-BYTE wide except REG_10_RX_ADDR_P0, REG_11_RX_ADDR_P1, and REG_16_TX_ADDR, which are each 5-BYTE wide Registers.
Specifying a A NULL pointer in R23:R22 does not prevent the routine from enbuffering BYTEs, as one might expect. It sets the SRAM address to 0, which is actually MCU Register R0. Due to the way the Operating System uses Registers, use an SRAM buffer address above 0x0100.
The "N ## ?" command performs the same function as this System Function, except that it simply outputs a string the COM1 serial port instead of making the value available to MCU subroutine logic.
This System Function calls the nRF_SPI_Command System Function to do the actual SPI port manipulation.
The value in the parenthesis in the examples using the "N" and "N # ?" System Commands is the value of the REG_7_STATUS Register. Refer to the nRF_SPI_Command page for additional details about how and why this happens.
For more information about the nRF24L01+ radio microchip itself, please refer to the Nordic Semiconductor ® nRF24L01+ Product Specification, version 1.0, dated September, 2008.
Dropin: 
(setup
code)
;   Setup for the NRF_Initialize() call:
; Passed:  R24     BYTE   bRegister index of the nRF24L01+ Register to read
;          R23:R22 BYTE * bptrReply pointer to SRAM buffer (NULL points to R0)
; Returns: R25     BYTE   bRegByte1 first BYTE of the Register requested
;          R24     BYTE   bReg7Stat REG_7_STATUS value received simultaneously
;          R22     BYTE   bCount    number of BYTEs in the reply
; Alters:  R23, the FLAGs (SREG), and the destination buffer
Also see:  The nRF_SPI_Command System Function and the Nordic nRF24L01+ radio script commands.