pic16f877, picbasicpro, mirfV2, can someone proof my code?

Ok, I have done my homework. This is my"I’m Learning" setup, of which when I get it working, I will be able transmute the code into a bigger system I am working on. I have a sender pic16f877 with a switch for sending a single payload to a pic16f877 receiver. I have the SPI code working where I know that the pics are talking to the MirfV2’s. I have verified this with my HobbyLAB PC Oscillo/Logic anaylizer. My goal is real simple in this code: send 5 bytes and receive 5 bytes. I have been working on this since january…had to teach myself SPI…and doing it on about 5-10 hrs/week. Been through much frustration and success (with SPI), but I am sure that all i need is a few tweeks for probably obvious reasons.

ANY HELP!! would be much appreciated!!

THnx in Advance

Harold G. :?:

Here’s the code:

SENDER:

'****************************************************************

'* Name : MirfTransT2.BAS *

'* Author : Harold Goodrich *

'* Notice : Copyright (c) 2008 Harold Goodrich *

'* : All Rights Reserved *

'* Date : 4/2/2008 *

'* Version : 1.0 *

'* Notes : *

'* : *

'****************************************************************

define OSC 10

INCLUDE “modedefs.bas”

spin VAR PORTD.6

LED VAR PORTD.2

LED1 VAR PORTD.3

TRISD.2=0

TRISD.3=0

TRISD.6=0

low LED

low LED1

i VAR BYTE 'loop counter

ThisReg var byte

ThisCmd var byte

Temp var byte

RecData var byte[4]

SendData var byte[4]

'Mirf Config

REG_CONFIG var byte

REG_CONFIG=%00000000

PRIM_RX var REG_CONFIG.0

PWR_UP var REG_CONFIG.1

CRC0 var REG_CONFIG.2

EN_CRC var REG_CONFIG.3

R_REG_CONFIG con %00000000

W_REG_CONFIG con %00100000

REG_EN_AA var byte

REG_EN_AA = %0011111

ENAA_P5 var REG_EN_AA.5

ENAA_P4 var REG_EN_AA.4

ENAA_P3 var REG_EN_AA.3

ENAA_P2 var REG_EN_AA.2

ENAA_P1 var REG_EN_AA.1

ENAA_P0 var REG_EN_AA.0

R_REG_EN_AA con %00000001

W_REG_EN_AA con %00100001

REG_EN_RXADDR var byte

REG_EN_RXADDR=%0000000

ERX_P5 var REG_EN_RXADDR.5

ERX_P4 var REG_EN_RXADDR.4

ERX_P3 var REG_EN_RXADDR.3

ERX_P2 var REG_EN_RXADDR.2

ERX_P1 var REG_EN_RXADDR.1

ERX_P0 var REG_EN_RXADDR.0

R_REG_EN_RXADDR con %00000010

W_REG_EN_RXADDR con %00100010

REG_SETUP_AW var byte

REG_SETUP_AW=%00000011

R_REG_SETUP_AW con %00000011

W_REG_SETUP_AW con %00100011

REG_SETUP_RETR var byte

REG_SETUP_RETR=%00000011

'ARD: 7:4 250Us each increment

'This is the time the PTX is waiting for an ACK packet before a retransmit is made. The PTX is in RX mode

'for a minimum of 250?S, but it stays in RX mode to the end of the packet if that is longer than 250?S. Then

'it goes to standby-I mode for the rest of the specified ARD. After the ARD it goes to TX mode and then

'retransmits the packet.

'ARC 3:0 retry count 0 to 15, 0 is disabled

R_REG_SETUP_RETR con %00000100

W_REG_SETUP_RETR con %00100100

RF_CH var byte

RF_CH=%00000010

R_REG_RF_CH con %00000101

W_REG_RF_CH con %00100101

REG_RF_SETUP var byte

REG_RF_SETUP=%00001111

LNA_HCURR var REG_RF_SETUP.0 'gain

'RF_PWR 2:1, 11=0db, 10:-6db, 01:-12db, 00:-18db

R_REG_RF_SETUP con %00000110

W_REG_RF_SETUP con %00100110

REG_STATUS var byte

REG_STATUS=%00001100

RX_DR var REG_STATUS.6

'The RX_DR IRQ is asserted by a new packet arrival event. The procedure for handling this interrupt

'should be: 1) read payload through SPI, 2) clear RX_DR IRQ, 3) read FIFO_STATUS to check if there

'are more payloads available in RX FIFO, 4) if there are more data in RX FIFO, repeat from 1)

TX_DS VAR REG_STATUS.5

MAX_RT var REG_STATUS.4

'RX_P_NO is bits 3:1 000-101 DataPipe#, 110=not used, 111=FIFO empty

TX_FULL var REG_STATUS.0

R_REG_STATUS con %00000110

W_REG_STATUS con %00100110

'TX_ADDR 39:0

TX_ADDR VAR byte[5]

R_TX_ADDR con %00010000

W_TX_ADDR con %00110000

'RX_ADDR_P0 39:0

RX_ADDR_P0 VAR byte[5]

R_RX_ADDR_P0 con %00001010

W_RX_ADDR_P0 con %00101010

'RX_ADDR_P1 39:0

RX_ADDR_P1 VAR byte[5]

R_RX_ADDR_P1 con %00001011

W_RX_ADDR_P1 con %00101011

RX_ADDR_P2 var byte

RX_ADDR_P2=%00000000

R_RX_ADDR_P2 con %00001100

W_RX_ADDR_P2 con %00101100

RX_ADDR_P3 var byte

RX_ADDR_P3=%00000000

R_RX_ADDR_P3 con %00001101

W_RX_ADDR_P3 con %00101101

RX_ADDR_P4 var byte

RX_ADDR_P4=%00000000

R_RX_ADDR_P4 con %00001110

W_RX_ADDR_P4 con %00101110

RX_ADDR_P5 var byte

RX_ADDR_P5=%00000000

R_RX_ADDR_P5 con %00001111

W_RX_ADDR_P5 con %00101111

RX_PW_P0 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P0=%00000000

R_RX_PW_P0 con %00010001

W_RX_PW_P0 con %00110001

RX_PW_P1 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P1=%00000000

R_RX_PW_P1 con %00010010

W_RX_PW_P1 con %00110010

RX_PW_P2 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P2=%00000000

R_RX_PW_P2 con %00010011

W_RX_PW_P2 con %00110011

RX_PW_P3 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P3=%00000000

R_RX_PW_P3 con %00010100

W_RX_PW_P3 con %00110100

RX_PW_P4 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P4=%00000000

R_RX_PW_P4 con %00010101

W_RX_PW_P4 con %00110101

RX_PW_P5 var byte '5:0 is #bytes in payload, 1 to 32 bytes

RX_PW_P5=%00000000

R_RX_PW_P5 con %00010110

W_RX_PW_P5 con %00110110

REG_FIFO_STATUS var byte

REG_FIFO_STATUS=%00000000

TX_REUSE var REG_FIFO_STATUS.6

FIFO_TX_FULL var REG_FIFO_STATUS.5

FIFO_TX_EMPTY var REG_FIFO_STATUS.4

RX_FULL var REG_FIFO_STATUS.1

RX_EMPTY var REG_FIFO_STATUS.0

R_REG_FIFO_STATUS con %00010111

W_REG_FIFO_STATUS con %00110111

DYNPD var byte

DYNPD = %00000000

DPL_P0 var DYNPD.0

DPL_P1 var DYNPD.1

DPL_P2 var DYNPD.2

DPL_P3 var DYNPD.3

DPL_P4 var DYNPD.4

DPL_P5 var DYNPD.5

R_DYNPD con %00011100

W_DYNPD con %00111100

FEATURE var byte

'To activate this feature use the ACTIVATE SPI command followed by data 0x73.(1110011) The corresponding bits

'in the FEATURE register must be set.

FEATURE = %00000000

EN_DYN_ACK var FEATURE.0

EN_ACK_PAY var FEATURE.1

'If ACK packet payload is activated, ACK packets have dynamic payload lengths and the Dynamic Payload

'Length feature should be enabled for pipe 0 on the PTX and PRX. This is to ensure that they receive

'the ACK packets with payloads. If the payload in ACK is more than 15 byte in 2Mbps mode the ARD must

'be 500?S or more, and if the payload is more than 5byte in 1Mbps mode the ARD must be 500?S or more.

EN_DPL var FEATURE.2

R_FEATURE con %00011101

W_FEATURE con %00111101

R_RX_PAYLOAD con %01100001

W_TX_PAYLOAD con %10100000

FLUSH_TX con %11100001

FLUSH_RX con %11100010

ACTIVATE CON %01010000

R_RX_PL_WID con %01100000

W_ACK_PL_P0 con %10101000

W_ACK_PL_P1 con %10101001

W_ACK_PL_P2 con %10101010

W_ACK_PL_P3 con %10101011

W_ACK_PL_P4 con %10101100

W_ACK_PL_P5 con %10101101

W_TX_PL_NO_ACK con %10110000

NOP con %11111111

CE var PORTC.0

CSN var PORTC.1

IRQ var PORTB.4

TRISB.4=1

high CSN

low CE

'SPI Config

TRISC=%00010000

SSPEN VAR SSPCON.5 'SSP Enable bit

CKP VAR SSPCON.4 'Clock Polarity Select

SMP VAR SSPSTAT.7 'Data input sample phase

CKE VAR SSPSTAT.6 'Clock Edge Select bit

SSPIF VAR PIR1.3 'SPI interrupt flag

BF var SSPSTAT.0 'Buffer Full

SSPCON.0=0

SSPCON.1=1

SSPCON.2=0

SSPCON.3=0

SSPEN = 1 'enable SPI pins

CKP = 0 'clock idle low

CKE = 0 'transmit on idle to active transition

SSPIF = 0 'clear buffer full status

SMP = 0 'sample in middle of data

'*************************************************************************

Bttn VAR PORTD.0

TRISD.0=1

TxSent var bit

TxSent=0

WaitForMirf:

High LED

if IRQ=0 then WaitForMirf

pause 500

Low LED

PRIM_RX=1

gosub SetUPMirfV2

SendData[0]=“A”

SendData[1]=“B”

SendData[2]=“C”

SendData[3]=“D”

SendData[4]=“E”

loop:

if Bttn=1 then

gosub SendTXPayload

TxSent=1

endif

if TxSent=1 then

pause 1000

TxSent=0

endif

goto loop

end

GetIncoming:

high LED

if SSPIF=0 then GetIncoming

if BF=0 then GetIncoming

PauseUs 25 '25uS fudge factor

Temp=SSPBUF

SSPIF=0

Low LED

return

SetForRXTXNoSB:

'PRIM_RX=1 or PRIM_RX=0 set before sub called

pauseus 10

if PRIM_RX=1 then

'CE for RX mode

high CE

else

'CE for TX Mode

low CE

endif

return

GetRegister:

low CSN

pauseus 10

SSPBUF=ThisCmd

gosub GetIncoming

pauseus 10

SSPBUF=NOP

gosub GetIncoming

ThisReg=Temp

High CSN

return

SetGetReg:

low CSN

pauseus 10

SSPBUF=ThisCmd

gosub GetIncoming

pauseus 10

SSPBUF=ThisReg

gosub GetIncoming

High CSN

return

Set5byteAddress:

LOW CSN

pauseus 10

SSPBUF=W_TX_ADDR

gosub GetIncoming

for i = 0 to REG_SETUP_AW

SSPBUF=TX_ADDR

  • gosub GetIncoming*
    next
    HIGH CSN
    pauseus 10
    LOW CSN
    for i = 0 to REG_SETUP_AW
  • SSPBUF=RX_ADDR_P0*
    * gosub GetIncoming*
    next
    HIGH CSN
    return
    CheckIRQLED:
    if IRQ =0 then
    low LED1
    SerOut spin,N2400,[“I”,10,13]
    else
    high LED1
    endif
    SendTXPayload:
    high led
    low CSN
    pauseus 10
    SSPBUF=W_TX_Payload
    Gosub GetIncoming
    for i = 0 to 4
    * SSPBUF=SendData*
    * Gosub GetIncoming*
    next
    high CE
    pauseus 20
    low CE
    pauseus 20
    high CSN
    low led
    return
    ReadRXPayload:
    low CE
    low CSN
    SSPBUF=R_RX_Payload
    Gosub GetIncoming
    for i = 0 to 4
    * SSPBUF=NOP*
    * Gosub GetIncoming*
    _ RecData=Temp
    SerOut spin,N2400,[“R”,#RecData*,“D”,10,13] *
    next
    high CSN
    RX_DR=1
    ThisCmd=W_REG_STATUS
    ThisReg=REG_STATUS
    gosub SetGetReg
    high CE
    return
    SetUPMirfV2:
    REG_SETUP_AW=5
    ThisCmd=W_REG_SETUP_AW
    ThisReg=REG_SETUP_AW
    gosub SetGetReg
    TX_ADDR[0]=%01001001
    TX_ADDR[1]=%10001101
    TX_ADDR[2]=%00111001
    TX_ADDR[3]=%11001101
    TX_ADDR[4]=%01101100
    RX_ADDR_P0=TX_ADDR
    gosub Set5byteAddress
    ENAA_P0=1
    ThisCmd=W_REG_EN_AA
    ThisReg=REG_EN_AA
    gosub SetGetReg
    ERX_P0=1
    ThisCmd=W_REG_EN_RXADDR
    ThisReg=REG_EN_RXADDR
    gosub SetGetReg
    REG_SETUP_RETR=%00011010
    '500µs + 86µs, 10 retrans
    ThisCmd=W_REG_SETUP_RETR
    ThisReg=REG_SETUP_RETR
    gosub SetGetReg
    RF_CH=40
    ThisCmd=W_REG_RF_CH
    ThisReg=RF_CH
    gosub SetGetReg
    REG_RF_SETUP=%00001111
    'TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
    ThisCmd=W_REG_RF_SETUP
    ThisReg=REG_RF_SETUP
    gosub SetGetReg
    'PRIM_RX=1 or PRIM_RX=0 set before sub called
    PWR_UP=1
    CRC0=1
    EN_CRC=1
    ThisCmd=W_REG_CONFIG
    ThisReg=REG_CONFIG
    gosub SetGetReg
    pause 2
    return
    RECEIVER:
    '
    Name : MirfRecT2.BAS
    Author : Harold Goodrich
    Notice : Copyright (c) 2008 Harold Goodrich
    : All Rights Reserved
    Date : 4/2/2008
    Version : 1.0
    Notes :
    :
    '

    define OSC 10
    INCLUDE “modedefs.bas”
    spin VAR PORTD.6
    LED VAR PORTD.2
    LED1 VAR PORTD.3
    TRISD.2=0
    TRISD.3=0
    TRISD.6=0
    low LED
    low LED1
    i VAR BYTE 'loop counter
    ThisReg var byte
    ThisCmd var byte
    Temp var byte
    RecData var byte[4]
    SendData var byte[4]
    'Mirf Config
    REG_CONFIG var byte
    REG_CONFIG=%00000000
    PRIM_RX var REG_CONFIG.0
    PWR_UP var REG_CONFIG.1
    CRC0 var REG_CONFIG.2
    EN_CRC var REG_CONFIG.3
    R_REG_CONFIG con %00000000
    W_REG_CONFIG con %00100000
    REG_EN_AA var byte
    REG_EN_AA = %0011111
    ENAA_P5 var REG_EN_AA.5
    ENAA_P4 var REG_EN_AA.4
    ENAA_P3 var REG_EN_AA.3
    ENAA_P2 var REG_EN_AA.2
    ENAA_P1 var REG_EN_AA.1
    ENAA_P0 var REG_EN_AA.0
    R_REG_EN_AA con %00000001
    W_REG_EN_AA con %00100001
    REG_EN_RXADDR var byte
    REG_EN_RXADDR=%0000000
    ERX_P5 var REG_EN_RXADDR.5
    ERX_P4 var REG_EN_RXADDR.4
    ERX_P3 var REG_EN_RXADDR.3
    ERX_P2 var REG_EN_RXADDR.2
    ERX_P1 var REG_EN_RXADDR.1
    ERX_P0 var REG_EN_RXADDR.0
    R_REG_EN_RXADDR con %00000010
    W_REG_EN_RXADDR con %00100010
    REG_SETUP_AW var byte
    REG_SETUP_AW=%00000011
    R_REG_SETUP_AW con %00000011
    W_REG_SETUP_AW con %00100011
    REG_SETUP_RETR var byte
    REG_SETUP_RETR=%00000011
    'ARD: 7:4 250Us each increment
    'This is the time the PTX is waiting for an ACK packet before a retransmit is made. The PTX is in RX mode
    'for a minimum of 250?S, but it stays in RX mode to the end of the packet if that is longer than 250?S. Then
    'it goes to standby-I mode for the rest of the specified ARD. After the ARD it goes to TX mode and then
    'retransmits the packet.
    'ARC 3:0 retry count 0 to 15, 0 is disabled
    R_REG_SETUP_RETR con %00000100
    W_REG_SETUP_RETR con %00100100
    RF_CH var byte
    RF_CH=%00000010
    R_REG_RF_CH con %00000101
    W_REG_RF_CH con %00100101
    REG_RF_SETUP var byte
    REG_RF_SETUP=%00001111
    LNA_HCURR var REG_RF_SETUP.0 'gain
    'RF_PWR 2:1, 11=0db, 10:-6db, 01:-12db, 00:-18db
    R_REG_RF_SETUP con %00000110
    W_REG_RF_SETUP con %00100110
    REG_STATUS var byte
    REG_STATUS=%00001100
    RX_DR var REG_STATUS.6
    'The RX_DR IRQ is asserted by a new packet arrival event. The procedure for handling this interrupt
    'should be: 1) read payload through SPI, 2) clear RX_DR IRQ, 3) read FIFO_STATUS to check if there
    'are more payloads available in RX FIFO, 4) if there are more data in RX FIFO, repeat from 1)
    TX_DS VAR REG_STATUS.5
    MAX_RT var REG_STATUS.4
    'RX_P_NO is bits 3:1 000-101 DataPipe#, 110=not used, 111=FIFO empty
    TX_FULL var REG_STATUS.0
    R_REG_STATUS con %00000110
    W_REG_STATUS con %00100110
    'TX_ADDR 39:0
    TX_ADDR VAR byte[5]
    R_TX_ADDR con %00010000
    W_TX_ADDR con %00110000
    'RX_ADDR_P0 39:0
    RX_ADDR_P0 VAR byte[5]
    R_RX_ADDR_P0 con %00001010
    W_RX_ADDR_P0 con %00101010
    'RX_ADDR_P1 39:0
    RX_ADDR_P1 VAR byte[5]
    R_RX_ADDR_P1 con %00001011
    W_RX_ADDR_P1 con %00101011
    RX_ADDR_P2 var byte
    RX_ADDR_P2=%00000000
    R_RX_ADDR_P2 con %00001100
    W_RX_ADDR_P2 con %00101100
    RX_ADDR_P3 var byte
    RX_ADDR_P3=%00000000
    R_RX_ADDR_P3 con %00001101
    W_RX_ADDR_P3 con %00101101
    RX_ADDR_P4 var byte
    RX_ADDR_P4=%00000000
    R_RX_ADDR_P4 con %00001110
    W_RX_ADDR_P4 con %00101110
    RX_ADDR_P5 var byte
    RX_ADDR_P5=%00000000
    R_RX_ADDR_P5 con %00001111
    W_RX_ADDR_P5 con %00101111
    RX_PW_P0 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P0=%00000000
    R_RX_PW_P0 con %00010001
    W_RX_PW_P0 con %00110001
    RX_PW_P1 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P1=%00000000
    R_RX_PW_P1 con %00010010
    W_RX_PW_P1 con %00110010
    RX_PW_P2 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P2=%00000000
    R_RX_PW_P2 con %00010011
    W_RX_PW_P2 con %00110011
    RX_PW_P3 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P3=%00000000
    R_RX_PW_P3 con %00010100
    W_RX_PW_P3 con %00110100
    RX_PW_P4 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P4=%00000000
    R_RX_PW_P4 con %00010101
    W_RX_PW_P4 con %00110101
    RX_PW_P5 var byte '5:0 is #bytes in payload, 1 to 32 bytes
    RX_PW_P5=%00000000
    R_RX_PW_P5 con %00010110
    W_RX_PW_P5 con %00110110
    REG_FIFO_STATUS var byte
    REG_FIFO_STATUS=%00000000
    TX_REUSE var REG_FIFO_STATUS.6
    FIFO_TX_FULL var REG_FIFO_STATUS.5
    FIFO_TX_EMPTY var REG_FIFO_STATUS.4
    RX_FULL var REG_FIFO_STATUS.1
    RX_EMPTY var REG_FIFO_STATUS.0
    R_REG_FIFO_STATUS con %00010111
    W_REG_FIFO_STATUS con %00110111
    DYNPD var byte
    DYNPD = %00000000
    DPL_P0 var DYNPD.0
    DPL_P1 var DYNPD.1
    DPL_P2 var DYNPD.2
    DPL_P3 var DYNPD.3
    DPL_P4 var DYNPD.4
    DPL_P5 var DYNPD.5
    R_DYNPD con %00011100
    W_DYNPD con %00111100
    FEATURE var byte
    'To activate this feature use the ACTIVATE SPI command followed by data 0x73.(1110011) The corresponding bits
    'in the FEATURE register must be set.
    FEATURE = %00000000
    EN_DYN_ACK var FEATURE.0
    EN_ACK_PAY var FEATURE.1
    'If ACK packet payload is activated, ACK packets have dynamic payload lengths and the Dynamic Payload
    'Length feature should be enabled for pipe 0 on the PTX and PRX. This is to ensure that they receive
    'the ACK packets with payloads. If the payload in ACK is more than 15 byte in 2Mbps mode the ARD must
    'be 500?S or more, and if the payload is more than 5byte in 1Mbps mode the ARD must be 500?S or more.
    EN_DPL var FEATURE.2
    R_FEATURE con %00011101
    W_FEATURE con %00111101
    R_RX_PAYLOAD con %01100001
    W_TX_PAYLOAD con %10100000
    FLUSH_TX con %11100001
    FLUSH_RX con %11100010
    ACTIVATE CON %01010000
    R_RX_PL_WID con %01100000
    W_ACK_PL_P0 con %10101000
    W_ACK_PL_P1 con %10101001
    W_ACK_PL_P2 con %10101010
    W_ACK_PL_P3 con %10101011
    W_ACK_PL_P4 con %10101100
    W_ACK_PL_P5 con %10101101
    W_TX_PL_NO_ACK con %10110000
    NOP con %11111111
    CE var PORTC.0
    CSN var PORTC.1
    IRQ var PORTB.4
    TRISB.4=1
    high CSN
    low CE
    'SPI Config
    TRISC=%00010000
    SSPEN VAR SSPCON.5 'SSP Enable bit
    CKP VAR SSPCON.4 'Clock Polarity Select
    SMP VAR SSPSTAT.7 'Data input sample phase
    CKE VAR SSPSTAT.6 'Clock Edge Select bit
    SSPIF VAR PIR1.3 'SPI interrupt flag
    BF var SSPSTAT.0 'Buffer Full
    SSPCON.0=0
    SSPCON.1=1
    SSPCON.2=0
    SSPCON.3=0
    SSPEN = 1 'enable SPI pins
    CKP = 0 'clock idle low
    CKE = 0 'transmit on idle to active transition
    SSPIF = 0 'clear buffer full status
    SMP = 0 'sample in middle of data
    'Bttn VAR PORTD.0
    'TRISD.0=1
    High LED
    WaitForMirf:
    if IRQ=0 then WaitForMirf
    pause 500
    Low LED
    PRIM_RX=0
    gosub SetUPMirfV2
    loop:
    if IRQ=1 then
    ThisCmd=R_REG_STATUS
    ThisReg=NOP
    gosub SetGetReg
    REG_STATUS=Temp
    if RX_DR=1 then
    high LED
    gosub ReadRXPayload
    low LED
    endif
    endif
    goto loop
    end
    GetIncoming:
    high LED
    if SSPIF=0 then GetIncoming
    if BF=0 then GetIncoming
    PauseUs 25 '25uS fudge factor
    Temp=SSPBUF
    SSPIF=0
    Low LED
    return
    SetForRXTXNoSB:
    'PRIM_RX=1 or PRIM_RX=0 set before sub called
    pauseus 10
    if PRIM_RX=1 then
    'CE for RX mode
    high CE
    else
    'CE for TX Mode
    low CE
    endif
    return
    GetRegister:
    low CSN
    pauseus 10
    SSPBUF=ThisCmd
    gosub GetIncoming
    pauseus 10
    SSPBUF=NOP
    gosub GetIncoming
    ThisReg=Temp
    High CSN
    return
    SetGetReg:
    low CSN
    pauseus 10
    SSPBUF=ThisCmd
    gosub GetIncoming
    pauseus 10
    SSPBUF=ThisReg
    gosub GetIncoming
    High CSN
    return
    Set5byteAddress:
    LOW CSN
    pauseus 10
    SSPBUF=W_TX_ADDR
    gosub GetIncoming
    for i = 0 to REG_SETUP_AW
    * SSPBUF=TX_ADDR*
    * gosub GetIncoming*
    next
    HIGH CSN
    pauseus 10
    LOW CSN
    for i = 0 to REG_SETUP_AW
    * SSPBUF=RX_ADDR_P0*
    * gosub GetIncoming*
    next
    HIGH CSN
    return
    CheckIRQLED:
    if IRQ =0 then
    low LED1
    SerOut spin,N2400,[“I”,10,13]
    else
    high LED1
    endif
    SendTXPayload:
    high led
    low CSN
    pauseus 10
    SSPBUF=W_TX_Payload
    Gosub GetIncoming
    for i = 0 to 4
    * SSPBUF=SendData
    Gosub GetIncoming*

    next
    high CE
    pauseus 20
    low CE
    pauseus 20
    high CSN
    low led
    return
    ReadRXPayload:
    low CE
    low CSN
    SSPBUF=R_RX_Payload
    Gosub GetIncoming
    for i = 0 to 4
    * SSPBUF=NOP*
    * Gosub GetIncoming*
    RecData=Temp
    SerOut spin,N2400,[“R”,#RecData*,“D”,10,13] *
    next
    high CSN
    RX_DR=1
    ThisCmd=W_REG_STATUS
    ThisReg=REG_STATUS
    gosub SetGetReg
    high CE
    return
    SetUPMirfV2:
    REG_SETUP_AW=5
    ThisCmd=W_REG_SETUP_AW
    ThisReg=REG_SETUP_AW
    gosub SetGetReg
    TX_ADDR[0]=%01001001
    TX_ADDR[1]=%10001101
    TX_ADDR[2]=%00111001
    TX_ADDR[3]=%11001101
    TX_ADDR[4]=%01101100
    RX_ADDR_P0=TX_ADDR
    gosub Set5byteAddress
    ENAA_P0=1
    ThisCmd=W_REG_EN_AA
    ThisReg=REG_EN_AA
    gosub SetGetReg
    ERX_P0=1
    ThisCmd=W_REG_EN_RXADDR
    ThisReg=REG_EN_RXADDR
    gosub SetGetReg
    REG_SETUP_RETR=%00011010
    '500µs + 86µs, 10 retrans
    ThisCmd=W_REG_SETUP_RETR
    ThisReg=REG_SETUP_RETR
    gosub SetGetReg
    RF_CH=40
    ThisCmd=W_REG_RF_CH
    ThisReg=RF_CH
    gosub SetGetReg
    REG_RF_SETUP=%00001111
    'TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
    ThisCmd=W_REG_RF_SETUP
    ThisReg=REG_RF_SETUP
    gosub SetGetReg
    'PRIM_RX=1 or PRIM_RX=0 set before sub called
    PWR_UP=1
    CRC0=1
    EN_CRC=1
    ThisCmd=W_REG_CONFIG
    ThisReg=REG_CONFIG
    gosub SetGetReg
    pause 2
    return
    _

in the receiver code i found one code error…in the main loop when I am checking the IRQ pin: if “IRQ=1 then” should be “if IRQ=0 then”.

However the setup is still not working.

do I need pauses at certain places?

Basically the code before and after the main loop are constant/variable setups and subroutines respectively, and are the same for both files. (I had them in a library, but PBP didnt like it…something Ill work out later).

I modeled the setup of sender and receiver after the C example of setup in nordic’s documentation. I chose a different address, but otherwise I think my PBP setup is the same…and I have been pouring through the tutorials from www.diyembedded.com. (over and over again) and i think Im close, but I have something wrong with setup.

The setup from nordic documentation is (here is receiver only):

void RX_Mode(void)

{

SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_LENGTH);

// Use the same address on the RX device as the TX device

SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);

// Enable Auto.Ack:Pipe0

SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);

// Enable Pipe0

SPI_RW_Reg(WRITE_REG + RF_CH, 40);

// Select RF channel 40

SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH);

// Select same RX payload width as TX Payload width

SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x0f);

// TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR

SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);

// Set PWR_UP bit, enable CRC(2 bytes) & Prim:RX. RX_DR enabled

// Add a delay of 1.5ms before setting CE high if the device was in power down mode.

CE = 1; // Set CE pin high to enable RX device

// This device is now ready to receive one packet of 16 bytes payload from a TX device sending to address

// ‘3443101001’, with auto acknowledgment, retransmit count of 10, RF channel 40 and datarate = 2Mbps.

}

I would like to get my code working so I can continue work on my project…and also because of the lack of Pic Basic Pro code out there for the Nrf24L01, i would like to share the code with othe PBP developers. I am learning java right now at work and I know I will be able to use that to move to C, but i’m not there yet…and I need to finish my project up before june.

Please. please help if you can.

I changed the code slightly on the transmitter side to show me the status of TX_DS by turning on a second LED when the TX_DS reg shows transmitted.

When I press the button, there is a 10 second delay before the LED light for the TX_DS lights up…but nothing happens at the receiver.

Now, I am in an environment (at work) where we do have a TCPIP wireless network for laptop users.

Harold

You’d find it easier to use an 18F PIC with the C18 compiler, there is some software available that works OK.

Leon