Using NRF24L01+ with pure assembler programing

Dear people

I have connected NRF24!01+ with PIC16F1826 for use as PRX and have also another similar for PRX

For an initial test I tryed to trasmit a closed / open switch state to a LED and as ussually hapens it does not work

Also I have a Tx packets each 200ms with one Data byte incremented in each Tx
I get SPI write an read ok but at PRX have not getting any received packet

There is the same program for PTX an PRX with  #define    PRX  o rnot at compiling so most of defined values are the same

What I get reading with SPI : in PRX , Reg 0x17 FIFO_STATUS  bit4 TX_EMPTY:
 is 1 before loading data
0 after loading payload   (4 bytes)
1 after CE goes H

At PRX side  not IRQ arises , not changes in Reg 07 bit RX_DR

I only use assembler programming and I didn´t found in the web any complete and working assembler example.

--> I am asking please the simplest example with a detailed list of commands to send for configuring and useing TPX
and PRX, similar at Appendix B, pag 77 in NRF24L01+ data sheet.

*** But please include the waiting delays and other instructions that may be  needed ***

For some address, default values may be used in a first test ? ( only 1 Pipe )

Is it posible not  using CRC ?

I need to have something working before going to a complete use of full NRF24L01+ capabilities

Finally I will insert well tested software in bigger assembler programs

I like to  replace a RS485 conexion with this RF link

I will1452.Control_NRF.rar send the assembler that I am testing if somebody like to see it, but RF part is not working

Waiting some help, Best Regards, Osvaldo Hojvat

  • Hi  Torbjørn

    I will apply your last sent information.  I need to adquire some experience before next steps

    We are a two people team makeing electronics parts for Ferromodelism - Model railroad

    My final target is to replace actual cable connection with Rx links, for a Central unit that may be  connected to several handheld controls, using RS485 serial cables.

    Most of the time, the central unit send a call byte with the address of one control, wait 130us and if it is not a reply, it send a call with the following address of a control is sent.

    I will replace it by NRF24L01+  using all the automaric features available.

    I am making some simple tests before incorporate the RF part  to  the program of the Control units, PTX

    I will place the PRX part in a special interfase that keeps updated information of controls and Central unit, and to convert RF Tx/ Rx data with the required timing.

    One interfase for up to 6 controls.  Usually no more that one or two controls will be connected

    As data to be send from controls will be a result of a keyboard switch pressing, I expect it will be not a problem for the posibility than more than one control may Tx Data at the same time.

    After the present initial test, I will use the enhanced shock burst in a new test  as a second step.

    I will post resulting assembler when it works well.

    Best Regards, Osvaldo

  • Last news - working OK the corrected test program.

    With your instructions added, I get an uniform Tx / Rx Data trasmition.

    I am trasmiting a four data packet but the first one is incremented after each tx packet

    in PTX  I have one led as a negated copy of TxFIFO_Status bit4 (Tx fifo EMPTY)

    With some delays added there is a rate of about 4 Tx packets/ second , LED flashing  at this rate.

    In PRx board, there are one led connected at IRQ line ( tied to Vd) that flashes each received packed

    Two processor pins have copy of Received Data 1,  bits0 and one

    They show a uniform count following tx / rx packets rate

    Later I will post a list of NRF settings , commands used and also the assembler for the test

    -------------------------------------------------------------------

    Next I will  try adding ack and ack with pay load

    Best  Regards, Osvaldo

  • ;Short test program for Tx / Rx following Torbjørn instructions (from Nordic Forum)
    ;I have selected the procesor pins in order to keep posible USART pins free for next proyect step
    ;Procesor PIC16F1826    ( = PIC)
    ;Transceiver NRF24L01+ ( = NRF)         PTX = RF tx mode     PRX = RF rx mode
    ;Using default values at most NRF registers for low instructions count 
    ; RA4 pin open -> PTR mode   no interruptions
    ; RA4 to GND  ->  PRX mode   - IRQ used     ( the same program forboth modes )
    
    ; PIC definitions 
    ; INTERNAL OSCILLATOR 16MHZ
    ; SERIAL DATA OUT (MOSI): RA6      ; 
    ; SERIAL DATA IN (MISO):  RB1     ;
    ; SERIAL SPI CLOCK:  RB4 - 4MHz
    ; SPI  MASTERMODE for procesor  
    ; RB0 USED AS INPUT TO ENABLE INTERRUPT ON CHANGE (HIGH TO LOW) AND CONNECTED TO TRASCEIVER IRQ for use as TRP
    ; CSN - NRF SPI enable: RA7 
    ; CE  NRF24L01+ RF enable (data sheeet states: less than 4ms ON in Tx mode)
    
    ; Subrutines used for SPI
    ; sendSPI  - send WREG value to NRF - iniciate and wait 8 SPI CLK - return with banco0
    ; receiveSPI  - iniciate and wait 8 SPI CLK - return with banco0 and SPI received value in WREG (fron NRF)
    ; delay10u  - 10us
    ; delay1m   - 1ms
    ; delay200m - 200ms
    
    
    #define 	banco0	movlb	0     ; 
    #define 	banco1	movlb	1     ; OSCON - OPTION
    #define 	banco2	movlb	2     ; APFCON   (some inputs/outputs can be moved between default pin to other one )
    #define 	banco3	movlb	3     ; usart
    #define 	banco4	movlb	4     ; SPI
    
    #define		CSN		PORTA,7	
    #define     CE		PORTA,0
    #define     PTXsel	PORTA,4     ; 0 = PRX  mode ;  1 = PTX  mode
    #define	    LED 	PORTA,2   ; PTR shows tx fifo not empty  -  PRX shows rx fifo with data
    ;#define 
    ;#define 
    ;#define 
    ;#define 
    ;#define 
     CBLOCK 	0x20    
      Reg1      ; for delay subrutines 
      Reg2      ; 
      Reg3      ;
    
      RxDATA1 
      RxDATA2 
      RxDATA3 
      RxDATA4 
    
      TxDATA1 
      TxDATA2 
      TxDATA3 
      TxDATA4   
     ENDC
    
     CBLOCK 	0x70    ; access from any bank
      Arg0   
      Arg1   
      Arg2   
      Arg3   
      Arg4   
      Arg5
      Arg6
      Arg7
      Flg 
     ENDC
     
    
            list    p=16F1826,  r=hex   
            INCLUDE P16F1827.INC    ;  F1826,INC  is not present in MPLAB
    
    	__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    	__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_HI & _LVP_OFF     ; en el .INC ,     _BORV_19 = _BORV_LO es el trip point bajo   _HI alto
    
    
                       ORG 00
    
                  GOTO START
    
    ;;;INT      ; not using INT for this test 
    ;;;	clrf	BSR
    
    ;;;retfie
    
                       
    START         ;     
           ;   no poner dalay antes de ajustar oscilador  
          
    ; PIC initialize
      BANKSEL		TRISB
                       movlw    B'00000111' ; SETTING PORTB ACCORDING TO SPI, RB0 IS INPUT TO ENABLE TRANSCEIVER IRQ
                       movwf    TRISB  ;RB1 MISO   RB2  para Rx de 485 
    		   		movlw    b'00010010'    ; tecla a GND en RA1 - pongo 10k a +5  - puente a GND para modo TRX
    		   		movwf    TRISA           ;bit5 de MCLR no se baja- teclaa RA1 - LED en salida RA2
    			movlw	b'01111010'    ; para 16M
    			movwf	OSCCON					
    			movlw	b'10000100'    ;con pull-up (ver def. individuales) ; RB0 = 0 INTERRUPT HIGH TO LOW EDGE = bit6
    			movwf	OPTION_REG   ; presc 1/32 para TMR0 ( ver si lo uso) 
      BANKSEL PORTB           
                      MOVLW B'00000000'   
    		  MOVWF	PORTB    
                      MOVLW B'10000000'   
    		  MOVWF	PORTA    ; para CSN en alto 
    		BANKSEL ANSELA 
    		clrf	ANSELA
    		clrf	ANSELB
      BANKSEL  SSP1STAT                     ; tested at, 4MZ also works with SMP = 0
                       MOVLW B'01000000'      ;;; SMP= 1   CKE = 1     ( smp = bit 7 11000000)
                       MOVWF SSP1STAT
                       MOVLW B'00100000'     ; frecSPIclk = fosc/4 = frec instruccion -> 4M  for 16M-osc            
                       MOVWF SSP1CON1            ; bit4 CPK = 0    mode 0,0   smp = 1 
                       MOVLW B'10010000'
      BANKSEL  APFCON0    ; banco2
     			movlw   b'11000000'     ;  RA6 MOSI  
     			movwf	APFCON0         ; (bit7) Tx  USART  RB2 -> RB5
     			movlw   1               ; Rx del USART  RB1 -> RB2
     			movwf	APFCON1
      banco0
    ;;;			movlw	b'10010000'    ; GIE  INTE   - PRX  uses IRQ  falling level
    ;;;		btfsc	PORTA,4      ; to GND -> PRX
    			movlw	0       ; open -> PTX
    			MOVWF INTCON ; for this test I will use poling RIRQ  ;;;  ENABLE GLOBAL INTERRUPTS + RB0 EXTERNAL INTERRUPT IN
          
     clrf	 RxDATA1
     clrf	 RxDATA2
     clrf	 RxDATA3
     clrf	 RxDATA4
     clrf	Arg0  
     clrf	Arg1  
     clrf	Arg2  
     clrf	Arg3  
     clrf	Arg4  
     clrf	Arg5
     clrf	Arg6
     clrf	Arg7  
     clrf	Flg
      movlw	1
    movwf	TxDATA1	    ; for tests
     movlw	2	
    movwf	TxDATA2
     movlw	3
    movwf	TxDATA3
     movlw	4
    movwf	TxDATA4
    
    call	delay40ms   ; algo mas de 100ms  para el power-on del modulo NRF
    call	delay40ms 
    call	delay40ms 
    
    btfss	PORTA,4      ; to GND -> PRX
    goto	PRX
    
    ; NRF24L01 *************************** reference:  data sheet- commands table 20 page 51 and registers  9.1 page 57 ******************
    
    ; PTX:    -   IRQ is enabled but not used in PTR
    ; 1) Set the PWR_UP bit in the CONFIG register     -  
    				bcf CSN       				 ; Open NRF SPI
                       MOVLW B'00100000'         ; write reg 0 - CONFIG    (command 001aaaaa = write to aaaaa register 
                       CALL SEND    
                       MOVLW B'01010010'         ;bit5 low: IRQ for Tx send,  POWER_ON   ; no CRC , PTX mode
                       CALL SEND            
    				bsf CSN                      ; close SPI
    ; optional confirm CPNFIG value
    	movlw	0			
    	call	read_Regx
    	movwf	Arg0
    	
    ; necessary ??? disable auto-ack - uso tx sin ack ( o con ack, a mi gusto)
    ;;				bcf CSN       				 ; Open NRF SPI
     ;;                  MOVLW B'00100001'         ; write reg 1 -  EN_AA
     ;;                  CALL SEND    
    ;;                   MOVLW 0         ;
    ;;                   CALL SEND            
    ;;				bsf CSN                      ; close SPI	
    	
    ; -----   2)  3) are the same for
    ; -----   2)  3) are the same for  PTX and PRX    
    ; 2) Set DYNPD to 0x3F   
    				bcf CSN       				 ; 
                       MOVLW B'00111100'         ; write reg 1C - DYNPD    - b'00111100' = (0x20 + 0x1C)
                       CALL SEND    
                       MOVLW B'00111111'         ; dynamic PD all channels
                       CALL SEND                 ; 
    				bsf CSN
    
    ; 3) Set the EN_DPL bit in the FEATURE register
    				bcf CSN       				 ; 
                       MOVLW B'00111101'         ; write reg 1D - FEATURE   - b'00111101' = (0x20 + 0x1D)
                       CALL SEND    
                       MOVLW B'00000101'         ; dynamic PD  and EN_DYN_ACK enabled ; para tx sin ack 
                       CALL SEND                 ; 
    				bsf CSN
    ;optional ? .............. flush tx fifo ..................
    	bcf CSN	
    	    movlw	0xE1   ; b'11100001'
    	    call	SEND
    	bsf CSN		
    								
    ; 4) Upload a payload
    new_payload:
     ; optional ..............   
        		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg1   ;   before load  bit4 EMPTY must be = 1  empty
    	btfss	Arg1,4
    	bsf LED	; PORTA,2   ; a negated copy of Tx fifo EMPTY
    	btfsc	Arg1,4
    	bcf LED	; PORTA,2   ; led O = tx fifo with data
    ;...............
    		bcf CSN   ; habilito SPI para cargar datos en TX FiFO
    					movlw	0xB0       ;B0 es tx sin ack comando tx payload0 xA0
    					call	SEND
    					movf	TxDATA1,w    
    					call	SEND
    					movf	TxDATA2,w
    					call	SEND
    					movf	TxDATA3,w
    					call	SEND
    					movf	TxDATA4,w
    					call	SEND   
    			    bsf CSN	
    
    ;Optional:  read and check fifo status 
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg2   ;             bit4 EMPTY must be = 0  not empty
    	btfss	Arg2,4
    	bsf LED	; PORTA,2   ; a negated copy of Tx fifo EMPTY
    	btfsc	Arg2,4
    	bcf LED	; PORTA,2   ; led O = tx fifo with data
    ; 5) Pulse CE for 10 us   ******* DO NOT PLACE BREAKPOINTS HERE    ********
    retry:  
    				bsf	CE
    				call	delay10us
    				call	delay10us  ; minimum 10us
    				bcf	CE
                      ; ***************  TX Rf 4MS MAXIMUN ***********************
    ;Optional:  read and check fifo status  130us for rf iniciate?
       call delay10us	; tx 4 bytes needs 40us at 1MHz rate -> for tx FIFO empty
       call delay10us      ;NEEDS MORE TIME - time for next read is added to a more sure value
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg3  ;  after tx the data bit4 txbuf EMPTY must be = 1 empty
    	call	delay1ms    ; at  40us fifo not emty - after 1ms yes
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg4  ;  after tx the data bit4 txbuf EMPTY must be = 1 empty
    	btfss	Arg4,4
    	bsf LED	; PORTA,2   ; a negated copy of Tx fifo EMPTY
    	btfsc	Arg4,4
    	bcf LED	; PORTA,2
    
    	; optional ????............ clr tx  IRQ ..............
     	
    		call	read_status
    		movwf	Arg5		
    		
    	bcf CSN	
    	    movlw   0x27	; b'00100111' write to STATUS reg.
    		call	SEND   ;  
    	movlw	b'01110000'	; clr all interrupts flags
    		call	SEND	
    	bsf CSN                ; 56us from CE rise 
    		call	read_status    ; CSN inside
    		movwf	Arg6		; 72us from CE rise
    	
    		btfss	PORTB,0
    		nop		
    		btfsc	PORTB,0
    		nop
    	
    ; ......................................
    	
    		call	delay40ms
    
    btfss	Arg4,4   ; if tx FiFO not  empty, do not load again
    goto retry		
    
    	incf	TxDATA1,f    ;  modified data for next packet trasmition	
    ; 6) Add a delay (1ms+) and repeat from 4)
    	call delay200ms
    
    goto	new_payload
    
    ;;; goto	moreProgram
    ;****************************************************
    	; ; below - PRX 
    ;****************************************************
    
    PRX:
    ; 1) Set the PWR_UP bit and PRIM_RX bits in the CONFIG register     -  
    		bcf CSN       				 ; Open NRF SPI
                MOVLW B'00100000'         ; write reg 0 - CONFIG    (command 001aaaaa = write to aaaaa register 
                CALL SEND    
                MOVLW B'00110011'         ;Bit6 low: IRQ for Rx received,  POWER_ON   ; no CRC , PRX mode
                CALL SEND            
    		bsf CSN                      ; close SPI
    
    ; optional confirm CPNFIG value
    	movlw	0			
    	call	read_Regx
    	movwf	Arg0
    	
    ; necessary ??? disable auto-ack  mejor lo dejo y uso tx sin ack ( o con ack, a mi gusto)
    ;				bcf CSN       				 ; Open NRF SPI
     ;                  MOVLW B'00100001'         ; write reg 1 -  EN_AA
     ;                  CALL SEND    
    ;                  MOVLW 0         ;
     ;                  CALL SEND            
    ;				bsf CSN                      ; close SPI	
    	
    ; -----   2)  3) are the same for  PTX and PRX
    ; 2) Set DYNPD to 0x3F
    				bcf CSN       				 ; 
                       MOVLW B'00111100'         ; write reg 1C - DYNPD    - b'00111100' = (0x20 + 0x1C)
                       CALL SEND    
                       MOVLW B'00111111'         ; dynamic PD all channels
                       CALL SEND                 ; 
    				bsf CSN
     
    ; 3) Set the EN_DPL bit in the FEATURE register
    				bcf CSN       				 ; 
                       MOVLW B'00111101'         ; write reg 1D - FEATURE   - b'00111101' = (0x20 + 0x1D)
                       CALL SEND    
                       MOVLW B'00000101'         ; dynamic PD  enabled y para tx sin ack
                       CALL SEND                 ; 
    				bsf CSN
     ;optional
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg2   ;             bit0 EMPTY must be = 1 empty
     ;optional
    		call	read_status
    		movwf	Arg5		
    		nop
    
    ; 4) Set CE high
    		bsf		CE    ;  set RF  ON  for Rx
    
    ; 5) Wait for the IRQ line to go low   ; no used INT for this test 
    rx_wait:
    		btfss	PORTB,0
    ;;;loop extended to some lines below;	goto	rx_wait
    
    ; 6) Read out the RX payload  ( IRQ low )
    		call	readPayload ;;goto
    ; 7) Repeat from 5) 
    	call	delay1ms     ; read more frecuently than Tx send 
    	;;	bcf	LED ; PORTA,2   ; 
    ;	call	delay40ms
    ;goto	rx_wait
     ;optional
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg3   ;             bit0 EMPTY must be = 1 empty
     goto	rx_wait
    ; required ? flush rx fifo   :+++++  empeora ++++++
    ;;	bcf CSN	
    ;;	    movlw	0xE2   ; b'11100010'
    ;;	    call	SEND
    ;;	bsf CSN
    ;goto	rx_wait
     ;optional
    		call 	read_fifo_status	  ;  readed value in WREG
    		movwf	Arg4   ;             bit0 EMPTY must be = 1 empty
    ;;;goto	rx_wait
    
    ;optional
    	call	read_status
    	movwf	Arg6		
    	
    ; reset IRQ to 1  in the subrutine		
    				
    goto	rx_wait
    
    ; ***************** main program end ***** subrutines below **********
    ;............................................................
    ; -----------------------------------------------------------------
    
    ;************************* Subrutines ******************************
    
    readPayload      ;; no INT for this test ;banco0     ;only for PRX
    ;optional	
    ;;	bsf	LED	; PORTA,2   ; 		
    call	delay1ms   ; may be not needed
    	call read_status
    	movwf	Arg5
                bcf CSN	
                       MOVLW B'01100001' ;0x61 Comando SEND REQUEST READ PAYLOAD - en pag 51 el tercer comando
                       CALL SEND
                    CALL RECEIVE		; get SPI data
                      MOVWF RxDATA1   ; lee 4 datos manteniendo CSN en bajo
                    CALL RECEIVE
                      MOVWF RxDATA2
                    CALL RECEIVE
                      MOVWF RxDATA3
                    CALL RECEIVE
                      MOVWF RxDATA4                  
                bsf CSN			; cierra el /CS luego de leer 6 datos	  
        ;;;;;;;    BCF INTCON,INTF ; CLEAR RB0 INTERRUPT FLAG    bit1
    	nop
    	nop
    	bcf CSN
    	    movlw	b'00100111'	;  0x27 escribo en STATUS
    		call	SEND
    	    movlw	b'01110000'  ;clear flags  ;     pongo 1 en bit6 => borra flag RDb'01000000'
    		call	SEND
    	bsf CSN 
    ; show RxDATA1  counting
    	btfss	RxDATA1,0	
    	bcf LED
    	btfsc	RxDATA1,0	
    	bsf LED
    	
    	btfss	RxDATA1,1	
    	bcf PORTA,3
    	btfsc	RxDATA1,1	
    	bsf PORTA,3
    	return	        ; RETFIE
                       
       ; -----------------------------------------------------------------
    
    SEND: 	  ; procesor SPI send WREG value to NRF
      BANKSEL SSP1STAT
                       MOVWF SSP1BUF ; MOVE BYTE TO W REGISTER BEFORE CALLING
    ;;;..........  wait 8 clk ........
                       BTFSS SSP1STAT,BF ; POLL RECEIVING COMPLETE
                       GOTO $-1
    ;;;;.......................................
      BANKSEL PORTB
                       RETURN
    
    ;*************************************
    
    RECEIVE:    ; procesor receive SPI data from NRF
        BANKSEL SSPSTAT     ;  data was send by SPI before this sub.
    				clrf	SSP1BUF   ; con cargar o borrar este registro inicia 8 clk
    ;;;..........  wait 8 clk ........
                       BTFSS SSP1STAT,BF ; POLL RECEIVING COMPLETE
                       GOTO $-1
    ;;;;.......................................
    			MOVF SSP1BUF,W   ; received SPI data in WREG
      BANKSEL PORTB
                       RETURN
    
    ; *********************************************************
    
    
    
    
    
    ;------------------------ delay  subs ------------------------------------------
    
    delay200ms: movlw .0   ;   
                movwf Reg1
                movlw .16     
                movwf Reg2
                movlw .5
                movwf Reg3
                decfsz Reg1,F
               goto $-1
                decfsz Reg2,F
               goto $-3
                decfsz Reg3,F
               goto $-5
                nop
            RETURN
    ; ---------------------------------------------------
    
    delay40ms:  movlw	.202  ; 
                movwf	Reg1
    	    movlw	    .208     ;  40ms    
                movwf	Reg2            
                decfsz Reg1,F
    		  goto $-1
                decfsz Reg2,F
              goto $-3           
          return      
    
    ; ---------------------------------------------------
    
    delay1ms:  movlw	.60  ;
                movwf	Reg1
    	    movlw	    .6   ;   1ms        
                movwf	Reg2            
                decfsz Reg1,F
    		  goto $-1
                decfsz Reg2,F
              goto $-3           
          return      
    
    ; ----------------------------------------
    
    delay10us: movlw	.13   ; 10us  + 1us for call/return
    			movwf	Reg1
                decfsz Reg1,F
            	goto $-1           
          return      
    
    ;;**************  subs for debug  ****************
    
    read_fifo_status:     ; lo puse para debug - se puede usar en Tx y en Rx
    	bcf	CSN ; PORTA,7
    		movlw	0x17 ; 	(para lectura de un registro no sumar 0x20)
    		call	SEND	
    		    CALL RECEIVE
    	bsf	CSN
    		    return   ; valor leido en w y está en banco0
    ;--------------------------------
    		    
    read_status:     ; lo puse para debug - se puede usar en Tx y en Rx
    	bcf	CSN ; PORTA,7
    		movlw	0x7 ; 	(para lectura de un registro no sumar 0x20)
    		call	SEND	
    		    CALL RECEIVE
    	bsf	CSN
    		    return   ; valor leido en w y está en banco0
    ;---------------------------
    read_Regx:     ; lo puse para debug - se puede usar en Tx y en Rx
    	bcf	CSN ; PORTA,7
    	; usa el valor en  w  ; (para lectura de un registro no sumar 0x20)
    		call	SEND	
    		    CALL RECEIVE
    	bsf	CSN
    		    return   ; valor leido en w y está en banco0
    		    
    ;----------------------------
    
    
    
    END               
        
        
    

    List of SPI commands needed for NRF24L01+       RF link working OK

    The regarding assembler is also attached

    With dynamic payload , no ack

    After procesor settings, with SPI at 4MHz:

    ------------------ For PTX --------------------------------

    Write Reg. Config(0) - value 01010010  ; Tx IRQ mask / no CRC /power on / PTX mode

    Write Reg. DYNPD(0x1C) - value 00111111 dyn. payload all channels

    Write Reg. FEATURE (1D) -  value 00000101   EN_DPL

    command:  flush tx fifo (0xE1) ; opcional

    ; loop
    new_payload:         ; Upload a payload
     
    command   tx payload , no ACK (0xB0)
    load 4 TxDATA bytes before CNS goes high   

    retry:

    Set CE High  - RF = ON
    wait 20us
    Set CE Low  - RF go OFF when all the packet is sent

    wait 1ms
    ; reset IRQ line  - clear any posible flag  (but IRQ not used in PTX)
    command: 0x27 write STATUS(reg07) value 01110000

    read FIFO_STATUS
    Test bit4 Tx fifo EMPTY
    If no empty, goto retry

    ; Packet wass ent
        incf    TxDATA1,f    ;  modified data for next packet trasmition    
    ; Add a delay and repeat new_payload
        wait    200ms  ; (minimum 1ms)

    goto    new_payload  ; loop rate 4 times/ second
                              
     --------------------- for PRX ----------------

    Write Reg. Config(0) - value 00110010  ; Set bits for: Rx IRQ mask, PWR_UP  and PRIM_RX in the CONFIG register , no CRC  , PRX mode

    Write Reg. DYNPD(0x1C) - value 00111111 dyn. payload all channels

    Write Reg. FEATURE (1D) -  value 00000101   EN_DPL

     Set CE High  ; set RF  ON  for Rx

    rx_wait:
    test    IRQ line = low ?

    if low: call readPayload  ; in the subrutine: command 0x27 (write STATUS) value 01110000
                              ; so RX_RD bit is cleared and IRQ line goes HIGH

    ;  if IRQ is high , do not read
         wait 1ms
         goto rx_wait

  • Hi 

    So everything is working fine?

    Please note that with the CRC check disabled there is a risk that you will receive packets with incorrect data, caused by bit errors in the payload. 

    With CRC enabled any packet with a bit error will be discarded, and if you have ACK and retransmits enabled the packet will be sent again. 

    Best regards
    Torbjørn

  • Thank you for your reply

    A wished to have at first some rf link working

    I make a litle more advance and added ACKand ACK + payload and it is also working

    At the end there is list of wht I had modifyed and added.

    Now I will begin with the complete system programms.

    Please comment about the following matters:

    - I guess dynamic payload  also applies to the ack payload length,

    and the Tx FIFO need to be loaded before receiving the packet    Please confirm

    - If there are Tx from two PTX devices at the same time, I guess no one will be received OK

    I think it may be needed to use diferent ARD in each PTX for avoiding the same problem in the retry

    -  I need in a big room a 15m secure link ,  Is it convenient to use 250 Kb rate or 1 Mb rate is OK ?

    The RS485 cable rate is 57600K and not too busy,  so with 250K and a processor (with buffers)  in the Rf to 485 conversion I estimated they will be no a rate problem.

    - At the RX unit, as it will have a power supply cable I can use a board with amplifier and external antena if it is necessary or the simplest available board may be OK ?

    Best Regards, Osvaldo

    -------------------- added/ modified  for  test  with ack_payload ----------------------------------

    PTX

    CONFIG   01011010    (CRC enabled, 1 byte)

    FEATURE    00000111

    Data upload with command 0xA0

    wait 1ms and read Rx FIFO for payload received with ack

    ----------------------------------------

    PRX

    CONFIG   01011011

    FEATURE    00000111

    At the end but inside of  rx_wait  loop
    Data upload with  command   10101000 (pipe number 0) for ack payload
    data value selected by a switch
    data = 0  if   PORTA,1 tied to Vcc
    data =  1111111  if   PORTA,1 tied to GND

    ---------------------------------------------------------------------

Related