Menu

NRF24L01+ pic16f1825 EXTINT0

Help
2019-07-04
2019-07-21
  • tony golding

    tony golding - 2019-07-04

    hi all,

    i have 2 NRF modules each connected to a 16f1825 on their own breadboards.

    i used the test code provided by william to successfully read and write to the registers for the rf modules and have them setup with matching data in the areas required

    i was able to get the tx to send a single byte to the rx which in turn incremented the pwm value for an led attached to the rx breadboard, however as it was running without interrupts and using basic delays the modules eventually lose sync after a few minutes or less and the rx stops adjusting the pwm value.

    i have been attempting to use the EXTINT0 on PORTA.2 for both modules but i get no luck at all versus my basic and crude initial success, i ddont know whats changed for it to stop working but my interrupt is not firing, im sure i am clearing the NRF irq flag bits in case they cause it to stop until cleared

    i started playing with these around 10pm last night and didnt quit until after 6 this morning when i finally got the initial short lived success of the rx recieving packets but now im stumped as to where to look next.

    NRF configs:

    TX
    
    CONFIG      122 0  1  1  1  1  0  1  0  
    EN_AA       1   0  0  0  0  0  0  0  1  
    EN_RXADDR   1   0  0  0  0  0  0  0  1  
    SETUP_AW    3   0  0  0  0  0  0  1  1  
    SETUP_RETR  3   0  0  0  0  0  0  1  1  
    RF_CH       11  0  0  0  0  1  0  1  1  
    RF_SETUP    8   0  0  0  0  1  0  0  0  
    STATUS      14  0  0  0  0  1  1  1  0  
    OBSERVE_TX  0   0  0  0  0  0  0  0  0  
    RPD         0   0  0  0  0  0  0  0  0  
    FIFO_STATUS 17  0  0  0  1  0  0  0  1  
    DYNPD       1   0  0  0  0  0  0  0  1  
    FEATURE     7   0  0  0  0  0  1  1  1  
    
    RX_PW_P0    0
    RX_PW_P1    0
    RX_PW_P2    0
    RX_PW_P3    0
    RX_PW_P4    0
    RX_PW_P5    0
    
    TX_ADDR 99  99  99  99  99  :  63  63  63  63  63  
    
    RX_ADDR_P0  99  99  99  99  99  :  63  63  63  63  63  
    RX_ADDR_P1  109  109  109  109  109  :  6D  6D  6D  6D  6D  
    
    RX_ADDR_P2  119  :  77
    RX_ADDR_P3  129  :  81
    RX_ADDR_P4  139  :  8B
    RX_ADDR_P5  149  :  95
    
    RX
    
    CONFIG      123 0  1  1  1  1  0  1  1  
    EN_AA       1   0  0  0  0  0  0  0  1  
    EN_RXADDR   1   0  0  0  0  0  0  0  1  
    SETUP_AW    3   0  0  0  0  0  0  1  1  
    SETUP_RETR  3   0  0  0  0  0  0  1  1  
    RF_CH       11  0  0  0  0  1  0  1  1  
    RF_SETUP    8   0  0  0  0  1  0  0  0  
    STATUS      14  0  0  0  0  1  1  1  0  
    OBSERVE_TX  0   0  0  0  0  0  0  0  0  
    RPD         0   0  0  0  0  0  0  0  0  
    FIFO_STATUS 17  0  0  0  1  0  0  0  1  
    DYNPD       1   0  0  0  0  0  0  0  1  
    FEATURE     7   0  0  0  0  0  1  1  1  
    
    RX_PW_P0    0
    RX_PW_P1    0
    RX_PW_P2    0
    RX_PW_P3    0
    RX_PW_P4    0
    RX_PW_P5    0
    
    TX_ADDR 99  99  99  99  99  :  63  63  63  63  63  
    
    RX_ADDR_P0  99  99  99  99  99  :  63  63  63  63  63  
    RX_ADDR_P1  109  109  109  109  109  :  6D  6D  6D  6D  6D  
    
    RX_ADDR_P2  119  :  77
    RX_ADDR_P3  129  :  81
    RX_ADDR_P4  139  :  8B
    RX_ADDR_P5  149  :  95
    

    the code on the pics :

    ; NRF24L01+ Test/Debug Code - WMR
    
     #chip 16f1825, 8  'Go faster later
     #CONFIG MCLRE = OFF
    
     #define RX
    
    'Prevent Serial data being sent during Program DL
     Wait 2 s  'Remove in final code ( or not)
    
     'Software Serial
     #Define SendAHigh Set PORTA.4 ON
     #Define SendALow Set PORTA.4 OFF
     #Define CR 13    'Carriage Return
     #Define LF 10    'Line Feed
     #Define BS 8     'Backspace
     Set PORTA.4 OFF   'Serial TX Idles Low
     Dir PORTA.4 OUT
     InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal
     Sersend 1, BS : Sersend 1, BS 'Backspaces
    
     'NFR24L01 Pins
     #define CE   PORTA.5     ;  Chip Enable
     #define CSN  PORTC.3     ;  CSN or Slave select
     #define NIRQ PORTA.2     ;  IRQ  Interrupt Request
     #Define NRF_VDD PORTC.4
    
     Dir PORTC.5 out
     Dir CE Out : Set CE Off
     Dir CSN Out : Set CSN ON
     DIR NIRQ IN
     DIR NRF_VDD OUT : Set NRF_VDD OFF 'Power to NRF Module
    
     'HSPI Pins - See Datasheet for Pin Assignments
     DIR PORTC.1 IN   'SDI  Pin 14
     DIR PORTC.0 OUT    'SCK1 Pin 15
     DIR PORTC.2 OUT   'SDO1 Pin 16
     'Note:  10K Pullup on NIRQ
     '       10K Pulldown on PIC SDI Pin 14
     SPIMode MasterFast, 0
    
    'NRF24L01+ REGISTERS
     'Preceded Reg name with "NRF" for common names
     #define NRF_CONFIG 0        '0x00   Config
     #define EN_AA 1             '0x01   Enable Auto Ack
     #define EN_RXADDR 2         '0x02   Enabled RX
     #define SETUP_AW 3          '0x03   Setup address width
     #define RETR 4              '0x04   Setup Auto Retr
     #define RF_CH 5             '0x05   RF channel
     #define NRF_SETUP 6         '0x06   RF setup
     #define NRF_STATUS 7        '0x07   Status
     #define OBSERVE_TX 8        '0x08   Observe
     #define RPD 9               '0x09   Received Power Detector
    
     #define RX_ADDR_P0 10       '0x0A   RX pipe0 reg address
                                 '       5 bytes Deep
     #define RX_ADDR_P1 11       '0x0B   RX pipe1 reg address
                                 '       5 bytes deep
     #define RX_ADDR_P2 12       '0x0C   RX pipe2 reg address
     #define RX_ADDR_P3 13       '0x0D   RX pipe3 reg address
     #define RX_ADDR_P4 14       '0x0E   RX pipe4 reg address
     #define RX_ADDR_P5 15       '0x0F   RX pipe5 reg address
     #define TX_ADDR 16          '0x10   TX address
                                 '       5 Bytes deepo
     #define RX_PW_P0 17         '0x11   RX payload width, pipe0
     #define RX_PW_P1 18         '0x12   RX payload width, pipe1
     #define RX_PW_P2 19         '0x13   RX payload width, pipe2
     #define RX_PW_P3 20         '0x14   RX payload width, pipe3
     #define RX_PW_P4 21         '0x15   RX payload width, pipe4
     #define RX_PW_P5 22         '0x16   RX payload width, pipe5
     #define FIFO_STATUS 23      '0x17   FIFO Status
     #define DYNPD 28            '0x1C   Dynamic Payload Length
     #define FEATURE 29          '0x1D   Feature
    
     'NRF24L01+ "COMMANDS"
     #define R_RX_PL_WID 96          '0x60   Read RX Payload width
     #define R_RX_PAYLOAD 97         '0x61   Read RX payload
     #define W_TX_PAYLOAD 160        '0xA0   Write TX payload
     #define W_ACK_PAYLOAD 168       '0xA8   Write RX ACK Payload
     #define W_TX_PAYLOAD_NOACK 176  '0xB0   Write TX Payload NO ACK
     #define FLUSH_TX 225            '0xE1   FLUSH TX FIFO
     #define FLUSH_RX 226            '0xE2   FLUSH RX  FIFO
     #define REUSE_TX_PL 227         '0xE3   Reuse TX payloadd
     #define NOPP 255                '0xFF   No Operation
    'Cannot use "NOP" - NOP Reserved for ASM
     ' ** Radio Configutation Constants (Used in Init) **
    
    ' Alias for Pipes 0 - 5 - Used in Subs
     #Define RX_P0 0
     #Define RX_P1 1
     #Define RX_P2 2
     #Define RX_P3 3
     #Define RX_P4 4
     #Define RX_P5 5
    
    ' Declare Some Variables
     DIM NRF_ADD    ' TMP Variable
     DIM NRF_DATA   ' TMP Variable
     DIM NRF_NUL    ' Dummy Variable
     DIM NRF_TMP    ' TMP Variable
     DIM TMP_0      ' TMP Variable
     DIM TMP_1      ' TMP Variable
     DIM TMP_2      ' TMP Variable
     DIM TMP_3      ' TMP Variable
     DIM TMP_4      ' TMP Variable
     DIM PL_WID      ' TMP Variable
    
     DIM IRQ_STATUS
     DIM IRQ_CLEAR
     DIM IRQ_MASK : IRQ_MASK = b'01110000'
     DIM TX_PAYLOAD : TX_PAYLOAD = 0
     DIM RX_PAYLOAD : RX_PAYLOAD = 0
     DIM LAST_PAYLOAD : LAST_PAYLOAD = 0
    
     #ifdef RX
      Goto PRX
     #endif
    
     #ifdef TX
      GoTo PTX
     #endif
    
    '==========================================================
     PTX:
    
     INTF = 0
     INTEDG = 0
     INTE = 1
     radio_config
     Print_Details
     ON Interrupt ExtInt0 call handle_packet
    
     do
    
     Loop
    
    '==========================================================
     PRX:
    
     INTF = 0
     INTEDG = 0
     INTE = 1
     radio_config
     Print_Details
     ON Interrupt ExtInt0 call handle_packet
     HPWM 1, 1, RX_PAYLOAD
    
     do
    
       if RX_PAYLOAD <> LAST_PAYLOAD Then
         HPWM 1, 1, RX_PAYLOAD
         LAST_PAYLOAD = RX_PAYLOAD
       end if
    
     Loop
    
    '******** Subs Below ***********************
    
     sub handle_packet
    
    ' Read NRF status register for interrut bits to mask and clear
     NRF_READ (NRF_STATUS, IRQ_STATUS)
     IRQ_CLEAR = IRQ_STATUS OR IRQ_MASK
     NRF_WRITE (NRF_STATUS, IRQ_CLEAR)
    
     #ifdef RX
      NRF_READ (R_RX_PAYLOAD, RX_PAYLOAD)
     #endif
    
      #ifdef TX
      TX_PAYLOAD += 1
      WRITE_TX_NO_ACK
     #endif
    
     end Sub
    
    sub radio_config
    
     SET NRF_VDD ON : Wait 200 ms
     SET CSN ON : Wait 10 ms
    
    '*********** Set TX,RX and pipe Addresses *************
    
      TMP_0 = 99 : TMP_1 = 99 : TMP_2 = 99 : TMP_3 = 99 : TMP_4 = 99
    
      Write_TX_ADDR (TMP_0, TMP_1, TMP_2, TMP_3, TMP_4)
      Write_RX_ADDR (RX_P0, TMP_0, TMP_1, TMP_2, TMP_3, TMP_4)
    
      TMP_0 += 10 : TMP_1 += 10 : TMP_2 += 10 : TMP_3 += 10 : TMP_4 += 10
    
      Write_RX_ADDR (RX_P1, TMP_0, TMP_1, TMP_2, TMP_3, TMP_4)
      TMP_0 += 10
    
      for ii = 2 to 5
      Write_RX_ADDR( ii, TMP_0)
      TMP_0 += 10
      Next
    
    '*********** configure radio registers *************
    
      #ifdef TX
       TMP_0 = 122
      #endif
    
        #ifdef RX
       TMP_0 = 123
      #endif
                                   'b'01111010' TX / b'01111011' RX
     NRF_WRITE (NRF_CONFIG, TMP_0)
    ' CRC 2 bytes, mask interupts for now
    '==========================================================
    
     TMP_0 = 1                     'b'00000001'
     NRF_WRITE (EN_AA, TMP_0)
    ' EN_AA pipe 0
    
     TMP_0 = 1                     'b'00000001'
     NRF_WRITE (EN_RXADDR, TMP_0)
    ' Enable RX addr pipe 0
    
     TMP_0 = 11                    'b'00001011'
     NRF_WRITE (RF_CH, TMP_0)
    ' RF Channel 11
    
     TMP_0 = 8                     'b'00001000'
     NRF_WRITE (NRF_SETUP, TMP_0)
    ' 2Mbps air rate, PA -18dbm
    
     TMP_0 = 1                     'b'00000001'
     NRF_WRITE (DYNPD, TMP_0)
    ' Enable dynamic payload pipe 0
    
     TMP_0 = 7                     'b'00000111'
     NRF_WRITE (FEATURE, TMP_0)
    ' enable W_TX_PAYLOAD_NOACK, Enable ACK_PAYLOAD, EN DPL
    
    end Sub
    
    SUB Write_ACK_PL (IN RX_PIPE)
       Set CSN OFF
       SpiTransfer (168+RX_PIPE, NRF_NUL)
    
       For ii = 1 to ACK_PAYLOAD(0)
         SpiTransfer ACK_PAYLOAD(ii), NRF_NUL
       next
       Set CSN ON
    
    END SUB
    
    Sub NRF_READ (in NRF_ADDr, out NRF_DATA)
        set CSN Off
        Spitransfer NRF_ADDr, Nul_var
        Spitransfer 0, NRF_DATA
        set CSN ON
    End sub
    
    Sub NRF_WRITE (in NRF_ADDr, in NRF_DATA)
        Set CSN Off
        Set NRF_ADDr.5 on   'Write bit on
        SPITransfer NRF_ADDr, NRF_nul
        SPITransfer NRF_DATA,  NRF_nul
        Set CSN ON
    End Sub
    
    Sub Write_RX_ADDR (In RX_PIPE, In TMP_0, IN Optional TMP_1 = 0, In Optional TMP_2 = 0,  IN OPtional TMP_3 = 0,  IN Optional TMP_4 = 0)
    
       'Burst Write All 5 Pipe Address Bytes
        SET CSN ON
    
         Select Case RX_PIPE
            Case 0 :  NRF_ADDR = 0x0A + 32
            Case 1 :  NRF_ADDR = 0x0B + 32
            Case 2 :  NRF_ADDR = 0x0C + 32
            Case 3 :  NRF_ADDR = 0x0D + 32
            Case 4 :  NRF_ADDR = 0x0E + 32
            Case 5 :  NRF_ADDR = 0x0F + 32
         End Select
    
        Set CSN OFF
          spitransfer NRF_ADDR, NRF_NUL
          SpiTransfer TMP_0 , NRF_NUL 'ADDR 0  LSB
    
          IF RX_PIPE = 0 OR RX_PIPE = 1 then
             SpiTransfer TMP_1, NRF_NUL 'ADDR1
             SpiTransfer TMP_2, NRF_NUL 'ADDR2
             SpiTransfer TMP_3, NRF_NUL 'ADDR3
             SpiTransfer TMP_4, NRF_NUL 'ADDR4  MSB
          End IF
        Set CSN On
    End SUB
    
    SUB Read_RX_ADDR (RX_PIPE, OUT TMP_0, OUT TMP_1, OUT TMP_2, OUT TMP_3, OUT TMP_4)
        'Sub For debugging Addresses  - Delete in final Code (or not)
        Set CSN OFF
        NRF_ADDR = RX_PIPE + 0x0A
        Spitransfer (NRF_ADDR, NRF_NUL)
        Spitransfer (0 ,TMP_0)
        Spitransfer (0, TMP_1)
        if RX_PIPE = 0 or RX_PIPE  = 1 then
            Spitransfer (0,TMP_2)
            Spitransfer (0,TMP_3)
            Spitransfer (0,TMP_4)
        end if
        Set CSN ON
    End Sub
    
    SUB Read_RX_PL_WID (OUT RX_PL_W)
        Set CSN OFF
        SPITransfer 96, NRF_NUL
        SPITransfer 0, RX_PL_WID
        If RX_PL_W > 32 then
           RX_PLW_ERR = 1
           ' Should Flush RX Buffer Here
           ' Or in Main Code
        Else
           RX_PLW_ERR = 0
        END IF
        Set CSN OFF
    End SUB
    
    Sub Flush_RX_FIFO
         CSN = 0
         SPITransfer (226, nul)
         CSN = 1
    End Sub
    
    Sub Flush_TX_FIFO
         CSN = 0
         SPITransfer (225, nul)
         CSN = 1
    End Sub
    
    Sub Write_TX_ADDR (IN TMP_0, In TMP_1, In TMP_2, In TMP_3, In TMP_4)
        Set CSN OFF
        spitransfer 0x10+32, NRF_NUL
        SpiTransfer TMP_0, NRF_NUL
        SpiTransfer TMP_1, NRF_NUL
        SpiTransfer TMP_2, NRF_NUL
        SpiTransfer TMP_3, NRF_NUL
        SpiTransfer TMP_4, NRF_NUL
        Set CSN ON
    END SUB
    
    Sub Read_TX_ADDR (OUT TMP_0, OUT TMP_1, OUT TMP_2, OUT TMP_3, OUT TMP_4)
       Set CSN OFF
       SpiTransfer 0x10, NRF_NUL
       SPITransfer 0, TMP_0
       SPITransfer 0, TMP_1
       SPITransfer 0, TMP_2
       SPITransfer 0, TMP_3
       SPITransfer 0, TMP_4
      Set CSN ON
    END SUB
    
    Sub NRF_VDD_OFF  'Remove VDD From Module
       Set NRF_VDD OFF
    End Sub
    
    Sub NRF_VDD_ON  'Apply VDD to MOdule
       Set NRF_VDD ON
       wait 10 ms
    End Sub
    
    Sub NRF_RESET
       'Physically Power off / on
       Set NRF_VDD OFF
       Wait 200 ms
       Set NRF_VDD ON
       Wait 200 MS
    END SUB
    
    Sub Print_Details
        'Formatted for Brays Temminal included with GCB
    
        NRF_READ (0, NRF_TMP)
        SerPrint 1, "CONFIG" : Tab : tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
        NRF_READ (1, NRF_TMP)
        SerPrint 1, "EN_AA" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (2, NRF_TMP)
        SerPrint 1, "EN_RXADDR" : Tab
        SerPrint 1, NRF_TMP : TAB
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (3, NRF_TMP)
        SerPrint 1, "SETUP_AW" : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (4, NRF_TMP)
        SerPrint 1, "SETUP_RETR" : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (5, NRF_TMP)
        SerPrint 1, "RF_CH" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (6, NRF_TMP)
        SerPrint 1, "RF_SETUP" : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (7, NRF_TMP)
        SerPrint 1, "STATUS" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (8, NRF_TMP)
        SerPrint 1, "OBSERVE_TX" : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (9, NRF_TMP)
        SerPrint 1, "RPD" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x17, NRF_TMP)
        SerPrint 1, "FIFO_STATUS" : TAB
        SerPrint 1, NRF_TMP : TAB
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x1C, NRF_TMP)
        SerPrint 1, "DYNPD" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x1D, NRF_TMP)
        SerPrint 1, "FEATURE" : Tab : Tab
        SerPrint 1, NRF_TMP : Tab
        SendBits NRF_TMP : CRLF
        CRLF
        wait 20 ms
    
        NRF_READ (0x11, NRF_TMP)
        SerPrint 1, "RX_PW_P0" : TAB
        SerPrint 1, NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x12, NRF_TMP)
        SerPrint 1, "RX_PW_P1" : TAB
        SerPrint 1, NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x13, NRF_TMP)
        SerPrint 1, "RX_PW_P2" : TAB
        SerPrint 1, NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x14, NRF_TMP)
        SerPrint 1, "RX_PW_P3" : TAB
        SerPrint 1, NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x15, NRF_TMP)
        SerPrint 1, "RX_PW_P4" : TAB
        SerPrint 1, NRF_TMP : CRLF
        wait 20 ms
    
        NRF_READ (0x16, NRF_TMP)
        SerPrint 1, "RX_PW_P5" : TAB
        SerPrint 1, NRF_TMP : CRLF
        CRLF
        wait 20 ms
    
        SerPrint 1, "TX_ADDR" : TAB : TAB
        NRF_Print5 (0x10)
        CRLF
        wait 20 ms
    
        SerPrint 1, "RX_ADDR_P0" : TAB
        NRF_Print5 (0x0A) '5 bytes
        wait 20 ms
    
        SerPrint 1, "RX_ADDR_P1" : TAB
        NRF_Print5 (0x0B) '5 Bytes
        CRLF
        wait 20 ms
    
        NRF_READ (0x0C, NRF_TMP)
        SerPrint 1, "RX_ADDR_P2" : TAB
        SerPrint 1, NRF_TMP : SPC
        SerPrint 1, ":" : SPC
        DECTOHEX NRF_TMP
        Sersend 1, Chr1 : Sersend 1, Chr2
        CRLF
        wait 20 ms
    
        SerPrint 1, "RX_ADDR_P3" : TAB
        NRF_READ (0X0D, NRF_TMP)
        SerPrint 1, NRF_TMP : SPC
        SerPrint 1, ":" : SPC
        DECTOHEX NRF_TMP
        Sersend 1, Chr1 : Sersend 1, Chr2
        CRLF
        wait 20 ms
    
        SerPrint 1, "RX_ADDR_P4" : TAB
        NRF_READ (0X0E, NRF_TMP)
        SerPrint 1, NRF_TMP : SPC
        SerPrint 1, ":" : SPC
        DECTOHEX NRF_TMP
        Sersend 1, Chr1 : Sersend 1, Chr2
        CRLF
        wait 20 ms
    
        SerPrint 1, "RX_ADDR_P5" : TAB
        NRF_READ (0x0F, NRF_TMP)
        SerPrint 1, NRF_TMP : SPC
        SerPrint 1, ":" : SPC
        DECTOHEX NRF_TMP
        Sersend 1, Chr1 : Sersend 1, Chr2
        CRLF
        CRLF
        CRLF
    
    End Sub
    
    Sub NRF_Print5(NRF_ADD)
        Set CSN OFF
        Spitransfer (NRF_ADD, NRF_NUL)
        Spitransfer (0,TMP_0)
        Spitransfer (0,TMP_1)
        Spitransfer (0,TMP_2)
        Spitransfer (0,TMP_3)
        Spitransfer (0,TMP_4)
        Set CSN ON
    
        SerPrint 1, TMP_0 : SPC
        SerPrint 1, TMP_1 : SPC
        SerPrint 1, TMP_2 : SPC
        SerPrint 1, TMP_3 : SPC
        SerPrint 1, TMP_4 : SPC
        SerPrint 1, ":" : SPC
        DECTOHEX TMP_0 :  SerSend 1, CHR1 : Sersend 1, CHR2 : SPC
        DECTOHEX TMP_1 :  SerSend 1, CHR1 : Sersend 1, CHR2 : SPC
        DECTOHEX TMP_2 :  SerSend 1, CHR1 : Sersend 1, CHR2 : SPC
        DECTOHEX TMP_3 :  SerSend 1, CHR1 : Sersend 1, CHR2 : SPC
        DECTOHEX TMP_4 :  SerSend 1, CHR1 : Sersend 1, CHR2 : SPC
        CRLF
    
    End SUb
    
    sub dectohex (DATA_TMP)
     'Hex Display Routine
       chr1 = ((Data_TMP / 16) + 48)
       If chr1 > 57 then
         chr1 = chr1 + 7
       End If
    
      chr2 = ((Data_TMP and 15) + 48)
       If chr2 > 57 then
         chr2 = chr2 + 7
       End If
    end sub
    
    Sub SendBits (Data_TMP)
      SerPrint 1, DATA_TMP.7 : SPC
      SerPrint 1, DATA_TMP.6 : SPC
      SerPrint 1, DATA_TMP.5 : SPC
      SerPrint 1, DATA_TMP.4 : SPC
      SerPrint 1, DATA_TMP.3 : SPC
      SerPrint 1, DATA_TMP.2 : SPC
      SerPrint 1, DATA_TMP.1 : SPC
      SerPrint 1, DATA_TMP.0 : SPC
    End SUB
    
    Sub SPC
      SerPrint 1, "  "
    End Sub
    
    Sub CRLF
      SerSend 1, CR
      Sersend 1, LF
    End Sub
    
    Sub TAB
    Sersend 1,9
    End Sub
    

    im hoping someone else can spot anything i missed, i have looked at the NRFa nd pic datasheets so much in the last 24 hours i think ill probably start dreaming about them lol.

    thanks,

    tony

     
  • tony golding

    tony golding - 2019-07-04

    well me being me and not able to switch off the melon i laid in bed for an hour or so thinking about these darn modules and ended up getting back up and trying other things.

    currently now working at 2Mbps with interrupts (which i forgot to unmask after initial play) with enhanced shockburst and just sending tx payload no ack with pic @ 16mhz

    next up is auto acknowledge but that has to wait until later as the wife has to be at hospital for surgery in just over 2 hours but hopefully i can start cleaning up the unnescessary code an get it looking better to progress and hopefully share.

    tony

     
  • kent_twt4

    kent_twt4 - 2019-07-04

    Have you tested if a Slave Node/Pipe comes in and out of range of the Master, and is there a way to resync? If you have an interest, and when you have a chance. All the best with your wife's surgery.

    Had this going once upon a time, but made fatal mistake of saving a good copy. A few changes led to a total break in functionality, and dust now collecting on the nrf24L01+ modules.

     
  • George Towler

    George Towler - 2019-07-05

    however as it was running without interrupts and using basic delays the modules eventually lose sync after a few minutes or less and the rx stops adjusting the pwm value.

    not sure why this would happen, I assume rx is sitting in a loop ( sorry didn't have time to read your code) waiting for tx why would it lose sync?

    I have used these modules a bit, albeit using a different basic, but never need to get ints going (even though I connected to hardware). Also you should play with Ack with payload, then you get two way data without swapping tx and rx (then you realy could lose sync).

     
  • tony golding

    tony golding - 2019-07-06

    hi kent,

    initially i did have the serial output in the ISR to monitor for the carrier detect bit and i did see the bit was set and it was detecting something on the same channel whilst the tx was transmitting and when the tx power was removed and i forced the rx side into interrupt to see serial data it did show the bit was cleared so im happy the rx side was detecting the tx.

    i did some reading on various forums etc through google searches and it seemed the best way to handle resync in case of lost transmission is to have a predefined control channel for each device to know where to go and wait for the other.

    i do intend to look at some form of FHSS and no doubt that would require a predefined control channel for them to both jump to incase of loss of signal or anything else that crops up but thats a little further down the road and for now i have it sending a packet every 10 ms but i will start tidying it up ad seeing how far i can reliably push it.

    as for the wife she is recovering well and should be home saturday morning much to the kids delight, thanks for the well wishes on that kent.

    hi george,

    im not too sure really why it lost sync so randomly in terms of duration but it seems to hold much better now responding to the interrupts well, i did notice in alot of the examples i could find the interrupt feature wasnt used that much either.

    i decided to use interrupts for this as ultimately i will be having alot of other things being done to get the data to send on the tx side and the rx side will be dealing with servos as well as other things so it just adds that bit more freedom for processing time for the tasks as opposed to stopping to poll the state of the device to see whether theres a packet to deal with or an issue with the radio link, once i tidy everything up a bit then i will start using the ACK feature just to add that extra layer of security so to speak

    hopefully i can get some more time with this over the next few days.

    tony

     

    Last edit: tony golding 2019-07-06
  • George Towler

    George Towler - 2019-07-06

    Please don't misunderstand, I'm not saying that you shouldn't implement ints in a real world app, indeed I think it's a great idea.

    Vital that you get simple Ack working so that you can retransmit bad data. Ack with payload is even better.

     
  • tony golding

    tony golding - 2019-07-06

    no thats absolutely fine george, i see lots of others not use interupts and instead poll the registers in a fast loop but then they mostly have minimal to no other tasks to do in between, i guess i was just sharing my thoughts more on why it was essential to get this working with interrupts for my needs so that i can work within a specified time frame between packets to get data continually flowing both ways eventually.

    i had the opportunity last night to spend a few hours rewriting a copy of the working code, my 2 year old decided to wake just after midnight and not fall asleep again until around 04:30 so hey why not make use of the time.

    the revised code is untested as of yet but hopefully i can do that later tonight.

    the original working no ack communication routine has been left alone and now an led has been added to the ccp1 default pin on the tx, simple code to handle dealing with an ack packet on either end plus interupts has been added, as long as this works well then ill change to sending multiple bytes and look at ways to resync any paired devices.

    but for now when the tx sends a byte with an ack packet request the rx copies it to an ack payload packet to send back and the tx applies this to the led on ccp1.

    the code looks good now its cleaned up and it compiles fine so im hoping there isnt too much debugging, hopefully i can get some time to hit the breadboards later tonight.

    tony

     
  • tony golding

    tony golding - 2019-07-07

    well i dont now what the heck is going on with these modules, even if i just slowly send data without ACK requirement the two radios never stay synchronised for any amount of time regardless of any required settings that are equal between devices.

    i just updated my GCB install just in case but im stumped for now so im just going to leave them be as they are becoming very annoying.

    tony

     
  • George Towler

    George Towler - 2019-07-08

    I wish I was able to post code (it caused an upset when I posted non-GCB basic code) to demonstrat just how good these modules are. They are very cheap compared with something like Xbee and there are long range versions available. Of course you always have the option of using simple 433 Mhz modules or even bluethooth.

     

    Last edit: George Towler 2019-07-08
  • tony golding

    tony golding - 2019-07-09

    thats not a problem george, i will just have to wait untiil i can afford to spend alot more time on them to get them working happily.

    i may try the standard interrupt method as opposed to the on interrupt option as im sure this has caused me issues before in other projects in the past where i need to ultimately have lots going on and many different interrupts processed, once my wife has healed fully then i can dive back into it and persist with it until madness sets in lol.

    tony

     
  • George Towler

    George Towler - 2019-07-10

    Looking after the missus comes before playing with pic's. Let me know once she's got the all clear and your ready to tinker some more.

     
  • tony golding

    tony golding - 2019-07-14

    Well the good news is that it appears i finally have success with this pair of NRF24L01+ modules.

    currently they are running at 2Mbps air data rate, 0dbm rf power with auto-ack enabled and an ack payload sent back from the rx to tx which then does what the rx is doing and applies the ack payload to its own pwm output/led, the master is sending a single byte value every 20 ms and both pic's are running at 16Mhz.

    i was worried that these modules were the worst of the worst chinese clones that would not work with auto-ack like some i had read about, but in a sweet little bit of an ironic twist it turned out that putting these aside and playing with some chinese nrf knockoffs AKA beken bk2421 modules i had is what eventually led to these working somehow, the bk2421 is a knockoff of the nrf non + variant and does not have the 250Kbps rate and an extra command in the register for the feature bits but other than that i was able to read and write to registers using the nrf settings.

    i eventually got those working somewhat poorly in auto-ack so changed back to the nrf modules and kept progressing from their, i still had some issues but have made good progress now.

    the modules i have are the tiny smd variants with the trace antenna i dont know what i should be getting range wise but as i understand running 2Mbps air rate does lead to a reduced range LoS and im testing indoors,

    the tx is beside me on the desk, a wireless printer sits a few feet above, the wifi router is about 9 ft behind me, the cable box is about 6 ft ftrom that and its wireless.

    i added an led to indicate when the MAX_RT int fired to get an idea of when the rf chip timed out trying to get an ack back from the rx and with all the rf traffic within close proximity supprisingly it barely changes state unless i deliberately try to shield the module.

    the rx is in the kitchen, through one wall about 20ft away, directly above the kitchen are two of my kids bedrooms, both have wireless cable boxes and one xbox thats mostly on so alot of wireless activity coming from the back end of the house too where the rx is listening and still im getting good data transfer it seems.

    i stil need to go battery power on both and see how the range does outdoors and then maybe go down to 250Kbps rate with a timer set and manually send a payload back from rx to tx as that feature is lost at the lower rate.

    i am currently tidying up the codes for each module and will post it soon.

    it seems that auto_ack and ack_payload were causing other users on other micros issues as well but im just glad its working now and working backwards to the slower rates without ack's for range increase should be a bit more straightforward ( i hope ).

    i still need to do a simple sync routine but for now if i remove power to either one they do seem to find each other and carry on with their thing .

    tony

     
  • George Towler

    George Towler - 2019-07-15

    Yipee, you must try the module with the amp and whip ariel.

     
  • tony golding

    tony golding - 2019-07-21

    i have some new modules on order now, i think my son was intrigued by the pulsing led on both boards and grabbed one or both of them and shorted out one of the modules

    i have ordered a selection of the modules with power amplifiers and some with ipex connectors to use external antennas, im still convinced the cheap modules i had were no doubt fakes but have ordered some from a seller whose modules come highly rated as being genuine and great quality but we shall see

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.