+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 64
  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default MRF90XAM9A interfacing help

    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
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Ha, just got a stupid config direction error, still 'hangs' when reading back from the MRF.
    New register data here:
    TRISA = %00001001 'Set PORTA for mixed

    Regards,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    OK-
    The radio is still not working, and I have switched over to the SHIFTIN and SHIFTOUT to try .......
    When I try to read back from the module, it is not what I thought I wrote, so I don't know if my writing or reading is wrong.
    Anyone used this module sucessfully?
    Code below:
    Code:
    'PIC is PIC18F66J11
    'Using PBP3 GOLD 3.0.7.0
    'Microcode Studio Plus 5.0.0.5
    #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 "modedefs.bas"
        INCLUDE "DT_INTS-18.bas"                                                    'Base Interrupt System
        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
    
    '---------------------------------------------------------------------------------------
    '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 = %00001001                                                           'Set PORTA for mixed
        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   
    '----------------------------------------------------------------------------------------    
        DEFINE  ADC_BITS 10                                                         '10-bit resolution
        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
        ANCON0_ALT = %11110111                                                      'AN2 as ANALOG input, rest are DIGITAL
        ANCON1_ALT = %11111111                                                      'Rest of inputs set as DIGITAL
        ADCON0 = %00001101                                                          'Use Vss&Vdd, sel AN3, enable A2D module
        ADCON1 = %10010001                                                          'RIGHT justified, 4 TAD A2D aq time select, Fosc/8
    
    '----------------------------------------------------------------------------------------
    '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
    '-----------------------------------------------------------------------------------------    
    'Additional I/O Definitions
            SDO             var PORTC.5
            SDI             var PORTC.4
            SCLK            var PORTC.3
            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  
            Volts           Var Word                                                'Voltage
            ADval           VAR WORD                                                'A/D conversion result
            RF_Init_Values  var byte[32]                                            'An array to initialize the RF unit
            MRFSPIdata      var byte                                                'Data to/from MRF module
            MRFregister     var byte                                                'MRF register we want to read/write
     
     '------------------------------------------------------------------------------------------
    '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] = $01                                                  '
         RF_Init_Values[15] = $00                                                  '
         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
      
    
    '---------------------------------------------------------------------------------------------
    init:       MRFReset=0                                                          'MRF reset is active HIGH
                Active=1                                                            'LEDs OFF
                HVEn=0 : HVSel=0                                                    'Booster OFF
                MRFConfigSel=1                                                      'MRF config deselected
                MRFDataSel=1                                                        'MRF data deselected
                MRFSPIdata=0
    'MRF initialization here
                MRFConfigSel=0                                                      'Select the chip       
                for i=0 to 31
                    SHIFTOUT SDO, SCLK, 1,[i,RF_Init_Values[i]]                        'send data to register
                    pauseus 100
                next i
                for i=0 to 31
                    SHIFTOUT SDO, SCLK, 1,[i]                                           'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                                   'Get data from reg
                    debug "MRF Config data: Register ", hex2 i, "   Data=", hex2 MRFSPIdata,13
                    pauseus 100
                next i
                MRFConfigSel=1                                                      'Deselect the chip
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Haven't used this part, but if you could post your results perhaps we might be able to shed some light.
    Maybe post the capture of your debug output.
    Regards,
    TABSoft

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Also I think you need to release the CSCON line (MFRConfigSel=1) after you write the initialization values and before you try to read them back.

    From the DS.

    The new value of the register is effective from the rising edge of CSCON.

    When writing more than one register successively, it is not compulsory to toggle CSCON back high between two write sequences. The bytes are alternatively considered as address and value. In this instance, all new values will become effective on rising edge of CSCON.
    Regards,
    TABSoft

  6. #6
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    I could be completely wrong here but it looks like it uses 5 bit addresses for the config registers.

    Looking through the MRF89XA Datasheet further in section 2.11.1 (SPI CONFIG), figures 2-12 (Write Register Sequence) and 2-13 (Read Register Sequence) on page 24, it looks like the address bytes only use 5 bits for the address and 2 bits for a preamble and 1 bit for a postamble for a total of 8 bits.

    The Preamble bits look to be the following:
    Bit 1: is a start bit and it is a 0
    bit 2: is a R/W bit. 0=Write, 1=Read

    The Postamble Stop Bit is a 0

    So, if I interpret the timing diagrams correctly if you are trying to Write to register 0x00 your address byte will be 0x00. But, to read Register 0x00 your address byte will be 0x40 (%01000000) noting that the DS states all data is received and sent MSB first.
    Bit 7: Start bit = 0
    Bit 6: R/W bit = 1
    Bit 5: Address bit 4 = 0
    Bit 4: Address bit 3 = 0
    Bit 3: Address bit 2 = 0
    Bit 2: Address bit 1 = 0
    Bit 1: Address bit 0 = 0
    Bit 0: Stop bit = 0

    Carrying on further, if you want to Write to and Read from register 0x09, I think these are the address byte values to use.

    Register 0x09
    Write: 0x12 (%00010010)
    Bit 7: Start bit = 0
    Bit 6: R/W bit = 0
    Bit 5: Address bit 4 = 0
    Bit 4: Address bit 3 = 1
    Bit 3: Address bit 2 = 0
    Bit 2: Address bit 1 = 0
    Bit 1: Address bit 0 = 1
    Bit 0: Stop bit = 0


    Read:0x52 (%01010010)
    Bit 7: Start bit = 0
    Bit 6: R/W bit = 1
    Bit 5: Address bit 4 = 0
    Bit 4: Address bit 3 = 1
    Bit 3: Address bit 2 = 0
    Bit 2: Address bit 1 = 0
    Bit 1: Address bit 0 = 1
    Bit 0: Stop bit = 0

    If these assumptions are correct you can just AND your address with with the appropriate mask for the preamble and postamble bits for Write or Read.

    Hope I am not taking you down a rabbit hole....
    Regards,
    TABSoft

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Smile Re: MRF90XAM9A interfacing help

    Steve,
    I took a look at the Microchip AN1340 appnote "MRF89XA Radio Utility Driver Program".

    Link: http://www.microchip.com/wwwAppNotes...pnote=en549380

    I downloaded the Source Code from that link and reviewed the interface Write/Read routines to the MRF89Xa.

    They do indeed account for the Preamble and Postamble I mentioned earlier.

    Notice what they do with address during the RegisterSet and RegisterRead functions before they call the SPIPut function.

    Code:
    void RegisterSet(BYTE address, BYTE value)
    {
    	volatile BYTE tmp0RFIE = PHY_IRQ1_En;
    	#if defined(__PIC24F__)
    	volatile BYTE tmp1RFIE = PHY_IRQ0_En;
    	#endif
    	PHY_IRQ1_En = 0;
    	#if defined(__PIC24F__)
    	PHY_IRQ0_En = 0;
    	IEC0bits.T2IE = 0;
    	#endif
        Config_nCS = 0;
    	address = (address<<1);
        SPIPut(address);
        SPIPut(value);
        Config_nCS = 1;
    	PHY_IRQ1_En = tmp0RFIE;
    	#if defined(__PIC24F__)
    	PHY_IRQ0_En = tmp1RFIE;
    	IEC0bits.T2IE = 1;
    	#endif
    
    BYTE RegisterRead(BYTE address)
    {
    	volatile BYTE tmp0RFIE = PHY_IRQ1_En;
    	#if defined(__PIC24F__)
    	volatile BYTE tmp1RFIE = PHY_IRQ0_En;
    	IEC0bits.T2IE = 0;
    	#endif
    	BYTE value;
        Config_nCS = 0;
    	address = ((address<<1)|0x40);
        SPIPut(address);
    	value = SPIGet();
        Config_nCS = 1;
    	PHY_IRQ1_En = tmp0RFIE;
    	#if defined(__PIC24F__)
    	PHY_IRQ0_En = tmp1RFIE;
    	IEC0bits.T2IE = 1;
    	#endif
    For a Write (RegisterSet) they leftshift the address 1 position.
    For a Read (RegisterRead) they leftshift the address 1 position and then OR that with 0x40 (sets bit6)

    Hope this helps.
    Regards,
    TABSoft

  8. #8
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Thanks Guys!
    I had to be in California for a few weeks on business and now am back to the fun part of life.
    I will be looking into the posts and get back to the forum hopefully later today or tonight.
    Thanks and Regards.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  9. #9
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    TABSoft, you are CORRECT, I didn't notice the 3 'special' bits. Going to steal some time and see about this today........
    More later,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  10. #10
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    TABSoft-
    It took a while for me to try this (the 232 interface chip crashed so no debug data)
    What I have tried using SHIFTIN/OUT is as below:
    Code:
    [B]'MRF initialization here
    debug "@ MRF init", 10,13
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values[i]]               'send data to register
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
                
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) || $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                 'Address to read
    '                MRFConfigSel=1                                                  'Deselect the chip
    '                MRFConfigSel=0                                                  'Select the chip
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                               'Get data from reg
                    debug "MRF Config data: Register ", hex2 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
                MRFConfigSel=1                                                      'Deselect the chip
    However, the data I get back is:
    @ MRF init

    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00
    MRF Config data: Register FF Data=00

    Its got to be staring at me, but I just can't see it..........
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  11. #11
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Give this a shot.

    Code:
    [B]'MRF initialization here
    debug "@ MRF init", 10,13
    '            MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    MRFConfigSel=0                                                      'Select the chip       
    '                SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values[i]]               'send data to register
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
                    MRFConfigSel=1
                next i    
    '            MRFConfigSel=1                                                      'Deselect the chip
                
    '            MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
    '                MRFaddr=((i << 1) || $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    MRFConfigSel=0                                                      'Select the chip 
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                 'Address to read
    '                MRFConfigSel=1                                                  'Deselect the chip
    '                MRFConfigSel=0                                                  'Select the chip
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                               'Get data from reg
                    MRFConfigSel=1    
                    debug "MRF Config data: Register ", hex2 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    Regards,
    TABSoft

  12. #12
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I've found a few things, I 'think' the registers are being set correctly, but I cannot read back from it.
    I just don't get the full-duplex SPI in this case.
    New code and debug data below:
    Register constants:
    Code:
    '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] = $03                                                   '16Bytes FIFO, 3 Bytes threshold FIFO 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] = $19                                                  '00011001
         RF_Init_Values[15] = $00                                                  '
         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
    and the new code for writing to the part:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values[i]]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    'Try to read back the 1st 8 registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
                MRFConfigSel=1                                                      'Deselect the chip
    Then I try to send 3 bytes:
    Code:
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT_EN:   i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88]                                 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    XMIT:      MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$A1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$B1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$C1]
               MRFDataSel=1
               
    XMIT_STDBY:i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$28]                                 'send data, STANDBY, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
    and the debug data:
    Code:
    @ MRF init
    Addr=00000000  Value=28
    Addr=00000010  Value=8C
    Addr=00000100  Value=01
    Addr=00000110  Value=63
    Addr=00001000  Value=0C
    Addr=00001010  Value=03
    Addr=00001100  Value=77
    Addr=00001110  Value=64
    Addr=00010000  Value=32
    Addr=00010010  Value=74
    Addr=00010100  Value=62
    Addr=00010110  Value=32
    Addr=00011000  Value=38
    Addr=00011010  Value=00
    Addr=00011100  Value=19
    Addr=00011110  Value=00
    Addr=00100000  Value=A3
    Addr=00100010  Value=38
    Addr=00100100  Value=30
    Addr=00100110  Value=00
    Addr=00101000  Value=00
    Addr=00101010  Value=00
    Addr=00101100  Value=53
    Addr=00101110  Value=59
    Addr=00110000  Value=44
    Addr=00110010  Value=00
    Addr=00110100  Value=70
    Addr=00110110  Value=BC
    Addr=00111000  Value=02
    Addr=00111010  Value=01
    Addr=00111100  Value=5E
    Addr=00111110  Value=00
    MRF Config data: i=0   Register 01000000   Data=00
    MRF Config data: i=1   Register 01000010   Data=00
    MRF Config data: i=2   Register 01000100   Data=00
    MRF Config data: i=3   Register 01000110   Data=00
    MRF Config data: i=4   Register 01001000   Data=00
    MRF Config data: i=5   Register 01001010   Data=00
    MRF Config data: i=6   Register 01001100   Data=00
    MRF Config data: i=7   Register 01001110   Data=00
    Try sending 3 bytes
    I got my ZENA sniffer but it does not pick up anything in RAW sniffer mode........
    How can I check to see if it transmits correctly when I don't know if I can read the registers or see if it transmits?

    -Stuck in RF bleakness......
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  13. #13
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I did find the double 'OR' but it didn't seem to help.
    I also remarked the chip selects and deselects - no help either.
    Thanks though for trying!

    The code in the next post is where I am now, but, its confusing when you can't read the register to know if its set, then, transmission to a ZENA
    sniffer I found on another board said that it is useless if you are not using MiWi......
    Ugh!
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  14. #14
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I think, with no certainty, that reading the part has to be done using hardware SPI in full-duplex mode. I don't see any way to SHIFTIN to send the address, and then SHIFTOUT to get the data accurately.
    I used hardware SPI (simplex) on a different project and it worked great, but I wasn't trying to write and read simultaneously.

    Has anyone had any luck using hardware SPI in a full-duplex project?
    If so, any help would be appreciated - maybe that is what I need to do?

    Regards
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  15. #15
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Perhaps you need to strip this back to the basics?
    Forget trying to configure the MRF registers.
    Just try to read them after a POR.
    Also, what is your physical connectivity between the PIC and the MRF (Pinouts/Schematic)?
    Can you show us your aliases for MRFConfigSel, SCLK, SDO and SDI?
    I can't think of any reason why you shouldn't be able to read the config registers.
    Using Shiftin/Shiftout for SPI has not been a problem thus far.


    Create just a skeleton program to configure the PIC for the connectivity you need to the MRF and Serial port for debug.
    Then with the skeleton, just wait for the appropriate amount of time and try to read regs 00 - 07, but do not do this in a For/Next loop. Read each register in a serial fashion.

    E.g.
    MRFaddr = $40
    MRFConfigSel = 0
    SHIFTOUT SDO, SCLK, 1,[MRFaddr]
    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]
    MRFConfigSel = 1
    debug "MRF Config data:Register ", bin8 MRFaddr, " Data=", hex2 MRFSPIdata,13
    pause 50
    MRFaddr = $41
    MRFConfigSel = 0
    SHIFTOUT SDO, SCLK, 1,[MRFaddr]
    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]
    MRFConfigSel = 1
    debug "MRF Config data:Register ", bin8 MRFaddr, " Data=", hex2 MRFSPIdata,13
    pause 50

    etc...
    Regards,
    TABSoft

  16. #16
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Thanks for the continued interest - I will share code with all when the darn thing works <grin>.
    the IO assignments below:
    Code:
            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
    I have the time to work on this now (at home) so I will try just readinga register back - no loops.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  17. #17
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    OK, I have added the base read-back as you suggested, code below:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
    
                MRFConfigSel=1                                                      'Deselect the chip
    
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFaddr=$40
                MRFConfigSel=0                                                      'Select the chip 
                SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read  
                SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                MRFConfigSel=1                                                      'Deselect the chip
    debug "MRF Config data:  Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                pause 50
                MRFaddr=$41
                MRFConfigSel=0                                                      'Select the chip 
                SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read  
                SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                MRFConfigSel=1                                                      'Deselect the chip
    debug "MRF Config data:  Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
    Still doesn't read back. Debug data below:
    Code:
    @ MRF init
    Addr=00000000  Value=28
    Addr=00000010  Value=8C
    Addr=00000100  Value=01
    Addr=00000110  Value=63
    Addr=00001000  Value=0C
    Addr=00001010  Value=03
    Addr=00001100  Value=77
    Addr=00001110  Value=64
    Addr=00010000  Value=32
    Addr=00010010  Value=74
    Addr=00010100  Value=62
    Addr=00010110  Value=32
    Addr=00011000  Value=38
    Addr=00011010  Value=00
    Addr=00011100  Value=19
    Addr=00011110  Value=00
    Addr=00100000  Value=A3
    Addr=00100010  Value=38
    Addr=00100100  Value=30
    Addr=00100110  Value=00
    Addr=00101000  Value=00
    Addr=00101010  Value=00
    Addr=00101100  Value=53
    Addr=00101110  Value=59
    Addr=00110000  Value=44
    Addr=00110010  Value=00
    Addr=00110100  Value=70
    Addr=00110110  Value=BC
    Addr=00111000  Value=02
    Addr=00111010  Value=01
    Addr=00111100  Value=5E
    Addr=00111110  Value=00
    MRF Config data:  Register 01000000   Data=00
    
    MRF Config data:  Register 01000001   Data=00
    Still getting all zeros......... what am I missing?
    BTW, where in Texas are you?
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  18. #18
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I do have a question, in the timing diagram below:

    Name:  MRF90XAM9A SPI timing.png
Views: 862
Size:  149.8 KB

    It looks to me as if there is a dummy byte before the real data, am I confusing myself?
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  19. #19
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    I'm in the Houston Area.

    I'm not sure, but it looks like from your posting this is still part of a larger program.
    When I am faced with this kind of issue, I go back to square 1.
    Create a new program with only the absolute minimum in it.

    MCU Config Fuses
    Only the VARS needed for this operation (Reading the MRF registers and printing out to the Debug serial port).
    TRIS, ADCON, etc for only the pins for the above operation.
    Disable the PIC modules correctly.
    Aliases only for the SPI pins and the debug pins.
    NO Interrupt handling at all. If you are using DT Interrupts, don't do it now.

    Do not try to write to the MRF Config registers, only try to read from them after POR + 10ms minimum.

    I mean BASIC functionality only.
    No ADC, No Interrupts, no nothing.

    You are having a fundamental issue just trying to read from the device.

    Do you have a logic probe or OScope?
    If so, monitor the CSCON line and make sure it is going low as it should.
    Monitor the SCK and SDI (on the MRF) to make sure it is being pulsed by the PIC.

    Also, and I am not trying to insult you, but how about your wiring between the PIC and MRF for the SPI interface?
    PIC MRF Module
    MRFReset (PORTA.1) ----- RESET (Pin 2) for MRF89xAM9A (Leave this disconnected for these tests)
    MRFConfigSel (PORTA.5) ----- CSCON (Pin 3) for MRF89XAM9A
    MRFDataSel (PORTA.4) ----- CSDATA (Pin 8) for MRF89XAM9A (Should be High for all of these tests)
    SCLK (PORTx.y) ----- SCK (Pin 6) for MRF89XAM9A
    SDO (PORTx.y) ----- SDI (Pin 5) for MRF89XAM9A
    SDI (PORTx.y) ----- SDO (Pin 7) for MRF89XAM9A

    I didn't see your aliases for SCLK, SDO and SDI.

    I know all this probably sounds elementary, but that is what I would do.
    Regards,
    TABSoft

  20. #20
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    I guess I don't see what you're referring to "dummy byte before the real data".
    Where specifically are you speaking of?
    Regards,
    TABSoft

  21. #21
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I've got it. And I am dumb guy. In my design for a wireless sensor for the house, I have the 3.3 rail turned OFF when it is charging - I thought it might be a good idea not to turn on the transmitter while I was re-charging it........
    Well, while I am building/designing this, I ALWAYS HAD THE POWER SUPPLY ON, thus, turning OFF the B+ to the MRF - Dumb, Dumb, Dumb.
    OK, with code being the same, what I get is

    Code:
    @ MRF init
    Addr=00000000  Value=28
    Addr=00000010  Value=8C
    Addr=00000100  Value=01
    Addr=00000110  Value=63
    Addr=00001000  Value=0C
    Addr=00001010  Value=03
    Addr=00001100  Value=77
    Addr=00001110  Value=64
    Addr=00010000  Value=32
    Addr=00010010  Value=74
    Addr=00010100  Value=62
    Addr=00010110  Value=32
    Addr=00011000  Value=38
    Addr=00011010  Value=00
    Addr=00011100  Value=19
    Addr=00011110  Value=00
    Addr=00100000  Value=A3
    Addr=00100010  Value=38
    Addr=00100100  Value=30
    Addr=00100110  Value=00
    Addr=00101000  Value=00
    Addr=00101010  Value=00
    Addr=00101100  Value=53
    Addr=00101110  Value=59
    Addr=00110000  Value=44
    Addr=00110010  Value=00
    Addr=00110100  Value=70
    Addr=00110110  Value=BC
    Addr=00111000  Value=02
    Addr=00111010  Value=01
    Addr=00111100  Value=5E
    Addr=00111110  Value=00
    MRF Config data:  Register 01000000   Data=28
    
    MRF Config data:  Register 01000001   Data=28
    Which looks like the same date being read from Register zero.......
    Now armed with this knowledge, moving forward??
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  22. #22
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Back to cooking with gas........
    Code as was before:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    And the debug output:
    Code:
    @ MRF init
    Addr=00000000  Value=28
    Addr=00000010  Value=8C
    Addr=00000100  Value=01
    Addr=00000110  Value=63
    Addr=00001000  Value=0C
    Addr=00001010  Value=03
    Addr=00001100  Value=77
    Addr=00001110  Value=64
    Addr=00010000  Value=32
    Addr=00010010  Value=74
    Addr=00010100  Value=62
    Addr=00010110  Value=32
    Addr=00011000  Value=38
    Addr=00011010  Value=00
    Addr=00011100  Value=19
    Addr=00011110  Value=00
    Addr=00100000  Value=A3
    Addr=00100010  Value=38
    Addr=00100100  Value=30
    Addr=00100110  Value=00
    Addr=00101000  Value=00
    Addr=00101010  Value=00
    Addr=00101100  Value=53
    Addr=00101110  Value=59
    Addr=00110000  Value=44
    Addr=00110010  Value=00
    Addr=00110100  Value=70
    Addr=00110110  Value=BC
    Addr=00111000  Value=02
    Addr=00111010  Value=01
    Addr=00111100  Value=5E
    Addr=00111110  Value=00
    MRF Config data: i=0   Register 01000000   Data=28
    MRF Config data: i=1   Register 01000010   Data=8C
    MRF Config data: i=2   Register 01000100   Data=01
    MRF Config data: i=3   Register 01000110   Data=63
    MRF Config data: i=4   Register 01001000   Data=0C
    MRF Config data: i=5   Register 01001010   Data=03
    MRF Config data: i=6   Register 01001100   Data=77
    MRF Config data: i=7   Register 01001110   Data=64
    Which matches perfectly.

    I did scope the data in, out and noticed the pulses were not right at all.
    Then double-check the schematic and board to the datasheets - cuz, you know sometimes there is a mistake.........
    I appreciate your help, your going back to basics post was done after I had done it so we think alike - I am just DUMB!

    Your help in finding the correct way to address the registers was of immense help, I just missed that one completely.
    I'm off to the races, well, off to get the code for a wireless smart sensor system for the house.......
    When working, will post code to help others.

    Regards.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  23. #23
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Okay! Now you're starting to cook.

    Stick with just reading the 1st two config registers 00-01($40/$41), but reset your MRFSPIdata to a known value between the two reads.
    Read register 00
    display data out to debug port.
    MRFSPIdata = $BE (or some other value besides $28, $FF, $00, etc)
    Read register 01
    display data out to debug port.
    Regards,
    TABSoft

  24. #24
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Looks like we cross-posted.

    Glad you moving forward now.
    Hope to see your final version when you have it working.
    Regards,
    TABSoft

  25. #25
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    OK, TABSoft -
    I'm having trouble either sending or receiving data.... Thought I had this puppy trained.
    Registers are:
    Code:
    '     RF_Init_Values[0] = $28                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
         RF_Init_Values[0] = $68                                                   'RECEIVE 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] = $03                                                   '16Bytes FIFO, 3 Bytes threshold FIFO 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] = $0D                                                  'RCV:IRQ0=payload ready + IRQ1=CRC OK
                                                                                   'TX: mostly normal
         RF_Init_Values[14] = $19                                                  '00011001
         RF_Init_Values[15] = $00                                                  '
         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] = $43                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $53                                                  '"S" 3rd byte of sync word  - my initials!
         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++)
    And test code is:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT_EN:   i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88]                                 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    XMIT:      MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$A1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$B1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$C1]
               MRFDataSel=1
               
    RCV:       i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$68]                                 'send data, RECEIVE, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    Wait4Pkt:  If MRFIrq0=1 and MRFIrq1=1 then
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data3,data2,data1]                              'Get data from reg   
    debug "MRF payload:  Data3=",hex2 data3,"   Data2=",hex2 data2,"   Data1=",hex2 data1,13
               endif
               goto Wait4Pkt
    But after init and the confirming of the 1st few registers as before - it just sits there like a plum.

    I seem to have the config registers working, but now the FIFO seems to be playing hard.
    My interrupts aren't being set either due to not transmitting or receiving correctly.
    My payload is only 3 bytes, and the smallest the FIFO can be is 16 bytes.
    Not much for me to scope on this...... MC's DS is not too clear but you honed in on a failure I had, do you see anything wrong?
    This is my 1st RF project so I may have the registers all screwed up in order to work.... not too much out there as a guide.
    Regards.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  26. #26
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Sorry, I had posted an older piece of code. Newest code below:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT_EN:   i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88]                                 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    XMIT:      MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$A1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$B1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$C1]
               MRFDataSel=1
               
    RCV:       i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$68]                                 'send data, RECEIVE, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    Wait4Pkt:  If MRFIrq0=1 and MRFIrq1=1 then
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data3]                                     'Get data from reg   
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data2]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data1]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
    debug "MRF payload:  Data3=",hex2 data3,"   Data2=",hex2 data2,"   Data1=",hex2 data1,13
               endif
               goto Wait4Pkt
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  27. #27
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Can you help me with your setup and test bed, a pic or drawing?
    Do you have 2 of these transceivers with 2 pics trying to talk to one another?

    I would like to get my head wrapped around that 1st.
    Regards,
    TABSoft

  28. #28
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Thanks TABSoft-
    The setup is I have 2 units which should be the same (I have checked pinouts on PCB but I have made many cut and re-eoutes). Both units are running same code as shown earlier;
    1. Units powerup - sets registers and programming fuses
    Code:
    'RF Section:
    'Transmit is by fixed packet length of 3 bytes; Adress byte (2) and a Message byte.
    'Packet looks like: 3-byte preamble       -      3-byte Sync Word - 2-byte Address  - 1-byte Message -        2-byte CRC
    '                  |(added by pkt handler)|          'SCS'        |       (provided by code)         | (added by pkt handler)
    'Everything but the 3-byte payload is processed on receive and removed........
    
    'PIC is PIC18F66J11
    'Using PBP3 GOLD 3.0.7.0
    'Microcode Studio Plus 5.0.0.5
    #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 "modedefs.bas"
        INCLUDE "DT_INTS-18.bas"                                                    'Base Interrupt System
        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
    
    '---------------------------------------------------------------------------------------
    '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 = %00001001                                                           'Set PORTA for mixed
        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   
    '----------------------------------------------------------------------------------------
    2. Setup debug stuff
    Code:
        DEFINE DEBUG_REG    PORTC
        DEFINE DEBUG_BIT    6
        DEFINE DEBUG_BAUD   38400
        DEFINE DEBUG_MODE   0
    3. Setup I/O, aliases, vars, and constants
    Code:
            SDO             var PORTC.5
            SDI             var PORTC.4
            SCLK            var PORTC.3
            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
            MRFregister     var byte                                                'MRF register we want to read/write
            MRFaddr         var byte                                                'MRF address which is 5 bytes
            I2CData         var byte                                                'Data byte to/from I2C buffer
            junk            var byte                                                'Hold dummy data from MRF
            data1           var byte                                                '1st byte from MRF payload
            data2           var byte                                                '2nd byte from MRF payload
            data3           var byte                                                '3rd byte from MRF payload
    '------------------------------------------------------------------------------------------
    'Constants here
    '     RF_Init_Values[0] = $28                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
         RF_Init_Values[0] = $68                                                   'RECEIVE 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] = $03                                                   '16Bytes FIFO, 3 Bytes threshold FIFO 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] = $0D                                                  'RCV:IRQ0=payload ready + IRQ1=CRC OK
                                                                                   'TX: mostly normal
         RF_Init_Values[14] = $39                                                  '00111001
         RF_Init_Values[15] = $00                                                  '
         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] = $43                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $53                                                  '"S" 3rd byte of sync word  - my initials!
         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++)
    4. MRF initialization
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    5. Then I try to send something via MRF
    Code:
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT_EN:   i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88]                                 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    XMIT:      MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$A1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$B1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$C1]
               MRFDataSel=1
    6. Then MRF switches to receive to try to receive the 3 bytes (from the other unit of course).
    Code:
    RCV:       i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$68]                                 'send data, RECEIVE, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    Wait4Pkt:  If MRFIrq0=1 and MRFIrq1=1 then
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data3]                                     'Get data from reg   
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data2]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data1]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
    debug "MRF payload:  Data3=",hex2 data3,"   Data2=",hex2 data2,"   Data1=",hex2 data1,13
               endif
               goto Wait4Pkt
    My method is this:
    I turn on both units and watch for debug information.
    At this time both units should be in receive mode - not very helpful.
    So then I reset one of the units which will make it go through everything again including transmit the 3 bytes.
    Nothing comes up on the debug window.
    No interrupt gets set
    I do see IRQ1 (I think - from memory) go high briefly on the transmitting unit which should be transmission done.

    I think its in my NOT understanding the transmission/reception registers - I'm more of a digi-head with some analog.
    The DS is not too helpful and the Microchip boards and forum are also not very helpful.
    Most of the work seems to be using the 2.4 GHz unit but I wanted to use the sub-ghz unit due to my desire to go throughout the house.

    You can PM instead of taking up forum space, I will post my final code using hardware SPI and working code for the MRF - as I am certain there HAS to be others struggling!

    Regards.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  29. #29
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    I have a few ideas but let me have a day or two to noodle through it.
    Regards,
    TABSoft

  30. #30
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    I changed some of the register settings after re-reading the DS for a gazillion-ith time still no luck. I do get an IRQ0 pulse now, but I don't think I set it??
    Slightly modified code for continuous xmit and receive (different code for the 2 units).
    Code and registers below:
    Code:
    'Constants here
    '     RF_Init_Values[0] = $28                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
         RF_Init_Values[0] = $68                                                   'RECEIVE 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] = $03                                                   '100KHz Freq Dev
         RF_Init_Values[3] = $07                                                   '25 KBps
         RF_Init_Values[4] = $0C                                                   'for OOK mode, not apliable
         RF_Init_Values[5] = $0F                                                   '16Bytes FIFO, 
         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] = $08                                                  'RCV:IRQ0=payload ready + IRQ1=CRC OK
                                                                                   'TX: IRQ1=TXdone
         RF_Init_Values[14] = $35                                                  'FIFO starts filling when SYNC detected,TXDONE goes hi when done,
                                                                                   'RSSI IRQ when is above level set, enable PLL lock
         RF_Init_Values[15] = $00                                                  'RSSI interupt level zero - minimum
         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] = $07                                                  '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] = $43                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $53                                                  '"S" 3rd byte of sync word  - my initials!
         RF_Init_Values[25] = $00                                                  '
         RF_Init_Values[26] = $70                                                  'Cutoff fcy = 200KHz, output power = 13dBm 0b000
         RF_Init_Values[27] = $BC                                                  'clk out by default 427KHz
         RF_Init_Values[28] = $03                                                  '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] = $80                                                  'FIFO autocreal enable if CRC fails, Write to FIFO in stby mode 
    
    'MRF initialization here
    debug "@ MRF init", 10
                MRFConfigSel=0                                                      'Select the chip       
    'Going to try using shiftout before using hardware SPI
                for i=0 to 31                                                       'Sets up the index var for data
                    MRFaddr=(i << 1)                                                'Shifts address 1 bit to left, automatically gets start,write, and stop bits      
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)]               'send data to register
    debug "Addr=",bin8 MRFaddr,"  Value=",hex2 RF_Init_Values[i],13
                next i    
                MRFConfigSel=1                                                      'Deselect the chip
    
    'Try to read back some registers as a test to see if they were written correctly            
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT_EN:   i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88]                                 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    XMIT:      MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$A1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$B1]
               MRFDataSel=1
               MRFDataSel=0
               SHIFTOUT SDO, SCLK, 1,[$C1]
               MRFDataSel=1
               
               i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$28]                                 'STANDBY, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
    
    '           goto XMIT_EN                                                        'Remark this line to be receive all the time, otherwise its xmitting all the time
    
    RCV:       i=0                                                                 'Register of interest
               MRFaddr=(i<<1)                                                      'Gets register address format
               MRFConfigSel=0                                                      'Select the chip
               SHIFTOUT SDO, SCLK, 1,[MRFaddr,$68]                                 'send data, RECEIVE, 915-928, Vtune by tank caps, Enable R1 P1 S1
               MRFConfigSel=1                                                      'Deselect the chip
               
    Wait4Pkt:  If MRFIrq0=1 and MRFIrq1=1 then
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data3]                                     'Get data from reg   
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data2]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data1]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
    debug "MRF payload:  Data3=",hex2 data3,"   Data2=",hex2 data2,"   Data1=",hex2 data1,13
               endif
               goto Wait4Pkt
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  31. #31
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    I went through the datasheet again, and again.
    I also went through Microchips MRF Radiodriver software source code, link here.

    Here is what I put together, see if this helps at all.......

    Code:
         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] = $0B                                                   'Change from 200KHz Freq Dev to 33KHz Dev
         RF_Init_Values[3] = $63                                                   '2KBps
         RF_Init_Values[4] = $0C                                                   'for OOK mode, not apliable
         RF_Init_Values[5] = $03                                                   '16Bytes FIFO, 3 Bytes threshold FIFO 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] = $08                                                  'PLREADY, CRCOK, TXDONE, FIFO Not Full, FIFO Empty, No FIFO Overrun
                                                                                   'TX: mostly normal
         RF_Init_Values[14] = $0B                                                  '00111001
         RF_Init_Values[15] = $00                                                  '
         RF_Init_Values[16] = $41                                                  '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] = $07                                                  '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] = $43                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $53                                                  '"S" 3rd byte of sync word  - my initials!
         RF_Init_Values[25] = $00                                                  '
         RF_Init_Values[26] = $F0                                                  'utoff fcy = 200KHz, output power = 13dBm 0b000
         RF_Init_Values[27] = $80                                                  'clk out by default 427KHz
         RF_Init_Values[28] = $03                                                  '3 bytes payload
         RF_Init_Values[29] = $01                                                  'initial MAC ADDRESS, only for test
         RF_Init_Values[30] = $4E                                                  '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++)
        
    RF_STANDBY     con $20      'Standby RF Mode     
    RF_SYNTHESIZER con $40      'Synthesizer Mode (Test if RF Module is on and PLL Locked and working)
    RF_RECEIVER    con $60      'Receive Mode
    RF_TRANSMITTER con $80      'Transmit Mode
    
    TxPacket var byte[16]   'Packet Buffer
    bRF_Mode var byte       'Used to set RF Mode
    RF_Mode var byte
    wr_FIFO_Val var byte    'byte to load into RF FIFO
    bReg_Address var byte   'byte for which register to set/read
    bReg_Value var byte     'Value of register to set/read
    TxPacketLen var byte    'Number of bytes to send
    i var byte    
    PLL_LOCK var bit        'Bit to read PLL Lock Flag
    
    
    TestMe:
        gosub MRFInint
        TxPacket[0] = $A1
        TxPacket[1] = $B1
        TxPacket[2] = $C1
        TxPacketLen = 3
        gosub Send_Packet
        bRF_Mode = RF_STANDBY
        gosub SetRFMode
    
        goto RCV    'This is a jump to your receive routine
        
    MRFInit:
    'Initialize the MRF Module
        'Intial setup
        for i = 0 to 31
            bReg_Address = i
            bReg_Value = RF_Init_Values(i)
            gosub RegisterSet    
        next i
    
        'Test the module setup
        'Clear the PLL Lock flag by setting LSTLPLL to 1
        bReg_Address = $0E  'FTPRIREG
        gosub RegisterRead
        bReg_Value = bReg_Value | $02   'Set LSTLPLL to 1
        gosub RegisterSet   'Clear the flag
        
        'Enable Synthesizer mode and test LSTSPLL stays at 1 (PLL Locked)
        bRF_Mode = RF_SYNTHESIZER
        gosub SetRFMode
    
        'Verify PLL Lock Flag
        bReg_Address = $0E  'FTPRIREG
        gosub RegisterRead
        PLL_LOCK = 0
        PLL_LOCK = bReg_Value.1
        'You can test this bit to see if PLL Is Locked
        
        'Change to Standby  
        bRF_Mode = RF_STANDBY
        gosub SetRFMode
        
        return
    
    Send_Packet:
        
        'Set Standby mode
        bRF_Mode = RF_STANDBY
        gosub SetRFMode
        
        'Enable FIFO access in Standby mode
        bReg_Address = $1F  'Register 31
        bReg_Value = (RF_Init_Values(bReg_Address) & $BF) | $00
        gosub RegisterSet
        
        'Clear FIFO Overrun
        bReg_Address = $0D  'Register 13
        bReg_Value = (RF_Init_Values(bReg_Address) | $01)
        gosub RegisterSet
        
        'Set PLL Locked
        bReg_Address = $0E  'Register 13
        bReg_Value = (RF_Init_Values(bReg_Address) | $02)
        gosub RegisterSet
        
        For i = 0 to (TxPacketLen-1)
            'Wite the Packets to the FIFO
            wr_FIFO_Val = TxPacket[i]
            gosub WriteFIFO
        Next i 
       
        'Set RFMode to Transmit
        bRF_Mode = RF_TRANSMITTER
        gosub SetRFMode
        pause 5 'Pause 5ms
        
        return
            
    WriteFIFO:
    'Inputs: wr_FIFO_Val
        
        MRFDataSel=0                
        SHIFTOUT SDO, SCLK, 1,[wr_FIFO_Val] 
        MRFDataSel=1                
    
        return
        
    SetRFMode:
    ' Inputs bRF_Mode
        'SetRFMode(RF_STANDBY); (mcparam0_read & 0x1F) | RF_STANDBY) = (6E & 1F) | 20 = 2E
        bReg_Address = $00  'MCPARAM0
        gosub RegisterRead
        mcparam0_read = bReg_Value
        bReg_Value = (bReg_Value & $1F) | bRF_Mode
        bReg_Address = $00
        gosub RegisterSet
        RF_Mode = bRF_Mode
    
    
        return
        
        
        
    RegisterSet:
    'Inputs: bReg_Address, bReg_Value
        MRFaddr=(bReg_Address<<1)                                           'Gets register address format
        MRFConfigSel=0                                                      'Select the chip
        SHIFTOUT SDO, SCLK, 1,[MRFaddr,bReg_Value]                          'Set the register
        MRFConfigSel=1                                                      'Deselect the chip
     
        
        return
        
    RegisterRead:
    'Inputs: bReg_Address
    'Outputs: bReg_Value
        
        MRFaddr = ((bReg_Address << 1) | $40)               'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits         
        MRFConfigSel = 0                                    'Select the chip
        SHIFTOUT SDO, SCLK, 1,[MRFaddr]                     'Address to read
        SHIFTIN SDI, SCLK, 0,[bReg_Value]                   'Get data from reg
        MRFConfigSel = 1                                    'DeSelect the chip
        
        return
    Regards,
    TABSoft

  32. #32
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Thanks, here is the update:
    Did add a var that was left out (mcparam0_read var byte) and corrected a misspell (gosub MRFInint changed to gosub MRFInit).
    Register constants (some were not changed per my interpretation of DS - BUT, I will try them later):
    Code:
    'Constants here
         RF_Init_Values[0] = $28                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
    '     RF_Init_Values[0] = $68                                                   'RECEIVE 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] = $0B                                                   '33KHz Freq Dev
         RF_Init_Values[3] = $63                                                   '2KBps
         RF_Init_Values[4] = $0C                                                   'for OOK mode, not apliable
         RF_Init_Values[5] = $03                                                   '16Bytes FIFO, 3 bytes threshold FIFO 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] = $08                                                  'RCV:IRQ0=payload ready + IRQ1=CRC OK
                                                                                   'TX: IRQ1=TXdone
         RF_Init_Values[14] = $35                                                  'FIFO starts filling when SYNC detected,TXDONE goes hi when done,
                                                                                   'RSSI IRQ when is above level set, enable PLL lock
         RF_Init_Values[14] = $0B                                                  '
                                                                                   '
         RF_Init_Values[15] = $00                                                  'RSSI interupt level zero - minimum
         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] = $07                                                  '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] = $43                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $53                                                  '"S" 3rd byte of sync word  - my initials!
         RF_Init_Values[25] = $00                                                  '
         RF_Init_Values[26] = $70                                                  'Cutoff fcy = 200KHz, output power = 13dBm 0b000
         RF_Init_Values[27] = $BC                                                  'clk out by default 427KHz
         RF_Init_Values[28] = $03                                                  '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] = $80                                                  'FIFO autocreal enable if CRC fails, Write to FIFO in stby mode 
    
    'Push all the registers to the MRF and check that each one is written correctly
         RF_STANDBY     con $20                                                    'Standby RF Mode     
         RF_SYNTHESIZER con $40                                                    'Synthesizer Mode (Test if RF Module is on and PLL Locked and working)
         RF_RECEIVER    con $60                                                    'Receive Mode
         RF_TRANSMITTER con $80                                                    'Transmit Mode
    Added your subroutines:
    Code:
    'New Subs - thanks to TABSoft
    MRFInit:'Initialize the MRF Module
                'Intial setup
                for i = 0 to 31
                    bReg_Address = i
                    bReg_Value = RF_Init_Values(i)
                    gosub RegisterSet    
                next i
                'Test the module setup
                'Clear the PLL Lock flag by setting LSTLPLL to 1
                bReg_Address = $0E                                                  'FTPRIREG
                gosub RegisterRead
                bReg_Value = bReg_Value | $02                                       'Set LSTLPLL to 1
                gosub RegisterSet                                                   'Clear the flag
        
                'Enable Synthesizer mode and test LSTSPLL stays at 1 (PLL Locked)
                bRF_Mode = RF_SYNTHESIZER
                gosub SetRFMode
    
                'Verify PLL Lock Flag
                bReg_Address = $0E                                                  'FTPRIREG
                gosub RegisterRead
                PLL_LOCK = 0
                PLL_LOCK = bReg_Value.1
                         'You can test this bit to see if PLL Is Locked
        
               'Change to Standby  
                bRF_Mode = RF_STANDBY
                gosub SetRFMode
                return
                
    Send_Packet:    
                'Set Standby mode
                bRF_Mode = RF_STANDBY
                gosub SetRFMode
        
                'Enable FIFO access in Standby mode
                bReg_Address = $1F  'Register 31
                bReg_Value = (RF_Init_Values(bReg_Address) & $BF) | $00
                gosub RegisterSet
        
                'Clear FIFO Overrun
                bReg_Address = $0D  'Register 13
                bReg_Value = (RF_Init_Values(bReg_Address) | $01)
                gosub RegisterSet
        
                'Set PLL Locked
                bReg_Address = $0E  'Register 13
                bReg_Value = (RF_Init_Values(bReg_Address) | $02)
                gosub RegisterSet
        
                For i = 0 to (TxPacketLen-1)
                'Wite the Packets to the FIFO
                wr_FIFO_Val = TxPacket[i]
                gosub WriteFIFO
                Next i 
       
                'Set RFMode to Transmit
                bRF_Mode = RF_TRANSMITTER
                gosub SetRFMode
                pause 5 'Pause 5ms
                return
    
    WriteFIFO:  'Inputs: wr_FIFO_Val
        
                MRFDataSel=0                
                SHIFTOUT SDO, SCLK, 1,[wr_FIFO_Val] 
                MRFDataSel=1                
                return
    
    SetRFMode:  ' Inputs bRF_Mode
                'SetRFMode(RF_STANDBY); (mcparam0_read & 0x1F) | RF_STANDBY) = (6E & 1F) | 20 = 2E
                bReg_Address = $00  'MCPARAM0
                gosub RegisterRead
                mcparam0_read = bReg_Value
                bReg_Value = (bReg_Value & $1F) | bRF_Mode
                bReg_Address = $00
                gosub RegisterSet
                RF_Mode = bRF_Mode
                return
    
    RegisterSet:'Inputs: bReg_Address, bReg_Value
                MRFaddr=(bReg_Address<<1)                                          'Gets register address format
                MRFConfigSel=0                                                     'Select the chip
                SHIFTOUT SDO, SCLK, 1,[MRFaddr,bReg_Value]                         'Set the register
                MRFConfigSel=1                                                     'Deselect the chip
                return
    
    RegisterRead:'Inputs: bReg_Address - Outputs: bReg_Value
                MRFaddr = ((bReg_Address << 1) | $40)                              'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits         
                MRFConfigSel = 0                                                   'Select the chip
                SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                    'Address to read
                SHIFTIN SDI, SCLK, 0,[bReg_Value]                                  'Get data from reg
                MRFConfigSel = 1                                                   'DeSelect the chip
                return
    And added test code:
    Code:
    'MRF initialization here
    debug "@ MRF init", 10
    TestMRF:
                gosub MRFInit
    
    'Try to read back 1st 8 registers as a test to see if they were written correctly - remove when done debugging           
                MRFConfigSel=0                                                      'Select the chip 
                for i = 0 to 7                                                      'Sets up address to read
                    MRFaddr=((i << 1) | $40)                                       'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
                    SHIFTOUT SDO, SCLK, 1,[MRFaddr]                                'Address to read
                    SHIFTIN SDI, SCLK, 0,[MRFSPIdata]                              'Get data from reg
                    debug "MRF Config data: i=", dec1 i, "   Register ", bin8 MRFaddr, "   Data=", hex2 MRFSPIdata,13
                next i
    
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT:       TxPacket[0] = $A1
                TxPacket[1] = $B1
                TxPacket[2] = $C1
                TxPacketLen = 3
                gosub Send_Packet
                bRF_Mode = RF_STANDBY
                gosub SetRFMode
               goto XMIT                                                          'Remark this line to be receive all the time, othewrwise its xmitting all the time
    
    RCV:        bRF_Mode = RF_RECEIVER
                gosub SetRFMode                                                    'Set to receive
    
               
    Wait4Pkt:  If MRFIrq0=1 and MRFIrq1=1 then
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data3]                                     'Get data from reg   
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data2]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
                  MRFDataSel=0                                                     'Select chip cuz we have a packet ready and CRC is good
                  SHIFTIN SDI, SCLK, 0,[data1]                                     'Get data from reg  
                  MRFDataSel=1                                                     'De-Select chip
    debug "MRF payload:  Data3=",hex2 data3,"   Data2=",hex2 data2,"   Data1=",hex2 data1,13
               endif
               goto Wait4Pkt
    But the receiver (with goto XMIT rem'd) doesn't print anything to the screen.
    Its like solving for simultaneous equations........ making an assumption (huge) that the transmitter is actually transmitting, then the problem is in the receiver.
    The SYNC is the same front and back 'SCS' so that shouldn't make a difference.
    The payload is 3 bytes......
    However, my trigger to debug the MRF is if both IRQ lines go high, my scope is telling me neither is going high so either the interrupt register is improperly configured or its not recognizing the payload.
    IF the transmitter is working.......
    See if you agree with my register values?

    Regards.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  33. #33
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Looking at the PLL, so I modified the init to debug if PLL is locked"
    Code:
                'Verify PLL Lock Flag
                bReg_Address = $0E                                                  'FTPRIREG
                gosub RegisterRead
                PLL_LOCK = 0
                PLL_LOCK = bReg_Value.1
                         'You can test this bit to see if PLL Is Locked
    debug "PLL Lock=",bin1 PLL_LOCK,13
    Debug shows a '0' so its not locked..... not real sure what that means...... MC site for support on this is thin indeed.
    I can't believe no one who has read this thread has not done this, I can't believe I am the only one!
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  34. #34
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Well, I attempted to modify MC's Radiodriver software to match your attempts.
    Perhaps you should drop back to exactly what they are doing.
    In essence they are running in Packet mode, variable length packets with a buffer threshold of 1 packet.
    They also use a (4) byte SYNC sequence.

    Here are the register settings they use.
    Code:
         RF_Init_Values[0] = $2E                                                   'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
         RF_Init_Values[1] = $84                                                   'FSK, max IF gain, Packet Mode
         RF_Init_Values[2] = $0B                                                   'Change from 200KHz Freq Dev to 33KHz Dev
         RF_Init_Values[3] = $63                                                   '2KBps
         RF_Init_Values[4] = $0C                                                   'for OOK mode, not apliable
         RF_Init_Values[5] = $C1                                                   '16Bytes FIFO, 3 Bytes threshold FIFO 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] = $C8                                                  'PLREADY, CRCOK, TXDONE, FIFO Not Full, FIFO Empty, No FIFO Overrun
                                                                                   'TX: mostly normal
         RF_Init_Values[14] = $0B                                                  '00111001
         RF_Init_Values[15] = $00                                                  '
         RF_Init_Values[16] = $41                                                  'default filters config
         RF_Init_Values[17] = $38                                                  'default filters config
         RF_Init_Values[18] = $38                                                  'sync word ON, 24bits, 0 errors tolerance
         RF_Init_Values[19] = $07                                                  '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] = $69                                                  '"S" 1st byte of sync word
         RF_Init_Values[23] = $81                                                  '"C" 2nd byte of sync word
         RF_Init_Values[24] = $7E                                                  '"S" 3rd byte of sync word  - my initials!
         RF_Init_Values[25] = $96                                                  '
         RF_Init_Values[26] = $F0                                                  'utoff fcy = 200KHz, output power = 13dBm 0b000
         RF_Init_Values[27] = $80                                                  'clk out by default 427KHz
         RF_Init_Values[28] = $40                                                  '3 bytes payload
         RF_Init_Values[29] = $00                                                  'initial MAC ADDRESS, only for test
         RF_Init_Values[30] = $E8                                                  '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++)
    Then alter your XMIT: to handle variable length packets.

    Code:
    'Try sending something
    debug "Try sending 3 bytes",13
    XMIT:       TxPacket[0] = $04   'Number of payload bytes + address byte
                TxPacket[1] = $00   'Hard coded address byte
                TxPacket[2] = $A1
                TxPacket[3] = $B1
                TxPacket[4] = $C1
                TxPacketLen = 5
                gosub Send_Packet
                bRF_Mode = RF_STANDBY
                gosub SetRFMode
                goto XMIT                                                          'Remark this line to be receive all the time, othewrwise its xmitting all the time
    I believe the key here is to make sure that the PLL Lock flag is setting.
    This lets you know that the Radio has turned on correctly.
    Regards,
    TABSoft

  35. #35
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Are you using this module?
    MRF89XAM9A
    Regards,
    TABSoft

  36. #36
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Yes, trying to.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  37. #37
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: MRF90XAM9A interfacing help

    Okay.
    Reading the MRF89XAM9A datasheet on page 7 "1.3.5 VCO TANK TRIM VALUE", it says you need to set VCOT<1:0> = ‘01’.
    From Datasheet:
    1.3.5 VCO TANK TRIM VALUE
    The VCO Trim bits (VCOT<1:0>) in the
    GCONREG<2:1> should be set for VCOT<1:0> = ‘01’
    for the inductor values of the module.

    That would change MC's value of Register 00 from $2E to $2A, and your value of Register 00 from $28 to $2A.

    That might explain why the PLL won't lock.
    Regards,
    TABSoft

  38. #38
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    OK, changed all registers to your last post.
    Added the changes to the 'send something' portion.
    Still no received data.
    Lost the IRQ0 pulses on the transmitter.
    No IRQ0 or IRQ1 pulses on the receiver - have never had any.
    Pulses going into SDI and SCK on transmitter.
    No pulses on SDO or SCK on the receiver - no surprise there, if it doesn't trip an IRQ line.

    I'll look into how to setup the unit for receive all the time?
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  39. #39
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Crossed posts.....
    I changed the Register 00 to $2A and it still reports PLL bit as '0'.
    BUT, on page 30 of the DS it shows $00 for VTune to be determined by the inductors - not $01 ???
    Forget it, I was still reading the 140 page DS not the 36 page one for the module.
    I get it.....

    The RESET pin is tied to an IO on the proc, it is currently held low, but the module datasheet says in a high impedance state.
    Wonder if this is my issue? Should I let it float?
    Last edited by ecoli-557; - 17th February 2015 at 00:36.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  40. #40
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: MRF90XAM9A interfacing help

    Made PORTA.1 an input which is tied to the RESET pin, no help either.......

    Went back to earlier code and changed register $00 to $2A and have my pulses out of IRQ0 on the transmitter, but still nothing on the receiver.......
    Need a sniffer that works!
    Last edited by ecoli-557; - 17th February 2015 at 00:55.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

Similar Threads

  1. Interfacing LC75854
    By MR2010 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 18th July 2010, 02:42
  2. Keypad Interfacing
    By uaf5000 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2010, 02:35
  3. Interfacing with the ISD4003
    By lerameur in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd June 2008, 15:25
  4. SPI Interfacing
    By toofastdave in forum Serial
    Replies: 8
    Last Post: - 18th November 2007, 12:15
  5. interfacing LCD
    By husakhalid in forum mel PIC BASIC
    Replies: 3
    Last Post: - 30th May 2006, 22:53

Members who have read this thread : 25

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts