News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Connection between NRF24L01 and PIC12F675

Started by asruben, Nov 24, 2023, 12:09 AM

Previous topic - Next topic

asruben

I am a new programmer and I find Proton Basic to be a quite understandable IDE that I really like. I want to delve even deeper into this IDE.

Previously, I made RF connections between the RF433mhz module and the PIC12F675, but this module is very limited in terms of distance and many other things.

Well, my question is specifically about the connection and transmission between the NRF24L01 module and the PIC12F675. I don't have data on how to make this connection; I have some ideas, but it's not enough. I need help or some ideas to achieve this connection specifically between these devices.



Thank you for your responses.

top204

#1
I did some experimenting with the nRF2401+ transceivers a few years ago, but never finished them because I moved to the E220 modules instead.

However, I have attached my nRF2401+ library and some demo programs so it may help some users. It is written for 18F devices or enhanced 14-bit core devices, but could be adapted for some of the, now obsolete, standard 14-bit core devices with a few tweaks of the code, but I would not recommend it because they are now very outdated and very limited in their capabilities compared to devices developed 15 years ago, onwards.

Below is the code listing for the nRF2401+ library, and this is also in the attached zip file:

$ifndef _NRF24L01_INC_
$define _NRF24L01_INC_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Interface to an nRF24L01+ Tranceiver module
'
' NRF24L01+ PCB Pinouts on the board used (PCB Component Side View)
' |
' |   3.3V   CSN   MOSI  IRQ
' |    |      |     |     |
' |    O      O     O     O
' |
' |    O      O     O     O
' |    |      |     |     |
' |   GND     CE   SCK    MISO
' ---------------------------------
'
' Written By Les Johnson for the Positron8 BASIC Compiler
' For Enhanced 14-bit core devices and 18F devices
'
' USed USART3 for TX and RX to/from the NRF2401+ module. Change code appropriately if using a different USART
'
    #Disable HRsin3To, HRSIn3, HSerOut3, HRSIn3_RCREG_Read      ' Disable the compiler's Hserout3 and Hserin3 library routines
'
' Setup the default pins used to connect to the nRF24L01+ device
'
$ifndef NRF_MOSI_Pin
    $define NRF_MOSI_Pin PORTC.5    ' Connects to the nRF24L01+ MOSI pin (SPI in to the nRF24L01+ chip)
    $SendWarning "Using the default pin for NRF_MOSI_Pin. Please set the NRF_MOSI_Pin in the main program before the NRF24L01+.Inc"
$endif
$ifndef NRF_MISO_Pin
    $define NRF_MISO_Pin PORTC.4    ' Connects to the nRF24L01+ MISO pin (SPI out from the nRF24L01+ chip)
    $SendWarning "Using the default pin for NRF_MISO_Pin. Please set the NRF_MISO_Pin in the main program before the NRF24L01+.Inc"
$endif
$ifndef NRF_SCK_Pin
    $define NRF_SCK_Pin  PORTC.3    ' Connects to the nRF24L01+ SCK pin
    $SendWarning "Using the default pin for NRF_SCK_Pin. Please set the NRF_SCK_Pin in the main program before the NRF24L01+.Inc"
$endif
$ifndef NRF_CSN_Pin
    $define NRF_CSN_Pin  PORTB.3    ' Connects to the nRF24L01+ CSN pin (active low)
    $SendWarning "Using the default pin for NRF_CSN_Pin. Please set the NRF_CSN_Pin in the main program before the NRF24L01+.Inc"
$endif
$ifndef NRF_IRQ_Pin
    $define NRF_IRQ_Pin  PORTB.4    ' Connects to the nRF24L01+ IRQ pin (active low)
    $SendWarning "Using the default pin for NRF_IRQ_Pin. Please set the NRF_IRQ_Pin in the main program before the NRF24L01+.Inc"
$endif
$ifndef NRF_CE_Pin
    $define NRF_CE_Pin   PORTC.1    ' Connects to the nRF24L01+ CE pin
    $SendWarning "Using the default pin for NRF_CE_Pin. Please set the NRF_CE_Pin in the main program before the NRF24L01+.Inc"
$endif

$define cRX_MODE         $01
$define cTX_MODE         $02
$define cR_REGISTER      $00
$define cW_REGISTER      $20
$define cR_RX_PAYLOAD    $61
$define cW_TX_PAYLOAD    $A0
$define cFLUSH_TX        $E1
$define cFLUSH_RX        $E2
$define cREUSE_TX_PL     $E3
'
' nRF24L01+ Registers
'
$define cNRF_CONFIG      $00
$define cNRF_EN_AA       $01
$define cNRF_EN_RXADDR   $02
$define cNRF_SETUP_AW    $03
$define cNRF_SETUP_RETR  $04
$define cNRF_RF_CH       $05
$define cNRF_RF_SETUP    $06
$define cNRF_STATUS      $07
$define cNRF_OBSERVE_TX  $08
$define cNRF_CD          $09
$define cNRF_RX_ADDR_P0  $0A
$define cNRF_RX_ADDR_P1  $0B
$define cNRF_RX_ADDR_P2  $0C
$define cNRF_RX_ADDR_P3  $0D
$define cNRF_RX_ADDR_P4  $0E
$define cNRF_RX_ADDR_P5  $0F
$define cNRF_TX_ADDR     $10
$define cNRF_RX_PW_P0    $11
$define cNRF_RX_PW_P1    $12
$define cNRF_RX_PW_P2    $13
$define cNRF_RX_PW_P3    $14
$define cNRF_RX_PW_P4    $15
$define cNRF_RX_PW_P5    $16
$define cNRF_FIFO_STATUS $17
'
' Power Amplifier levels
'
$define cNRF_PA_MIN   0
$define cNRF_PA_LOW   1
$define cNRF_PA_HIGH  2
$define cNRF_PA_MAX   3
$define cNRF_PA_ERROR 4
'
' CRC Length.  How big (if any) of a CRC is included
' For use with NRF_SetCRCLength()
'
$define cNRF_CRC_DISABLED 0
$define cNRF_CRC_8        1
$define cNRF_CRC_16       2
'
' Data rate. How fast data moves through the air
' For use with NRF_SetDataRate()
'
$define cNRF_1MBPS   0
$define cNRF_2MBPS   1
$define cNRF_250KBPS 2
'
' Non + omissions
$define cNRF_LNA_HCURR 0
'
' + model memory Map
'
$define cNRF_RPD                 $09
$define cNRF_W_TX_PAYLOAD_NO_ACK $B0
'
' + model bit Mnemonics
'
$define cNRF_DR_LOW   5
$define cNRF_DR_HIGH  3
$define cNRF_PWR_LOW  1
$define cNRF_PWR_HIGH 2
'
' Bit Mnemonics
'
$define cNRF_MnMASK_RX_DR  6
$define cNRF_MnMASK_TX_DS  5
$define cNRF_MnMASK_MAX_RT 4
$define cNRF_MnEN_CRC      3
$define cNRF_MnCRCO        2
$define cNRF_MnPWR_UP      1
$define cNRF_MnPRIM_RX     0
$define cNRF_MnENAA_P5     5
$define cNRF_MnENAA_P4     4
$define cNRF_MnENAA_P3     3
$define cNRF_MnENAA_P2     2
$define cNRF_MnENAA_P1     1
$define cNRF_MnENAA_P0     0
$define cNRF_MnERX_P5      5
$define cNRF_MnERX_P4      4
$define cNRF_MnERX_P3      3
$define cNRF_MnERX_P2      2
$define cNRF_MnERX_P1      1
$define cNRF_MnERX_P0      0
$define cNRF_MnAW          0
$define cNRF_MnARD         4
$define cNRF_MnARC         0
$define cNRF_MnPLL_LOCK    4
$define cNRF_MnRF_DR       3
$define cNRF_MnRF_PWR      6
$define cNRF_MnRX_DR       6
$define cNRF_MnTX_DS       5
$define cNRF_MnMAX_RT      4
$define cNRF_MnRX_P_NO     1
$define cNRF_MnTX_FULL     0
$define cNRF_MnPLOS_CNT    4
$define cNRF_MnARC_CNT     0
$define cNRF_MnTX_REUSE    6
$define cNRF_MnFIFO_FULL   5
$define cNRF_MnTX_EMPTY    4
$define cNRF_MnRX_FULL     1
$define cNRF_MnRX_EMPTY    0
$define cNRF_MnDPL_P5      5
$define cNRF_MnDPL_P4      4
$define cNRF_MnDPL_P3      3
$define cNRF_MnDPL_P2      2
$define cNRF_MnDPL_P1      1
$define cNRF_MnDPL_P0      0
$define cNRF_MnEN_DPL      2
$define cNRF_MnEN_ACK_PAY  1
$define cNRF_MnEN_DYN_ACK  0

$define NRF_SPI_Enable() PinClear NRF_CSN_Pin       ' Open the SPI interface
$define NRF_SPI_Disable() PinSet NRF_CSN_Pin        ' Close the SPI interface

$define NRF_TX() PinClear NRF_CE_Pin
$define NRF_RX() PinSet NRF_CE_Pin

$define cRX_MODE 0                                  ' Set the NRF24L01+ routines mode to RX
$define cTX_MODE 1                                  ' Set the NRF24L01+ routines mode to TX

$define NRF24L01_In HSerIn3                         ' Replace the name HSerin3 with  NRF24L01_In
$define NRF24L01_Out HSerOut3                       ' Replace the name HSerOut3 with  NRF24L01_Out
$define cNRF_PacketDelayUs 1024                     ' The delay (in Us) between packet transmissions

$define cNRF_TimeoutCycles $eval ((66 * _xtal) / 4)  ' Calculate the amount of cycles used in the Timeout loop
$if cNRF_TimeoutCycles > 65535
    $SendError "cNRF_TimeoutCycles is too high a value. It must not go above 65535"
$endif

$define _BV(x) $eval (1<<(x))

$define cNRF_PayloadAmount 5                        ' The amount of bytes to send or receive in a packet

    Dim NRF_bFlags As Byte Access
    Dim tMode_TXorRX As NRF_bFlags.0                ' 1 if TX mode has been set, 0 if RX mode has been set
'
' Create the data buffer for the TX and RX
'
    Dim NRF_bAddressDataPipe0[cNRF_PayloadAmount] As Byte Heap
'
' Create some aliases to the buffer
'
    Dim NRF_bBuffer        As NRF_bAddressDataPipe0#0
    Dim NRF_BufferByte     As NRF_bAddressDataPipe0#0
    Dim NRF_BufferByteH    As NRF_bAddressDataPipe0#1
    Dim NRF_BufferByteHH   As NRF_bAddressDataPipe0#2
    Dim NRF_BufferByteHHH  As NRF_bAddressDataPipe0#3
    Dim NRF_BufferWord     As NRF_BufferByte.Word
    Dim NRF_BufferDword    As NRF_BufferByte.Dword
    Dim NRF_BufferFloat    As NRF_BufferByte.Float


    Dim NRF_bGenIndex      As Byte Access   ' Holds the amount of bytes to read and write in a packet
    Dim NRF_bRegister      As Byte Access   ' Holds the register to write too in the NRF device
    Dim NRF_bAmtOfBufferBytes As Byte Access ' Holds the amount of bytes in a packet
    Dim NRF_wBufferAddress As Word          ' Holds the address of the buffer array
    Dim NRF_bTemp          As Byte Access   ' Used as a temporary byte variable
    Dim NRF_bValue         As NRF_bTemp     ' Holds the byte to write to the NRF device

    Dim NRF_bSPI_ByteInOut As Byte Access   ' Holds the byte transmitted or read from SPI
    Dim NRF_bSPI_BitCount  As Byte Access   ' Holds the bit count for the SPI routine
'
' Create compiler system variables for the original Hrsin3 and Hrsout3 library routines
'
    Dim GEN  As Byte System
    Dim GENH As Byte System
    Dim PP0  As Byte System
    Dim PP1  As Byte System
    Dim PP1H As Byte System
    Dim PP7  As Byte System
    Dim PP7H As Byte System

    Dim wGEN As GEN.Word                            ' Create a 16-bit variable from GEN\H
    Dim wPP1 As PP1.Word                            ' Create a 16-bit variable from PP1\H
    Dim wPP7 As PP7.Word                            ' Create a 16-bit variable from PP7\H

$ifdef _ecore                                       ' Are we using an enhanced 14-bit core device?
    Dim Save_WREG As Byte                           ' Holds a copy of the WREG
    Dim Save_FSR0 As Word                           ' Holds a copy of FSR0L\H
    Dim Save_FSR1 As Word                           ' Holds a copy of FSR1L\H
$else                                               ' Otherwise... It's an 18F device
    Dim Save_WREG As Byte Heap                      ' Holds a copy of the WREG
    Dim Save_FSR0 As Word Heap                      ' Holds a copy of FSR0L\H
    Dim Save_FSR1 As Word Heap                      ' Holds a copy of FSR1L\H
$endif
    Dim NRF_wFSR0 As FSR0L.Word                     ' Convert two 8-bit SFRs into a 16-bit SFR
    Dim NRF_wFSR1 As FSR1L.Word                     ' Convert two 8-bit SFRs into a 16-bit SFR

'----------------------------------------------------------------------------------------------
    GoTo NRF_Main                                   ' Jump to the main section of code

'----------------------------------------------------------------------------------------------
' Software SPI transmit and receive
' Input     : pValue holds the byte to write
' Output    : NRF_bSPI_ByteInOut and WREG hold the byte read from the SPI
' Notes     : 8-bit, MSB first
'           : Delays required when operating the microcontroller at 64MHz because the NRF2401+ does not operate well at high frequency SPI
'
Proc NRF_SPI_ReadWriteByte(pValue As WREG), WREG

    NRF_bSPI_ByteInOut = pValue                         ' Transfer the byte to write into NRF_bSPI_ByteInOut
    For NRF_bSPI_BitCount = 7 To 0 Step -1              ' Create a loop for the 8-bits
        PinClear NRF_MOSI_Pin                           ' \
        If NRF_bSPI_ByteInOut.7 = 1 Then                ' | Put the current outgoing bit on NRF_MOSI_Pin
            PinSet NRF_MOSI_Pin                         ' |
        EndIf                                           ' /
        NRF_bSPI_ByteInOut = NRF_bSPI_ByteInOut << 1    ' Shift the next bit into MSB
        PinSet NRF_SCK_Pin                              ' Set the SCK pin high
        DelayUS 2                                       ' A small delay between clock cycles
        NRF_bSPI_ByteInOut.0 = NRF_MISO_Pin             ' Capture the current bit from the NRF_MISO_Pin
        PinClear NRF_SCK_Pin                            ' Pull the SCK pin low
        DelayUS 2                                       ' A small delay between clock cycles
    Next
    DelayUS 10
    Result = NRF_bSPI_ByteInOut                         ' Transfer the byte read into WREG
EndProc

'----------------------------------------------------------------------------------------------
' Read from the SPI interface
' Input     : None
' Output    : WREG
' Notes     : None
'
Proc NRF_SPI_ReadByte(), WREG
    NRF_SPI_ReadWriteByte($FF)
    Result = WREG
EndProc

'----------------------------------------------------------------------------------------------
' Write to the SPI interface
' Input     : pValue holds the byte to write
' Output    : None
' Notes     : None
'
$define NRF_SPI_WriteByte(pValue) NRF_SPI_ReadWriteByte(pValue)

'----------------------------------------------------------------------------------------------
' Initialise the SPI interface pins
' Input     : None
' Output    : None
' Notes     : None
'
Proc NRF_SPI_Init()
    Low NRF_SCK_Pin
    Output NRF_MOSI_Pin
    Input NRF_MISO_Pin
    High NRF_CSN_Pin
EndProc

'-------------------------------------------------------------------------------------------
' Write to a register inside the nRF24L01+ device
' Input     : pRegister holds the register within the chip to write too
'           : pValue holds the value to write to the register
' Output    : None
' Notes     : None
'
Proc NRF_WriteRegister(pReg As NRF_bRegister, pValue As NRF_bValue)
    NRF_SPI_Enable()                        ' Enable the SPI interface
    NRF_SPI_WriteByte(cW_REGISTER | pReg)
    NRF_SPI_WriteByte(NRF_bValue)
    NRF_SPI_Disable()                       ' Disable the SPI interface
EndProc

'-------------------------------------------------------------------------------------------
' Read a register from the nRF24L01+ Device
' Input     : pRegister holds the register within the chip to read from
' Output    : Returns the value read from the register
' Notes     : WREG also holds the value read from the device
'
Proc NRF_ReadRegister(pReg As NRF_bRegister), Byte
    NRF_SPI_Enable()                        ' Enable the SPI interface
    NRF_SPI_WriteByte(cR_REGISTER | pReg)
    Result = NRF_SPI_ReadByte()
    NRF_SPI_Disable()                       ' Disable the SPI interface
EndProc

'-------------------------------------------------------------------------------------------
' Reads the nRF24L01+ STATUS register and returns 1 if the receiver has new data
' Input     : None
' Output    : WREG holds 1 when data is available
'           : WREG holds 0 when data is not available
' Notes     : None
'
Proc NRF_DataReady(), WREG
    NRF_bTemp = NRF_ReadRegister(cNRF_STATUS)
    If NRF_bTemp.6 = 1 Then
        Result = 1
        ExitProc
    EndIf
    Result = 0
EndProc

'-------------------------------------------------------------------------------------------
' Flush the buffer in the nRF24L01+ Device
' Input     : None
' Output    : None
' Notes     : None
'
Proc NRF_Flush_RX()
    NRF_SPI_Enable()
    NRF_SPI_WriteByte(cFLUSH_RX)
    NRF_SPI_Disable()
EndProc

'-------------------------------------------------------------------------------------------
' Flush the buffer in the nRF24L01+ Device
' Input     : None
' Output    : None
' Notes     : None
'
Proc NRF_Flush_TX()
    NRF_SPI_Enable()
    NRF_SPI_WriteByte(cFLUSH_TX)
    NRF_SPI_Disable()
EndProc

'-------------------------------------------------------------------------------------------
' Write a byte array to the nRF24L01+ Device
' Input     : pReg
'           : pBufAddr holds the address of the buffer array
'           : pAmount holds the amount of bytes to write
' Output    : None
' Notes     : None
'
Proc NRF_hWriteBuffer(pReg As NRF_bRegister, ByRef pBufAddr As NRF_wBufferAddress, pAmount As NRF_bAmtOfBufferBytes)
    NRF_SPI_Enable()                                            ' Enable the SPI interface
    NRF_SPI_WriteByte(pReg)                                     ' Select the register within the NRF24L01+ device
    For NRF_bGenIndex = pAmount - 1 To 0 Step -1                ' Create a loop for the amount of bytes to write
        NRF_bTemp = Ptr8(pBufAddr++)                            ' Read a byte from the buffer array and increment its adress
        NRF_SPI_WriteByte(NRF_bTemp)                            ' Write it to the nRF24L01+ Device
    Next
    NRF_SPI_Disable()                                           ' Disable the SPI interface
EndProc

'-------------------------------------------------------------------------------------------
' Read from the nRF24L01+ Device and place the result in a byte array
' Input     : pReg
'           : pBufAddr holds the address of the buffer array
'           : pAmount holds the amount of bytes to write
' Output    : The array pointed to by pBufAddr will be filled with the data read from the nRF24L01+ Device
' Notes     : None
'
Proc NRF_hReadBuffer(pReg As NRF_bRegister, ByRef pBufAddr As NRF_wBufferAddress, pAmount As NRF_bAmtOfBufferBytes)
    NRF_SPI_Enable()                                            ' Enable the SPI interface
    NRF_SPI_WriteByte(NRF_bRegister)                            ' Select the register within the NRF24L01+ device
    For NRF_bGenIndex = pAmount - 1 To 0 Step -1                ' Create a loop for the amount of bytes to read
        NRF_bTemp = NRF_SPI_ReadByte()                          ' Read a byte from the nRF24L01+ Device
        Ptr8(pBufAddr++) = NRF_bTemp                            ' Load it in the the array pointed to by NRF_wBufferAddress, and increment the address
    Next
    NRF_SPI_Disable()                                           ' Disable the SPI interface
EndProc

'-------------------------------------------------------------------------------------------
' Place the nRF24L01+ in TX mode
' Input     : None
' Output    : None
' Notes     : None
'
Proc NRF_SetMode_TX()
    NRF_WriteRegister(cNRF_STATUS, $70)     ' Reset the NRF24L01+ device's STATUS register
    NRF_WriteRegister(cNRF_CONFIG, $0E)     ' Set TX Control
    NRF_TX()
    tMode_TXorRX = cTX_MODE                 ' Set the flag as TX mode chosen
EndProc

'-------------------------------------------------------------------------------------------
' Place the nRF24L01+ in RX mode
' Input     : None
' Output    : None
' Notes     : None
'
Proc NRF_SetMode_RX()
    NRF_WriteRegister(cNRF_STATUS, $70)     ' Reset the NRF24L01+ device's STATUS register
    NRF_WriteRegister(cNRF_CONFIG, $0F)     ' Set RX Control
    NRF_RX()
    tMode_TXorRX = cRX_MODE                 ' Set the flag as RX mode chosen
EndProc

'-------------------------------------------------------------------------------------------
' Transmits data
' Input     : pBufferAddr holds the address of the buffer array to transmit
' Output    : None
' Notes     : Must have a delay after each piece of data is sent
'
Proc NRF_SendData(ByRef pBufferAddr As NRF_wBufferAddress)
    NRF_Flush_TX()
    NRF_SetMode_TX()                        ' Set the mode to transmit
    NRF_hWriteBuffer(cW_TX_PAYLOAD, pBufferAddr, cNRF_PayloadAmount)
    PinSet NRF_CE_Pin
    DelayUS 10
    PinClear NRF_CE_Pin
    DelayUS cNRF_PacketDelayUs
EndProc

'-------------------------------------------------------------------------------------------
' Reads data from the nRF24L01+ Device
' Input     : pBufferAddr holds the address of the buffer array
' Output    : The array pointed to by pBufAddr will be filled with the data read from the nRF24L01+ Device
' Notes     : None
'
Proc NRF_ReadData(ByRef pBufferAddr As NRF_wBufferAddress)
    NRF_hReadBuffer(cR_RX_PAYLOAD, pBufferAddr, cNRF_PayloadAmount)
    NRF_WriteRegister(cNRF_STATUS, $70)             ' Reset the nRF24L01+ STATUS register
    NRF_Flush_RX()                                  ' Flush the NRF24L01+ RX buffer
EndProc

'-------------------------------------------------------------------------------------------
' Set a channel.
' Input     : pRF_Channel holds the channel value
' Output    : None
' Notes     : None
'
$define NRF_SetChannel(pRF_Channel) NRF_WriteRegister(cNRF_RF_CH, pRF_Channel)

'-------------------------------------------------------------------------------------------
' Get the channel used
' Input     : None
' Output    : The channel used.
' Notes     : None
'
$define NRF_GetChannel() NRF_ReadRegister(cNRF_RF_CH)

'-------------------------------------------------------------------------------------------
'
$define NRF_StandbyI()                  '
    NRF_WriteRegister(cNRF_CONFIG, $0A) '
    DelayMS 10

'-------------------------------------------------------------------------------------------
'
Proc NRF_SetAutoAck(pEnable As Bit)
    If pEnable = 1 Then
        NRF_WriteRegister(cNRF_EN_AA, $3F)
    Else
        NRF_WriteRegister(cNRF_EN_AA, $00)
    EndIf
EndProc

'-------------------------------------------------------------------------------------------
'
Proc NRF_SetPALevel(pLevel As Byte)
    Dim bSetup As Byte = NRF_ReadRegister(cNRF_RF_SETUP)
    bSetup = bSetup & %11111000

    pLevel = (pLevel << 1) + 1                  ' \ Calculate level
    bSetup = bSetup | pLevel                    ' /
    NRF_WriteRegister(cNRF_RF_SETUP, bSetup)    ' Write it to the chip
EndProc

'-------------------------------------------------------------------------------------------
'
Proc NRF_SetCRCLength(pLength As Byte)
    Dim bConfig As Byte = NRF_Read_Register(cNRF_CONFIG) & ~(_BV(cNRF_CRCO) | _BV(cNRF_EN_CRC))

    If pLength <> cNRF_CRC_DISABLED Then
        If pLength = cNRF_CRC_8 Then
            bConfig = bConfig | _BV(cNRF_EN_CRC)

        ElseIf pLength = cNRF_CRC_16 Then
            bConfig = bConfig | _BV(cNRF_EN_CRC)
            bConfig = bConfig | _BV(cNRF_CRCO)
        EndIf
    EndIf
    NRF_WriteRegister(cNRF_CONFIG, bConfig)
EndProc

'-------------------------------------------------------------------------------------------
'
Proc NRF_SetDataRate(pSpeed As Byte), Bit
    Dim bSetup As Byte = NRF_Read_Register(cNRF_RF_SETUP)
'
' High and Low '00' is 1Mbs - The default
'
    bSetup = bSetup & ~(_BV(cNRF_DR_LOW) | _BV(cNRF_DR_HIGH))
    'txDelay=85
   
    If pSpeed = cNRF24_250KBPS Then
        '
        ' Must set the cNRF_DR_LOW to 1, cNRF_DR_HIGH is already 0
        ' Making it '10'
        '
        bSetup = bSetup | _BV(cNRF_DR_LOW)
        'txDelay = 155
    Else
        '
        ' Set 2Mbs, cNRF_DR (cNRF_DR_HIGH) is set 1
        ' Making it '01'
        '
        If pSpeed = cNRF24_2MBPS Then
            bSetup = bSetup | _BV(cNRF_DR_HIGH)
            'txDelay = 65
        EndIf
    EndIf

    NRF_Write_Register(cNRF_RF_SETUP, bSetup)
'
' Verify the result
'
    If bSetup = NRF_Read_Register(cNRF_RF_SETUP) Then
        Result = True
    Else
        Result = False
    EndIf
EndProc

'----------------------------------------------------------------------------------------------
'
Proc NRF_SetRetries(pDelay As Byte, pCount As Byte)
    NRF_Write_Register(cNRF_SETUP_RETR, (pDelay & $0F) << cNRF_MnARD | (pCount & $0F) << cNRF_MnARC)
EndProc

'----------------------------------------------------------------------------------------------
' Receive a byte from the NRF24L01+ device, with a timeout
' Input     : wGEN holds the timeout value (in approx milliseconds)
' Output    : PP0 And WREG hold the Byte read
' Notes     : Replaces the compiler's HRsin3 and Hserin3 (with timeout) Commands library routine
'
#ifSym __Syscom_Hrsin3_To_Req_                      ' Include the following code if HRSIn3 or HSerIn3 with timeout have been used in the program
__hrsin3_with_timeout__:
    wPP7 = wGEN                                     ' Move the timeout value so it doesn't get wrecked
    If tMode_TXorRX <> cRX_MODE Then                ' Are we already in RX mode?
        NRF_SetMode_RX()                            ' No. So set the NRF24L01+ to receive mode
    EndIf
    Clear wPP1                                      ' Clear the inside loop counter
    DelayCS 4                                       ' Delay 4 cycles
    Do
        DelayCS 1                                   ' Delay 1 cycle
        If NRF_IRQ_Pin = 0 Then GoTo _NRF_GetByte_  ' Check for a byte received
        Set WREG
        Addwf PP1,f
        Addwfc PP1H,f
        Addwfc PP7,f
        Addwfc PP7H,f
        If STATUSbits_C = 0 Then Return             ' Exit if timed out (Carry flag clear)
        Incfsz PP1,w                                ' Is the inside counter at $FFFF?
        Continue
        Incfsz PP1H,w
        Continue
        wPP1 = cNRF_TimeoutCycles                    ' Re-Load the inside loop counter
    Loop
#endIfSym   ' __Syscom_Hrsin3_To_Req_

'-------------------------------------------------------------------------------------------
' Read a byte from the NRF24L01+ device
' Input     : None
' Output    : PP0 And WREG hold the Byte read
' Notes     : Replaces the compiler's Hrsin3 and Hserin3 Commands library routine
'
#ifSym __Syscom_Hrsin3_Req_                     ' Include the following code if HRSIn3 or HSerIn3 have been used in the program
__hrsin3__:
    If tMode_TXorRX <> cRX_MODE Then            ' Are we already in RX mode?
        NRF_SetMode_RX()                        ' No. So set the NRF24L01+ to receive mode
    EndIf
    While NRF_IRQ_Pin = 1: DelayCS 1: Wend      ' Wait for a byte to be received
#endIfSym   ' __Syscom_Hrsin3_Req_
'
' Fall through
'
'-------------------------------------------------------------------------------------------
' Helper routine to read a byte from the NRF24L01+ device
' Input     : None
' Output    : PP0 and WREG hold the byte read
' Notes     : None
'
#ifSym __Syscom_Hrsin3_Helpers_Req_     ' Include the following code if HRSIn3 or HSerIn3 have been used in the program
Sub _NRF_GetByte_()
    Save_FSR0 = NRF_wFSR0               ' Save FSR0L\H
    Save_FSR1 = NRF_wFSR1               ' Save FSR1L\H
    NRF_ReadData(NRF_bBuffer)           ' Receive data from the NRF24L01+ device
    NRF_wFSR0 = Save_FSR0               ' Restore FSR0L\H
    NRF_wFSR1 = Save_FSR1               ' Restore FSR1L\H
    WREG = NRF_BufferByte               ' Place the byte received into WREG
    PP0 = WREG                          ' Also place the byte received into PP0
    Set STATUSbits_C                    ' Indicate not timed out (Carry flag set)
EndSub
#endIfSym   ' __Syscom_Hrsin3_Helpers_Req_

'-------------------------------------------------------------------------------------------
' Transmit a byte from the NRF24L01+ device
' Input     : WREG holds teh byte to transmit
' Output    : WREG still holds the byte transmitted
' Notes     : Replaces the compiler's Hrsout3 and Hserout3 commands library routine
'
#ifSym __Syscom_Hrsout3_Req_
Sub __hrsout3__()
    Save_WREG = WREG                    ' Save WREG
    NRF_BufferByte = WREG               ' Place the byte to write into the NRL24L01 buffer
    If tMode_TXorRX <> cTX_MODE Then    ' Are we in transmit mode?
        NRF_SetMode_TX()                ' No. So set the NRF24L01+ to transmit mode
    EndIf
    Save_FSR0 = NRF_wFSR0               ' Save FSR0L\H
    Save_FSR1 = NRF_wFSR1               ' Save FSR1L\H
    NRF_SendData(NRF_bBuffer)           ' Send the byte to the NRF24L01+ device
    NRF_wFSR0 = Save_FSR0               ' Restore FSR0L\H
    NRF_wFSR1 = Save_FSR1               ' Restore FSR1L\H
    WREG = Save_WREG                    ' Restore WREG
EndSub
#endIfSym   ' __SYSCOM_HRSOUT3_REQ_

'-------------------------------------------------------------------------------------------
' Initialise the nRF24L01+ Device
' Input     : None
' Output    : None
' Notes     : Defaults to Receive mode
'
Proc NRF_Init()
    DelayMS 100                                 ' Wait for things to stabilise
    Input NRF_IRQ_Pin                           ' Make the IRQ pin an input
    High NRF_CE_Pin                             ' Set the CE pin high
    NRF_SPI_Init()                              ' Initialise the SPI interface pins
'
' Setup the NRF24L01+ device
'
    NRF_bAddressDataPipe0 = $05, $04, $03, $02, $01

    NRF_WriteRegister(cNRF_CONFIG, $0A)
    DelayMS 10
    NRF_WriteRegister(cNRF_EN_AA, $01)
    NRF_WriteRegister(cNRF_EN_RXADDR, $01)
    NRF_WriteRegister(cNRF_SETUP_AW, $03)
    NRF_WriteRegister(cNRF_SETUP_RETR, $00)
    NRF_WriteRegister(cNRF_RF_SETUP, $0E)
    NRF_hWriteBuffer(cW_REGISTER | cNRF_RX_ADDR_P0, NRF_bAddressDataPipe0, cNRF_PayloadAmount)
    NRF_hWriteBuffer(cW_REGISTER | cNRF_TX_ADDR, NRF_bAddressDataPipe0, cNRF_PayloadAmount)
    NRF_WriteRegister(cNRF_RX_PW_P0, cNRF_PayloadAmount)

    #ifSym __Syscom_Hrsout3_Helpers_Req_
        tMode_TXorRX = cRX_MODE                 ' Set the flag as RX mode chosen
        NRF_Flush_TX()
    #endIfSym
    #ifSym __Syscom_Hrsin3_Helpers_Req_
        NRF_Flush_RX()
        tMode_TXorRX = cTX_MODE                 ' Set the flag as TX mode chosen
    #endIfSym
#endIfSym   ' __Syscom_Hrsout3_Helpers_Req_, __Syscom_Hrsin3_Helpers_Req_
EndProc

'----------------------------------------------------------------------------------------------
NRF_Main:[attach id=3234]nRF2401_Plus.zip[/attach]
$endif      ' _NRF24L01_INC_

asruben

Really very grateful for your answer, now I will review and try to use this information that you provide me, I think there are also many colleagues here who will be interested in using the NRF24L01 module, there is almost no data in Proton Basic, I think that many would benefit from it this information.
Thanks for the reply.