Been awhile since I been here and found this post while trying to bring the same module to life.

After a lot of reading and comparing "working" code not in PBP, I found that a lot of confusion starts at the datasheet on this RF module.
Some information led me into the boonies until I realized the Microchip datasheet writer laid it out in almost a story telling fashion. Setting up in TX or RX Mode as listed on page 89 of datasheet makes some assumptions as to "auto" this or that, didn't really work that way.
Unfortunately, I've been finding a lot of copy/paste going on in the datasheets without corrected info in some of the new PIC parts as well, but that's another gripe.

I managed to get these guys talking back and forth using a PIC16F1705 but left out the PIC setup particulars for this chip so only the MRF89XAM9A configurations can be focused on. Plus it really helps to have a spectrum analyzer or RF service monitor on hand.

As a note, the RX code register loading is done sequentially where the TX code is set up using a For/Next loop the way ecoli-557 started in this post. I like his way better because all the registers are listed and commented in one place at the top. This makes it easier to make changes.

The code set up contains TX/RX mode for both ends but only one mode is selected in each list here.

RX Mode:

Code:
' MRF89XAM9A Receiver mode

'*  OSC set to 4MHz because MRF89XA FIFO max CLK frequency is 1MHz.
OSCCON = %01101000       ' Set to 4MHz
' PLL enabled on :7
'  1 = 4x PLL is enabled
'  0 = 4x PLL is disabled
' OSC setting 6:3
'  1111 = 16MHz
'  1110 = 8Mhz or 32MHz when bit 7 set (SPLLEN)
'  1101 = 4MHz
'  1100 = 2MHz
'  1011 = 1MHz

DEFINE OSC 4

'***** SPI Setup for channel 1 *******
SSP1STAT.7 = 1           ' Data_In sampled at end of Data_out
SSP1STAT.6 = 1           ' Data transmitted on rising edge of SCK
SSP1CON1 = %00100000     ' :5 En/Disbles serial port, :4 low level Idle state, 3:0 CLK = Fosc/4

'========================================================================
'                        Variable PORT Definitions      
'========================================================================

INT3        VAR PORTA.4    ' RF INT1
INT4        VAR PORTA.5    ' RF INT2

CSDAT       VAR LATC.3     ' RF module MRF89XAM9A FIFO CS
CSCON       VAR LATC.5     ' RF module MRF89XAM9A Config CS

'========================================================================
'                        Variable Definitions      
'========================================================================
RX_data    VAR BYTE[16]
TX_data    VAR BYTE[16]
x          VAR BYTE

'=========================================================================
'                       Set values to variables       
'=========================================================================
CSDAT = 1      ' /CSData set high
CSCON = 1      ' /CSCON set high

PAUSE 500

GOTO Prestart

'=========================================================================
'                           RF module configuration
' Data in consists of Address followed with new value for that address.
' Toggling /CS between Writes not needed, see MRF89XA DS 2.11.1
'
' Address header:
'   7: Start bit = 0
'   6: R/W bit. Read = 1, Write = 0
'   5:1 register address
'   0: Stop bit = 0
'
' The OSC is set to 16MHz during Writes to 31 config registers so the time
' can be reduced from 1.34ms @4MHz to 335us @16MHz
'
' ***************** Deviation and Bit Rate calculations ****************** 
' fdev = 12.8MHz/(32*(FDVAL+1))
' BitRate = 12.8MHz/(64*(BRVAL+1)), where BitRate = 0<= BRVAL >=127
' Beta must be = (2*fdev)/BR >= 2
'                (2*50kHz)/40kbs = 2.5
'*************************************************************************
'
' ********************* Frequency calculation ****************************
' Freq = 9/8 * 12.8MHz/R+1 * [75*(P+1)+S]
'
'
'
'
'=========================================================================
MRF_Init:
   CSCON = 0               ' Enable Chip Select    
' GCONREG value            ' 2.14.1
   SSP1BUF = %00000000     ' Write bit with $00 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00101110     ' STBY mode, 915-928MHz band, Vtune +180mV
                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   
' DMODREG value            ' 2.14.2
   SSP1BUF = %00000010     ' Write bit with $01 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %10100100     ' FSK Mod, Packet data and max IF gain
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' FDEVREG value            ' 2.14.3
   SSP1BUF = %00000100     ' Write bit with $02 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000111     ' Freq deviation, calc = 50kHz 40k
   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

' BRSREG value             ' 2.14.4
   SSP1BUF = %00000110     ' Write bit with $03 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00010011     ' Bit Rate, calc = 10kbs
   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

' FLTHREG value            ' 2.14.5
   SSP1BUF = %00001000     ' Write bit with $04 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000000     ' Floor threshold for for OOK mode only
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' FIFOREG value            ' 2.14.6
   SSP1BUF = %00001010     ' Write bit with $05 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00001110     ' 16 byte FIFO and 14 byte Threshold
   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

' R1CREG value             ' 2.14.7
   SSP1BUF = %00001100     ' Write bit with $06 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01110111     ' $77 R1+P1+S1 = 921.00MHz
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' P1CREG value             ' 2.14.8
   SSP1BUF = %00001110     ' Write bit with $07 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01100101     ' $65
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' S1CREG value             ' 2.14.9
   SSP1BUF = %00010000     ' Write bit with $08 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00011001     ' $19
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' R2CREG value             ' 2.14.10
   SSP1BUF = %00010010     ' Write bit with $09 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01110111     ' $77 R2+P2+S2 = 908.04MHz
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' P2CREG value             ' 2.14.11
   SSP1BUF = %00010100     ' Write bit with $0A address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01100011     ' $63
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' S2CREG value             ' 2.14.12
   SSP1BUF = %00010110     ' Write bit with $0B address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01000011     ' $43
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' PACREG value             ' 2.14.13
   SSP1BUF = %00011000     ' Write bit with $0C address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000000     ' PA ramp control for OOK mode only
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   
                           
' FTXRXIREG value          ' 2.15.1
   SSP1BUF = %00011010     ' Write bit with $0D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00100001     ' IRQ0RXS = PLReady, IRQ1RXS = RSSI
                           ' IRQ1TX = TX Done,       IRQ1TX = FIFO full
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
                           
' FTPRIREG value           ' 2.15.2
   SSP1BUF = %00011100     ' Write bit with $0E address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00111001     ' 5:IRQ0 TX Done, 4:TX start FIFO !empty, 0: 1 = Clear PLL lock
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' RSTHIREG value           ' 2.15.3
   SSP1BUF = %00011110     ' Write bit with $0F address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01101110     ' RSSI threshold set to -60dBm. See 3.4.7.3, Fig 3-9
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' FILCREG value            ' 2.16.1
   SSP1BUF = %00100000     ' Write bit with $10 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00110011     ' Passive filter = 137kHz, Butterworth = 100kHz
   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

' PFCREG value             ' 2.16.2
   SSP1BUF = %00100010     ' Write bit with $11 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00111000     ' Polyphase Center Freq. set to 100kHz default
                           ' for OOK only
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' SYNCREG value            ' 2.16.3
   SSP1BUF = %00100100     ' Write bit with $12 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00110000     ' Sync word EN, 24bit, no errors allowed
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' RSTSREG value            ' 2.16.4
   SSP1BUF = %00100110     ' Write bit with $13 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000111     ' Reserved, non zero value
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' RSVREG value              ' 2.16.5
   SSP1BUF = %00101000     ' Write bit with $14 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000000     ' RSSI read only value
                           ' RSSI[dBm] = 0.55 * RSSIVAL - 118.5[dBm]
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' OOKCREG value            ' 2.16.6
   SSP1BUF = %00101010     ' Write bit with $15 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000000     ' OOK only, default value
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' SYNCV31REG value         ' 2.17.1
   SSP1BUF = %00101100     ' Write bit with $16 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %10101010     ' Sync value, 1st byte = $AA
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' SYNCV23REG value         ' 2.17.2
   SSP1BUF = %00101110     ' Write bit with $17 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01010101     ' Sync value, 2nd byte = $55
   GOSUB SSP_INT           ' Wait until MSSP module finishes task    

' SYNCV15REG value         ' 2.17.3
   SSP1BUF = %00110000     ' Write bit with $18 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %10101010     ' Sync value, 3rd byte = $AA
   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

' SYNCV07REG value         ' 2.17.4
   SSP1BUF = %00110010     ' Write bit with $19 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01010101     ' Sync value, 4th byte = $55
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' TXCONVREG value          ' 2.18.1
   SSP1BUF = %00110100     ' Write bit with $1A address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01110000     ' TX filter default = 200kHz, TX Pwr = +13dBm
   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

' CLKOREG value            ' 2.19.1
   SSP1BUF = %00110110     ' Write bit with $1B address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00000000     ' Clock out control disabled
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' PLOADREG value           ' 2.20.1
   SSP1BUF = %00111000     ' Write bit with $1C address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00010000     ' Manchester disabled, Packet length = 16 byte
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' NADDSREG value           ' 2.20.2
   SSP1BUF = %00111010     ' Write bit with $1D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %11001100     ' Node address = $CC
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' PKTCREG value            ' 2.20.3
   SSP1BUF = %00111100     ' Write bit with $1E address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01011000     ' Pkt length fixed, preamble = 3 bytes, White ON
                           ' CRC EN, 2:1 Address filter OFF
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

' FCRCREG value            ' 2.20.4
   SSP1BUF = %00111110     ' Write bit with $1F address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task            
   SSP1BUF = %00000000     ' FIFO auto clear if/CRC, FIFO Write on STBY
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   
   CSCON = 1               ' Disable Chip Select

RETURN

' Allow MSSP module to finish task
SSP_INT: 
   WHILE !PIR1.3: WEND
   PIR1.3 = 0
RETURN

'=========================================================================
'                           RF module RX mode config
' This routine takes xxxms to complete where the receive time uses xxxms
' of it with 16 bytes at 10kbs.
'=========================================================================
RX_mode:
   CSCON = 0               ' Enable Chip Select
   
'************ Set IRQ0 to /FIFOEmpty and IRQ1 to FIFO Threshold ***********
' FTXRXIREG value (INT3 & 4)   ' 2.15.1
   SSP1BUF = %00011010     ' Write bit with $0D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00100001     ' 7:6 IRQ0 = PLReady, 5:4 IRQ1 = CRCOK  11000001
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* RX mode **************************************
' GCONREG value            ' 2.14.1
   SSP1BUF = %00000000     ' Write bit with $00 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01101000     ' RX mode, 915-928MHz band, Vtune via inductors
                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

   CSCON = 1               ' Disable Chip Select
   
RETURN

'************************* Read FIFO **************************************
' Reading the FIFO will clear IRQ0.
' This routine takes 696us to complete.
'**************************************************************************  
Read_FIFO:
  FOR x = 0 TO 15
    CSDAT = 0               ' Enable Chip Select
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    CSDAT = 1               ' Disable Chip Select
    RX_data[x] = SSP1BUF    ' Assign RX data to array (adds 150us to loop)
  NEXT x

RETURN
'=========================================================================
'                           RF module TX mode config
' This routine takes 20.9ms to complete where the transmit time uses 20.1ms
' of it with 16 bytes at 10kbs.
'=========================================================================
TX_mode:
   CSCON = 0               ' Enable Chip Select    

'********************** Set IRQ1 to TX Done *******************************
' FTXRXIREG value (INT4)   ' 2.15.1
   SSP1BUF = %00011010     ' Write bit with $0D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %11001101     ' 3: IRQ1TX = TX Done
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* STBY mode **************************************
' GCONREG value            ' 2.14.1
   SSP1BUF = %00000000     ' Write bit with $00 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00100001     ' STBY mode, 902-915MHz band, Vtune via inductors
                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* FIFO Write on STBY *****************************
' FCRCREG value            ' 2.20.4
   SSP1BUF = %00111110     ' Write bit with $1F address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task            
   SSP1BUF = %00000000     ' FIFO auto clear if/CRC, FIFO Write on STBY
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

   CSCON = 1               ' Disable Chip Select
   
'************************* Fill FIFO **************************************  
  FOR x = 1 TO 16
    CSDAT = 0             ' Enable Chip Select
    SSP1BUF = x           ' Write value
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    CSDAT = 1             ' Disable Chip Select 
  NEXT x
   
'************************* Enable TX mode *********************************      
' GCONREG value           ' 2.14.1
  CSCON = 0               ' Enable Chip Select
    SSP1BUF = %00000000   ' Write bit with $00 address
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    SSP1BUF = %10000001   ' TX mode, 902-915MHz band, Vtune via inductors
                          ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
    GOSUB SSP_INT         ' Wait until MSSP module finishes task  
  CSCON = 1               ' Disable Chip Select
   
  WHILE !INT4: WEND       ' Wait until transmission is complete
  PAUSEUS 100             ' Wait a little
  
'************************* Enable Sleep mode*******************************  
' GCONREG value           ' 2.14.1
  CSCON = 0               ' Enable Chip Select
    SSP1BUF = %00000000   ' Write bit with $00 address
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    SSP1BUF = %00101000   ' Sleep mode, 915-928MHz band, Vtune via inductors
                          ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
  CSCON = 1               ' Disable Chip Select
      
RETURN

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Reg_check:
  CSCON = 0                 ' Enable Chip Select  
    SSP1BUF = %01011010     ' Read bit with $0D address
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task  
  
    SSP1BUF = %01011100     ' Read bit with $0E address
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    x = SSPBUF       
  CSCON = 1                 ' Disable Chip Select
RETURN

RIRQS_clear:
' FTPRIREG value            ' 2.15.2
  CSCON = 0                 ' Enable Chip Select
    SSP1BUF = %00011100     ' Write bit with $0E address
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSP1BUF = %00111101     ' 2: Clear RIRQS bit 0: 1 = Clear PLL lock
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
  CSCON = 1                 ' Disable Chip Select  
RETURN

Reg_read:
  CSCON = 0                 ' Enable Chip Select
  FOR x = 0 TO 31    
    SSP1BUF = ((x << 1) | $40)  ' Shifts left 1 bit, sets $40 bit
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task        
  NEXT x
  CSCON = 1                 ' Disable Chip Select
RETURN  


'=========================================================================
'                           Prestart settings       
'=========================================================================
Prestart:
GOSUB MRF_Init            ' Config the RF module
GOSUB RX_mode             ' Put into RX mode

Main:
  
' Monitor INT3 indicating data in RX buffer
  IF INT3 THEN 
    GOSUB Read_FIFO
  ENDIF

'*************************************************************************
' My test code here checked the last incoming byte value. If valid then
' switch to TX mode and send 16 bytes and revert back to RX mode.
'*************************************************************************
'  IF RX_data[15] = $10 THEN
'    RX_data[15] = 0       ' Clear the value for next RX
'    GOSUB TX_mode         ' Send 16 bytes with values 1~16
'    PAUSE 10 
'    GOSUB RX_mode         ' Switch back to RX mode
'  ENDIF  

GOTO Main


END
TX Mode:

Code:
' MRF89XAM9A Transmitter mode

'*  OSC set to 4MHz because MRF89XA FIFO max CLK frequency is 1MHz.
OSCCON = %01101000       ' Set to 4MHz
' PLL enabled on :7
'  1 = 4x PLL is enabled
'  0 = 4x PLL is disabled
' OSC setting 6:3
'  1111 = 16MHz
'  1110 = 8Mhz or 32MHz when bit 7 set (SPLLEN)
'  1101 = 4MHz
'  1100 = 2MHz
'  1011 = 1MHz

DEFINE OSC 4

'***** SPI Setup for channel 1 *******
SSP1STAT.7 = 1           ' Data_In sampled at end of Data_out
SSP1STAT.6 = 1           ' Data transmitted on rising edge of SCK
SSP1CON1 = %00100000     ' :5 En/Disbles serial port, :4 low level Idle state, 3:0 CLK = Fosc/4

'========================================================================
'                        Variable PORT Definitions      
'========================================================================

INT3        VAR PORTA.4    ' RF INT1
INT4        VAR PORTA.5    ' RF INT2

CSDAT       VAR LATC.3     ' RF module MRF89XAM9A FIFO CS
CSCON       VAR LATC.5     ' RF module MRF89XAM9A Config CS

'========================================================================
'                        Variable Definitions      
'========================================================================

MRF_Config  VAR BYTE[32]
RX_data     VAR BYTE[16]
TX_data     VAR BYTE[16]
inc         VAR BYTE      ' Increment variable counter
x           VAR BYTE
y           VAR WORD


'///// MRF configuration list, D/S sect, Config name: Description /////////
MRF_Config[0] = $2E     ' 2.14.1, GCONREG: STBY mode, 915-928MHz band, Vtune +180mV, $2E = Enable R1/P1/S1, $2F = Enable R2/P2/S2 
MRF_Config[1] = $84     ' 2.14.2, DMODREG: FSK Mod, Packet data and max IF gain
MRF_Config[2] = $07     ' 2.14.3, FDEVREG: Freq deviation, calc = 50kHz 40k
MRF_Config[3] = $13     ' 2.14.4, BRSREG: Bit Rate, calc = 10kbs
MRF_Config[4] = $00     ' 2.14.5, FLTHREG: Floor threshold for for OOK mode only
MRF_Config[5] = $0E     ' 2.14.6, FIFOREG: 16 byte FIFO and 14 byte Threshold
MRF_Config[6] = $77     ' 2.14.7, R1CREG: R1    (R1+P1+S1) = 921.00MHz
MRF_Config[7] = $65     ' 2.14.8, P1CREG: P1
MRF_Config[8] = $19     ' 2.14.9, S1CREG: S1
MRF_Config[9] = $77     ' 2.14.10, R2CREG: R2   (R2+P2+S2) = 908.04MHz
MRF_Config[10] = $63    ' 2.14.11, P2CREG: P2
MRF_Config[11] = $43    ' 2.14.12, S2CREG: S1
MRF_Config[12] = $00    ' 2.14.13, PACREG: PA ramp control for OOK mode only
MRF_Config[13] = $CC    ' 2.15.1, FTXRXIREG: IRQ0RX = RX Sync match, IRQ1RX = RX CRC Okay, IRQ1TX = TX Done, IRQ1TX = FIFO full
MRF_Config[14] = $39    ' 2.15.2, FTPRIREG: 5:IRQ0 TX Done, 4:TX start FIFO !empty, 0: 1 = Clear PLL lock
MRF_Config[15] = $2D    ' 2.15.3, RSTHIREG: RSSI threshold set to -95dBm. See 3.4.7.3
MRF_Config[16] = $33    ' 2.16.1, FILCREG: Passive filter = 137kHz, Butterworth = 100kHz
MRF_Config[17] = $38    ' 2.16.2, PFCREG: Polyphase Center Freq. set to 100kHz default for OOK only
MRF_Config[18] = $30    ' 2.16.3, SYNCREG: Sync word EN, 24bit, no errors allowed
MRF_Config[19] = $07    ' 2.16.4, RSTSREG: Reserved, non zero value
MRF_Config[20] = $00    ' 2.16.5, RSVREG: RSSI read only value, RSSI[dBm] = 0.55 * RSSIVAL - 118.5[dBm]
MRF_Config[21] = $00    ' 2.16.6, OOKCREG: OOK only, default value 
MRF_Config[22] = $AA    ' 2.17.1, SYNCV31REG: Sync value, 1st byte = $AA
MRF_Config[23] = $55    ' 2.17.2, SYNCV23REG: Sync value, 2nd byte = $55
MRF_Config[24] = $AA    ' 2.17.3, SYNCV15REG: Sync value, 3rd byte = $AA
MRF_Config[25] = $55    ' 2.17.4, SYNCV07REG: Sync value, 4th byte = $55
MRF_Config[26] = $70    ' 2.18.1, TXCONVREG: TX filter default = 200kHz, TX Pwr = +13dBm
MRF_Config[27] = $00    ' 2.19.1, CLKOREG: Clock out control disabled 
MRF_Config[28] = $10    ' 2.20.1, PLOADREG: Manchester disabled, Packet length = 16 byte
MRF_Config[29] = $CC    ' 2.20.2, NADDSREG: Node address = $CC
MRF_Config[30] = $58    ' 2.20.3, PKTCREG: Pkt length fixed, preamble = 3 bytes, White ON, CRC EN, Address filter OFF
MRF_Config[31] = $00    ' 2.20.4, FCRCREG: FIFO auto clear if/CRC, FIFO Write on STBY

'=========================================================================
'                       Set values to variables       
'=========================================================================
CSDAT = 1      ' /CSData set high
CSCON = 1      ' /CSCON set high

PAUSE 500

GOTO Prestart

'=========================================================================
'                           RF module configuration
' Data in consists of Address followed with new value for that address.
' Toggling /CS between Writes not needed, see MRF89XA DS 2.11.1
'
' Address header:
'   7: Start bit = 0
'   6: R/W bit. Read = 1, Write = 0
'   5:1 register address
'   0: Stop bit = 0
'
' The OSC can be set to 16MHz during Writes to 31 config registers so the 
' time can be reduced from 1.34ms @4MHz to 335us @16MHz
'
' ***************** Deviation and Bit Rate calculations ****************** 
' fdev = 12.8MHz/(32*(FDVAL+1))
' BitRate = 12.8MHz/(64*(BRVAL+1)), where BitRate = 0<= BRVAL >=127
' Beta must be = (2*fdev)/BR >= 2
'                (2*50kHz)/40kbs = 2.5
'*************************************************************************
'
' ********************* Frequency calculation ****************************
' Freq = 9/8 * 12.8MHz/R+1 * [75*(P+1)+S]
'
'
'
'
'=========================================================================
MRF_Init:

' This For/Next technique uses 341 less Words but takes 2.06ms compared to
' 1.34ms sequentially
  CSCON = 0                   ' Enable Chip Select 
  FOR inc = 0 TO 31
    SSP1BUF = inc << 1        ' Write bit with address
    GOSUB SSP_INT             ' Wait until MSSP module finishes task
    SSP1BUF = MRF_Config[inc] ' Write config value from list
    GOSUB SSP_INT             ' Wait until MSSP module finishes task
  NEXT inc
  CSCON = 1                   ' Disable Chip Select
RETURN  

' Same function as above but sequentially. Left here for comparison only
'
'   CSCON = 0               ' Enable Chip Select    
'' GCONREG value            ' 2.14.1
'   SSP1BUF = %00000000     ' Write bit with $00 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00101110     ' STBY mode, 915-928MHz band, Vtune +180mV
'                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   
'' DMODREG value            ' 2.14.2
'   SSP1BUF = %00000010     ' Write bit with $01 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %10000100     ' FSK Mod, Packet data and max IF gain
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' FDEVREG value            ' 2.14.3
'   SSP1BUF = %00000100     ' Write bit with $02 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000111     ' Freq deviation, calc = 50kHz 40k
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

'' BRSREG value             ' 2.14.4
'   SSP1BUF = %00000110     ' Write bit with $03 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00010011     ' Bit Rate, calc = 10kbs
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

'' FLTHREG value            ' 2.14.5
'   SSP1BUF = %00001000     ' Write bit with $04 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000000     ' Floor threshold for for OOK mode only
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' FIFOREG value            ' 2.14.6
'   SSP1BUF = %00001010     ' Write bit with $05 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00001110     ' 16 byte FIFO and 14 byte Threshold
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

'' R1CREG value             ' 2.14.7
'   SSP1BUF = %00001100     ' Write bit with $06 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01110111     ' $77 R1+P1+S1 = 921.00MHz
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' P1CREG value             ' 2.14.8
'   SSP1BUF = %00001110     ' Write bit with $07 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01100101     ' $65
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' S1CREG value             ' 2.14.9
'   SSP1BUF = %00010000     ' Write bit with $08 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00011001     ' $19
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' R2CREG value             ' 2.14.10
'   SSP1BUF = %00010010     ' Write bit with $09 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01110111     ' $77 R2+P2+S2 = 908.04MHz
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' P2CREG value             ' 2.14.11
'   SSP1BUF = %00010100     ' Write bit with $0A address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01100011     ' $63
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' S2CREG value             ' 2.14.12
'   SSP1BUF = %00010110     ' Write bit with $0B address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01000011     ' $43
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' PACREG value             ' 2.14.13
'   SSP1BUF = %00011000     ' Write bit with $0C address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000000     ' PA ramp control for OOK mode only
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   
                           
'' FTXRXIREG value          ' 2.15.1
'   SSP1BUF = %00011010     ' Write bit with $0D address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %11001100     ' IRQ0RX = RX Sync match, IRQ1RX = RX CRC Okay
'                           ' IRQ1TX = TX Done,       IRQ1TX = FIFO full
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
                           
'' FTPRIREG value           ' 2.15.2
'   SSP1BUF = %00011100     ' Write bit with $0E address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00111001     ' 5:IRQ0 TX Done, 4:TX start FIFO !empty, 0: 1 = Clear PLL lock
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' RSTHIREG value           ' 2.15.3
'   SSP1BUF = %00011110     ' Write bit with $0F address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00101101     ' RSSI threshold set to -95dBm. See 3.4.7.3
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' FILCREG value            ' 2.16.1
'   SSP1BUF = %00100000     ' Write bit with $10 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00110011     ' Passive filter = 137kHz, Butterworth = 100kHz
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

'' PFCREG value             ' 2.16.2
'   SSP1BUF = %00100010     ' Write bit with $11 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00111000     ' Polyphase Center Freq. set to 100kHz default
'                           ' for OOK only
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' SYNCREG value            ' 2.16.3
'   SSP1BUF = %00100100     ' Write bit with $12 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00110000     ' Sync word EN, 24bit, no errors allowed
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' RSTSREG value            ' 2.16.4
'   SSP1BUF = %00100110     ' Write bit with $13 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000111     ' Reserved, non zero value
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' RSVREG value              ' 2.16.5
'   SSP1BUF = %00101000     ' Write bit with $14 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000000     ' RSSI read only value
'                           ' RSSI[dBm] = 0.55 * RSSIVAL - 118.5[dBm]
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' OOKCREG value            ' 2.16.6
'   SSP1BUF = %00101010     ' Write bit with $15 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000000     ' OOK only, default value
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' SYNCV31REG value         ' 2.17.1
'   SSP1BUF = %00101100     ' Write bit with $16 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %10101010     ' Sync value, 1st byte = $AA
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' SYNCV23REG value         ' 2.17.2
'   SSP1BUF = %00101110     ' Write bit with $17 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01010101     ' Sync value, 2nd byte = $55
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task    

'' SYNCV15REG value         ' 2.17.3
'   SSP1BUF = %00110000     ' Write bit with $18 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %10101010     ' Sync value, 3rd byte = $AA
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task   

'' SYNCV07REG value         ' 2.17.4
'   SSP1BUF = %00110010     ' Write bit with $19 address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01010101     ' Sync value, 4th byte = $55
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' TXCONVREG value          ' 2.18.1
'   SSP1BUF = %00110100     ' Write bit with $1A address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01110000     ' TX filter default = 200kHz, TX Pwr = +13dBm
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task  

'' CLKOREG value            ' 2.19.1
'   SSP1BUF = %00110110     ' Write bit with $1B address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00000000     ' Clock out control disabled
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' PLOADREG value           ' 2.20.1
'   SSP1BUF = %00111000     ' Write bit with $1C address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %00010000     ' Manchester disabled, Packet length = 16 byte
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' NADDSREG value           ' 2.20.2
'   SSP1BUF = %00111010     ' Write bit with $1D address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %11001100     ' Node address = $CC
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' PKTCREG value            ' 2.20.3
'   SSP1BUF = %00111100     ' Write bit with $1E address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
'   SSP1BUF = %01011000     ' Pkt length fixed, preamble = 3 bytes, White ON
'                           ' CRC EN, Address filter OFF
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'' FCRCREG value            ' 2.20.4
'   SSP1BUF = %00111110     ' Write bit with $1F address
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task            
'   SSP1BUF = %00000000     ' FIFO auto clear if/CRC, FIFO Write on STBY
'   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   
'   CSCON = 1               ' Disable Chip Select

'RETURN

' Allow MSSP module to finish task
SSP_INT: 
   WHILE !PIR1.3: WEND
   PIR1.3 = 0
RETURN

'=========================================================================
'                           RF module RX mode config
' This routine takes xxxms to complete where the receive time uses xxxms
' of it with 16 bytes at 10kbs.
'=========================================================================
RX_mode:
   CSCON = 0               ' Enable Chip Select
   
'************ Set IRQ0 to /FIFOEmpty and IRQ1 to FIFO Threshold ***********
' FTXRXIREG value (INT3 & 4)   ' 2.15.1
   SSP1BUF = %00011010     ' Write bit with $0D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00100001     ' 7:6 IRQ0 = PLReady, 5:4 IRQ1 = CRCOK  11000001
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* RX mode **************************************
' GCONREG value            ' 2.14.1
   SSP1BUF = %00000000     ' Write bit with $00 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %01100001     ' RX mode, 902-915MHz band, Vtune via inductors
                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

   CSCON = 1               ' Disable Chip Select
   
RETURN

'************************* Read FIFO **************************************
' Reading the FIFO will clear IRQ0.
' Max clock allowed here is 1MHz
' This routine takes 696us to complete.
'**************************************************************************  
Read_FIFO:
  FOR x = 0 TO 15
    CSDAT = 0               ' Enable Chip Select
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    CSDAT = 1               ' Disable Chip Select
    RX_data[x] = SSP1BUF    ' Assign RX data to array (adds 150us to loop)
  NEXT x

RETURN


'=========================================================================
'                           RF module TX mode config
' This routine takes 20.9ms to complete where the transmit time uses 20.1ms
' of it with 16 bytes at 10kbs.
'=========================================================================
TX_mode:
   CSCON = 0               ' Enable Chip Select    

'********************** Set IRQ1 to TX Done *******************************
' FTXRXIREG value (INT4)   ' 2.15.1
   SSP1BUF = %00011010     ' Write bit with $0D address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %11001101     ' 3: IRQ1TX = TX Done
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* STBY mode **************************************
' GCONREG value            ' 2.14.1
   SSP1BUF = %00000000     ' Write bit with $00 address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task
   SSP1BUF = %00101000     ' STBY mode, 915-928MHz band, Vtune via inductors
                           ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

'************************* FIFO Write on STBY *****************************
' FCRCREG value            ' 2.20.4
   SSP1BUF = %00111110     ' Write bit with $1F address
   GOSUB SSP_INT           ' Wait until MSSP module finishes task            
   SSP1BUF = %00000000     ' FIFO auto clear if/CRC, FIFO Write on STBY
   GOSUB SSP_INT           ' Wait until MSSP module finishes task

   CSCON = 1               ' Disable Chip Select
   
'************************* Fill FIFO **************************************  
  FOR x = 1 TO 16
    CSDAT = 0             ' Enable Chip Select
    SSP1BUF = x           ' Write value
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    CSDAT = 1             ' Disable Chip Select
  NEXT x
   
'************************* Enable TX mode *********************************      
' GCONREG value           ' 2.14.1
  CSCON = 0               ' Enable Chip Select
    SSP1BUF = %00000000   ' Write bit with $00 address
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    SSP1BUF = %10001000   ' TX mode, 915-928MHz band, Vtune via inductors
                          ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
    GOSUB SSP_INT         ' Wait until MSSP module finishes task  
  CSCON = 1               ' Disable Chip Select
   
  WHILE !INT4: WEND       ' Wait until transmission is complete
  PAUSEUS 100             ' Wait a little
  
'************* Enable Sleep mode to turn Off transmitter*******************
' GCONREG value           ' 2.14.1
  CSCON = 0               ' Enable Chip Select
    SSP1BUF = %00000000   ' Write bit with $00 address
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
    SSP1BUF = %00101000   ' Sleep mode, 915-928MHz band, Vtune via inductors
                          ' :0, 0 = Enable R1/P1/S1, 1 = Enable R2/P2/S2 
    GOSUB SSP_INT         ' Wait until MSSP module finishes task
  CSCON = 1               ' Disable Chip Select
      
RETURN

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

PLL_check:
' FTPRIREG value            ' 2.15.2
  CSCON = 0                 ' Enable Chip Select
    SSP1BUF = %01011100     ' Read bit with $0E address
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task       
  CSCON = 1                 ' Disable Chip Select
RETURN

Reg_read:
  CSCON = 0                 ' Enable Chip Select
  FOR x = 0 TO 31    
    SSP1BUF = ((x << 1) | $40)  ' Shifts left 1 bit, sets $40 bit
    GOSUB SSP_INT           ' Wait until MSSP module finishes task
    SSPBUF = $0             ' Send 8 clock cycles
    GOSUB SSP_INT           ' Wait until MSSP module finishes task        
  NEXT x
  CSCON = 1                 ' Disable Chip Select
RETURN  

'=========================================================================
'                           Prestart settings       
'=========================================================================
Prestart:
GOSUB MRF_Init        ' Configure the Radio module, xxxms
PAUSEUS 100

Main:
  
 GOSUB TX_mode        ' Send 16 bytes with value 1~16
 PAUSE 50             ' every 50ms


'*************************************************************************
' Original test code had the transceiver: 
'   * send 16 bytes
'   * switch to RX mode
'   * monitor INT3 for 50ms, checking for RX data in FIFO buffer
'   * check last byte value and clear it and wait 200ms before repeating
'
' This allowed a ping pong function between the transmitter and receiver
' every 200ms when valid data was exchanged or the transmitter sent every
' 50ms when receiver was not active.
'*************************************************************************

'  IF RX_data[15] != 16 THEN
'    GOSUB TX_mode
'    GOSUB RX_mode
'  ENDIF  
  
'  FOR y = 0 TO 49
'    IF INT3 THEN 
'      GOSUB Read_FIFO      
'    ENDIF
'    PAUSE 1
'  NEXT y   
  
'  IF RX_data[15] = 16 THEN
'    RX_data[15] = 0
'    PAUSE 200
'  ENDIF

GOTO Main


END