Good Afternoon All-
I have been trying to get the MRF89XAM9A module to work with a PIC18F66J11 and I can't seem to get the read function to work (SPI) so I can see if I am setting up the module correctly.
I am hopefully writing to the module then reading back from it to verify the register - but it doesn't work......

I have looked on this forum for sometime but no one seems to have either tried or shared how to set up the regs and how to just very simply to communicate to/from it.
Its just a simple many transmitter to one receiver idea, only a payload of 3 bytes!

If anyone HAS gotten this to work, I would appreciate any guidance ......

Code below for all to see.....
-Steve

Code:
#CONFIG
    CONFIG  WDTEN = OFF           ; WDT NOT enabled
    CONFIG  STVREN = ON           ; Reset on stack overflow/underflow enabled
    CONFIG  XINST = OFF           ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    CONFIG  DEBUG = OFF           ; Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
    CONFIG  CP0 = OFF             ; Program memory is not code-protected
;    CONFIG  FOSC = INTOSC	  ; Internal oscillator, port function on RA6 and RA7 
    CONFIG  FOSC = INTOSCPLL	  ; INTOSC with PLL enabled, port function on RA6 and RA7
    CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor disabled
    CONFIG  IESO = OFF            ; Two-Speed Start-up disabled
    CONFIG  WDTPS = 512           ; 1:512
    CONFIG  CCP2MX = DEFAULT      ; ECCP2/P2A is multiplexed with RC1
    CONFIG  MSSPMSK = MSK7        ; 7-Bit Address Masking mode enable
#ENDCONFIG
Asm
    ERRORLEVEL -306
Endasm
'---------------------------------------------------------------------------------------
'Define the oscillator, INCLUDE files, A2D setup
    DEFINE  OSC 8					'8 MHz oscillator, internal x 4 via PLL = 32MHz  
    INCLUDE "DT_INTS-18.bas"                                                    'Base Interrupt System - miss DT!
    INCLUDE "ReEnterPBP-18.bas"                                                 'Include if using PBP interrupts
'    DEFINE RX2_INT PIR4,RC2IF,PIE4,RC2IE                'Used to ADD the 2nd serial port to the interrupt scheme
    DEFINE  ADC_BITS 10     ' 10-bit resolution
    DEFINE  ADC_CLOCK 5     ' Set clock source to Frc/16
    DEFINE  ADC_SAMPLEUS 50 ' Sample time in uS before A/D conversion is started
    Quanta  CON 1251        ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.251=Quanta
    ADCON1.7 = 1            ' Right justify for 10-bit
    ADCON0 = %00001001      ' VRef is 3.3v and Gnd, select AN2, A2D is ENABLED
    ANCON0_ALT = %11011010  ' AN2 and AN0 set as ANALOG input, rest are DIGITAL
    ANCON1_ALT = %11111111  ' Rest of inputs set as DIGITAL
'---------------------------------------------------------------------------------------
'OKAY, Lets set up the registers.....
    OSCCON=%01110000                                    'Sleep mode when sleep instr, 8MHz, System clock is via CONFIG BITS
'    OSCTUNE.6=1                                         'PLL ENABLED
'---------------------------------------------------------------------------------------
'Direction registers
    TRISA = %11111111                                   'Set PORTA for all OUTPUTs
    TRISB = %11011111                                   'PORTB is INPUT, except for RB5 
    TRISC = %10010011                                   'Mixed 
    TRISD = %00101110                                   'Mixed
    TRISE = %00000000                                   'Set PORTE for all OUTPUTS
    TRISF = %11111000                                   'Set PORTF for use with comparitor direction  
    TRISG = %10000000                                   'Set PORTG for all OUTPUTS, PORTD pullups ENABLED   
'---------------------------------------------------------------------------------------- 
'    ODCON1_ALT = 0                                          'DISABLES open drain outputs
'    ODCON2_ALT = 0                                          'DISABLES open drain outputs
'    ODCON3_ALT = 0                                          'DISABLES open drain outputs                
'----------------------------------------------------------------------------------------    

'----------------------------------------------------------------------------------------
'Assembly routine for the heartbeat LED, get vitals update
ASM
INT_LIST  macro     ; IntSource,     Label,           Type, ResetFlag?
        INT_Handler   TMR0_INT,   _ToggleHeartBeat,    PBP,   yes
    endm
    INT_CREATE                                                                  ; Creates the interrupt processor
ENDASM
T0CON=%10000100                                                                 'TMR0 enabled, 16 bit mode, use CLK0 (internal)
                                                                                'Low to High transition, use prescaler of 1:32
'T4CON=%01111111                                                                 '1:16 postscale, 1:16 prescaler, Timer4 is enabled
@    INT_ENABLE  TMR0_INT                                                       ;enable Timer0 interrupts

'-----------------------------------------------------------------------------------------------------------------------
'****Here is my SPI Setup****
'This is for the 1st SPI comm - used here for the MRF RF module
    SSP1STAT.7 = 0                                      'SMP=0, sample phase
    SSP1STAT.6 = 1                                      'CKE=1, xmits on rising edge
    SSP1CON1.5=1                                        'enable SPI
    SSP1CON1.4=0                                        'CKP=0, clk idles low
    SSP1CON1.3=0                                        'bit 3 to 0 indicate clock speed. bit 0 set means clock = OSC/4 
    SSP1CON1.2=0
    SSP1CON1.1=0
    SSP1CON1.0=0
    PIR1.3 = 0                                          'Clear the buffer status. 
'-----------------------------------------------------------------------------------------
    DEFINE DEBUG_REG    PORTC
    DEFINE DEBUG_BIT    6
    DEFINE DEBUG_BAUD   38400
    DEFINE DEBUG_MODE   0
'-----------------------------------------------------------------------------------------    

'-----------------------------------------------------------------------------------------    
'Additional I/O Definitions
        Active          var PORTD.0                                             'Active LED, Active LOW
        MRFReset        var PORTA.1                                             'MRF module reset
        MRFDataSel      var PORTA.4                                             'MRF module serial interface data chip select, active LOW
        MRFConfigSel    var PORTA.5                                             'MRF module serial interface configure chip select, active LOW
        MRFIrq0         var PORTB.0                                             'MRF module interupt 0
        MRFIrq1         var PORTC.2                                             'MRF module interupt 1
'------------------------------------------------------------------------------------------
'Variable List
        i               var byte  
        RF_Init_Values  var byte[32]                                            'An array to initialize the RF unit
        MRFSPIdata      var byte                                                'Data to/from MRF module
 '------------------------------------------------------------------------------------------
'Constants here
     RF_Init_Values[0] = $28                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
     RF_Init_Values[1] = $8C                                                   'FSK, max IF gain, Packet Mode
     RF_Init_Values[2] = $01                                                   '200KHz Freq Dev
     RF_Init_Values[3] = $63                                                   '2KBps
     RF_Init_Values[4] = $0C                                                   'for OOK mode, not apliable
     RF_Init_Values[5] = $0F                                                   '16Bytes FIFO, 10Bytes threshold transmit interrupt
     RF_Init_Values[6] = $77                                                   '915MHz R1 Reg
     RF_Init_Values[7] = $64                                                   '915MHz P1 Reg
     RF_Init_Values[8] = $32                                                   '915MHz S1 Reg
     RF_Init_Values[9] = $74                                                   '920MHz R2 Reg
     RF_Init_Values[10] = $62                                                  '920MHz P2 Reg
     RF_Init_Values[11] = $32                                                  '920MHz S2 Reg
     RF_Init_Values[12] = $38                                                  'config mode for OOK, not apliable
     RF_Init_Values[13] = $00                                                  'interrupts by default
     RF_Init_Values[14] = $00                                                  '
     RF_Init_Values[15] = $01                                                  '
     RF_Init_Values[16] = $A3                                                  'default filters config
     RF_Init_Values[17] = $38                                                  'default filters config
     RF_Init_Values[18] = $30                                                  'sync word ON, 24bits, 0 errors tolerance
     RF_Init_Values[19] = $00                                                  'reserved reg
     RF_Init_Values[20] = $00                                                  'RSII status read register, 0.5dB / bit
     RF_Init_Values[21] = $00                                                  'OOK config reg
     RF_Init_Values[22] = $53                                                  '"S" 1st byte of sync word
     RF_Init_Values[23] = $59                                                  '"Y" 2nd byte of sync word
     RF_Init_Values[24] = $44                                                  '"D" 3rd byte of sync word
     RF_Init_Values[25] = $00                                                  '
     RF_Init_Values[26] = $70                                                  'utoff fcy = 200KHz, output power = 13dBm 0b000
     RF_Init_Values[27] = $BC                                                  'clk out by default 427KHz
     RF_Init_Values[28] = $02                                                  '3 bytes payload
     RF_Init_Values[29] = $01                                                  'initial MAC ADDRESS, only for test
     RF_Init_Values[30] = $5E                                                  'Fix Packet Lenght, 3 bytes preamble, whitening ON, CRC ON, Node ADDR|0x00|0xFF filtering
     RF_Init_Values[31] = $00                                                  'FIFO autocreal enable if CRC fails, Write to FIFO in stby mode     for (i = 0; i < 32; i++)

'Push all the registers to the MRF and check that each one is written correctly
  
'---------------------------------------------------------------------------------------------
    goto Init                                           'Steps around subroutines
'---------------------------------------------------------------------------------------------
'Subroutines Here-

Write_MRF_SPIData:
             MRFDataSel=0                                                       'Select the chip
             SSP1BUF = MRFSPIdata
             while !PIR1.3 : wend
             PIR1.3=0                                                           'Reset the flag
             SSP1CON1.7=0                                                       'Clear collision bit
             MRFDataSel=1                                                       'Deselect the chip
             return 

Write_MRF_SPIConfig:
             MRFConfigSel=0                                                     'Select the chip
             SSP1BUF = MRFSPIdata
             while !PIR1.3 : wend
             PIR1.3=0                                                           'Reset the flag
             SSP1CON1.7=0                                                       'Clear collision bit
             MRFConfigSel=1                                                       'Deselect the chip
             pauseus 1
             return 

Read_MRF_SPIConfig:                         'NOT FINISHED!!!
             MRFConfigSel=0                                                     'Select the chip
             MRFSPIdata = SSP1BUF                                                'Equate buffers
             while SSP1STAT.0=0 : wend
             return           

MRF_Sleep:  MRFSPIdata=%00001000                                                 'SLEEP command
            gosub Write_MRF_SPIConfig                                            'Send command to MRF
            return
            
MRF_Wake:   MRFSPIdata=%00001001                                                 'Standby command
            gosub Write_MRF_SPIConfig                                            'Send command to MRF
            return
            
MRF_Init:   'Doesn't seem to work, hangs at the read used for verification
            debug "at MRF Initialize", 10, 13
            For i=0 to 31                                                       'Setup counter var to step through all regisiters
            MRFSPIdata=i                                                         'Sets up the address
            gosub Write_MRF_SPIConfig                                           'Send the address to MRF
            debug "1st write reg=",hex2 i,10,13
            MRFSPIdata=RF_Init_Values[i]                                         'Gets value for regisiter
            gosub Write_MRF_SPIConfig                                           'Send the data to MRF
            debug "2nd write data=",hex2 RF_Init_Values[i],10,13
            gosub Read_MRF_SPIConfig                                            'Read it back
            debug "MRF Config data: ",dec2 i," Reg     Data=", hex2 MRFSPIdata,10,13
            next i                                                              'Do for all addresses and all data
            return
            
'#########################################################################################################################
'#	Hookay Boyz, We are going to start this Pig!
'#########################################################################################################################
init:
            Active=1                                                            'LEDs OFF
            HVEn=0 : HVSel=0                                                    'Booster OFF
            MRFConfigSel=1                                                      'MRF config deselected
            MRFDataSel=1                                                        'MRF data deselected

'MRF initialization here
             SSP1CON1.7=0                                                       'Clear collision bit
             PIR1.3=0                                                           'Reset the flag
MRFinit:     gosub MRF_Init                                                     'Sets up all the registers (I hope)

main:        'Put stuff in here when module works
             goto main
            
            
            
            
            stop

'---[TMR0 - interrupt handler]---(Heartbeat)------------------------------------
ToggleHeartBeat:
                  toggle Active
                  @   INT_RETURN