PDA

View Full Version : MRF90XAM9A interfacing help



ecoli-557
- 19th January 2015, 22:09
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



#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

ecoli-557
- 19th January 2015, 22:35
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

ecoli-557
- 21st January 2015, 17:29
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:


'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

Tabsoft
- 22nd January 2015, 00:22
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.

Tabsoft
- 22nd January 2015, 01:07
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.

Tabsoft
- 22nd January 2015, 06:05
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....

Tabsoft
- 22nd January 2015, 22:23
Steve,
I took a look at the Microchip AN1340 appnote "MRF89XA Radio Utility Driver Program".

Link: http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=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.


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. :smile:

ecoli-557
- 10th February 2015, 16:49
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.

ecoli-557
- 10th February 2015, 17:22
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

ecoli-557
- 11th February 2015, 17:10
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:


[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..........

Tabsoft
- 11th February 2015, 18:50
Give this a shot.



[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

ecoli-557
- 11th February 2015, 20:59
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:


'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:


'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:


'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:


@ 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......

ecoli-557
- 12th February 2015, 03:27
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!

ecoli-557
- 12th February 2015, 03:34
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

Tabsoft
- 12th February 2015, 16:03
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...

ecoli-557
- 12th February 2015, 19:48
Thanks for the continued interest - I will share code with all when the darn thing works <grin>.
the IO assignments below:


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.

ecoli-557
- 12th February 2015, 20:03
OK, I have added the base read-back as you suggested, code below:


'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:


@ 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?

ecoli-557
- 12th February 2015, 20:21
I do have a question, in the timing diagram below:

7717

It looks to me as if there is a dummy byte before the real data, am I confusing myself?

Tabsoft
- 12th February 2015, 21:10
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.:)

Tabsoft
- 12th February 2015, 21:14
I guess I don't see what you're referring to "dummy byte before the real data".
Where specifically are you speaking of?

ecoli-557
- 12th February 2015, 21:19
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



@ 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??

ecoli-557
- 12th February 2015, 21:33
Back to cooking with gas........
Code as was before:


'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:


@ 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.

Tabsoft
- 12th February 2015, 21:34
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.

Tabsoft
- 12th February 2015, 21:36
Looks like we cross-posted.

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

ecoli-557
- 13th February 2015, 18:51
OK, TABSoft -
I'm having trouble either sending or receiving data.... Thought I had this puppy trained.
Registers are:


' 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:


'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.

ecoli-557
- 13th February 2015, 19:04
Sorry, I had posted an older piece of code. Newest code below:


'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

Tabsoft
- 13th February 2015, 21:00
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. :)

ecoli-557
- 14th February 2015, 16:35
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


'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


DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
DEFINE DEBUG_BAUD 38400
DEFINE DEBUG_MODE 0

3. Setup I/O, aliases, vars, and constants


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


'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


'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).


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.

Tabsoft
- 14th February 2015, 20:22
I have a few ideas but let me have a day or two to noodle through it.

ecoli-557
- 16th February 2015, 19:31
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:


'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

Tabsoft
- 16th February 2015, 19:36
I went through the datasheet again, and again.
I also went through Microchips MRF Radiodriver software source code, link here (http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en549380).

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




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

ecoli-557
- 16th February 2015, 21:14
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):


'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:


'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:


'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.

ecoli-557
- 16th February 2015, 21:45
Looking at the PLL, so I modified the init to debug if PLL is locked"


'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!

Tabsoft
- 16th February 2015, 22:23
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.


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.



'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.

Tabsoft
- 16th February 2015, 22:29
Are you using this module?
MRF89XAM9A

ecoli-557
- 16th February 2015, 22:51
Yes, trying to.

Tabsoft
- 16th February 2015, 23:08
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.

ecoli-557
- 16th February 2015, 23:14
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?

ecoli-557
- 16th February 2015, 23:19
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?

ecoli-557
- 16th February 2015, 23:49
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!

ecoli-557
- 17th February 2015, 01:40
Changed the registers one more time - still no PLL lock being reported.
Below:


RF_Init_Values[0] = $2A '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] = $03 '100KHz Freq Dev
RF_Init_Values[3] = $07 '25kbps
RF_Init_Values[4] = $0C 'for OOK mode, not apliable
RF_Init_Values[5] = $01 '16Bytes FIFO, 1 byte 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] = $00 'RCV:IRQ0=payload ready + IRQ1=CRC OK
'TX: IRQ1=TXdone
RF_Init_Values[14] = $01 '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] = $53 '"S" 2nd byte of sync word
RF_Init_Values[24] = $53 '"S" 3rd byte of sync word - my initials!
RF_Init_Values[25] = $53 '"S" just in case
RF_Init_Values[26] = $72 'Cutoff fcy = 200KHz, output power = 13dBm 0b000
RF_Init_Values[27] = $3C 'clk out disabled - 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] = $00 'FIFO autocreal enable if CRC fails, Write to FIFO in stby mode



I'm frustrated ......

ecoli-557
- 17th February 2015, 19:24
I now get a PLL lock indication, I put a wait until PLL lock bit was true before moving on.


'Verify PLL Lock Flag
PLLwait: 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 "waiting for PLL lock",13
if PLL_LOCK=0 then PLLwait
PLLdone:
debug "PLL Lock=",bin1 PLL_LOCK,13

Still no received data or IRQs however.
Transmitter gives both IRQ0 and IRQ1 outputs - making some progress.

Tabsoft
- 17th February 2015, 22:11
Progress for sure.
When in TX mode your IRQ0 says you have crossed the FIFO Input threshold and IRQ1 says FIFOFull.

Why don't you try changing your definition of IRQ1 for TX (IRQ1TX) from 0 = FIFOFULL (default) to 1 = TXDONE. This is your RF_Init_Values[13] value.
Then in the Send_Packet: routine after changing the mode to RF_TRANSMITTER, instead of a hard pause 5, use a loop to test for IRQ1 to go high (TXDONE).
This way you can explicitly test for the Transmitter to complete.

ecoli-557
- 18th February 2015, 15:03
Thanks for the additional input TABSoft, I had already changed the $0D register to $08, and still saw no interrupt.
One thing I had noticed, In the Send_Packet routine, I saw you re-write the registers. I had changed your original code changing registers $1F, $0D, $0E, in which you re-wrote the registers to the original value, I changed to read the register 1st, then performed the logic manipulation thinking it may have been an oversight on your part. Still no output:


Send_Packet:
'Set Standby mode
bRF_Mode = RF_STANDBY
gosub SetRFMode

'Enable FIFO access in Standby mode
bReg_Address = $1F 'Register 31
gosub RegisterRead
bReg_Value = ((bReg_Value & $BF) | $00)
' bReg_Value = (RF_Init_Values(bReg_Address) & $BF) | $00
gosub RegisterSet
'Clear FIFO Overrun
bReg_Address = $0D 'Register 13
gosub RegisterRead
bReg_Value = bReg_Value | $01
' bReg_Value = (RF_Init_Values(bReg_Address) | $01)
gosub RegisterSet
'Set PLL Locked
bReg_Address = $0E 'Register 14
gosub RegisterRead
bReg_Value = bReg_Value | $02 'Set LSTLPLL to 1
' bReg_Value = (RF_Init_Values(bReg_Address) | $02)
gosub RegisterSet
'debug "Send Packet: waiting for PLL lock",13
' gosub PLLchk 'Verify PLL Lock Flag
'debug "Send Packet: PLL locked",13

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
return

Then as you can also see, I also added a bit test to see if in fact the PLL locked - it never did. Just sat there and spun waiting. I don't know what that is telling me. The 2 other places I have the wait until PLL lock do seem to change; the initial initialization and the RCV loop. Don't know what that is telling me either......

I like your advice, and I had thought of doing something similar but my observations in the no IRQ0 or IRQ1 being set, I was looking for a way to test the register to see if the FIFO was ready. Some kind of flag I could use.
I still haven't found it - an easy one.

I have been on MC site and found numerous people grumbling over this radio - I can't believe this is so hard! One guy could never get the packet to work and went for the buffered approach. Many, Many posters have had interrupt issues as well. Seems I am not alone. All the more reason to post actual working code.

My current drain is higher on the transmitter, so I think it is transmitting, and I actually believe the receiver is receiving - I just don't have it set to flag me so I can get the data!

Thanks again for the assist, I owe you several beers! Any other ideas?
Regards.

Tabsoft
- 21st February 2015, 15:35
Sorry I've been busy on other items.
Have you made any further headway or are you still stuck?

ecoli-557
- 21st February 2015, 23:28
Thanks for asking, I haven't done any more on it. I don't have a spectrum analyzer to see if its transmitting, so its really frustrating.
It looks like it should work, but it doesn't so I am still missing something basic I feel.
I appreciate your help, but, I am stuck and like you, I have things I should be doing besides this 'fun' item.

richard
- 22nd February 2015, 01:58
these rfm69 chips are easy to use and have loads of working examples to draw information from and are really cheap too

http://www.ebay.com.au/itm/RFM69CW-HopeRF-433Mhz-Wireless-Transceiver-with-RFM12B-compatible-Footprint-/181643908981?pt=LH_DefaultDomain_0&hash=item2a4ad21775
(http://www.ebay.com.au/itm/RFM69CW-HopeRF-433Mhz-Wireless-Transceiver-with-RFM12B-compatible-Footprint-/181643908981?pt=LH_DefaultDomain_0&hash=item2a4ad21775)
I started out with the rfm12b modules and now have developed code that can successfully network the rfm69's with the old rfm12b's . I had similar issues to you trying to get the rfm69's up an running , not having the right gear to see what is really happening makes life difficult . in my case the known working rfm12b net allowed me to get pkt reception code working first after that the tx side just fell into place.

ecoli-557
- 22nd February 2015, 19:03
Richard, Thanks for the link. My only desire (if I stick with it) to use the MC modules, is I think it would be interesting to build my own PAN using the Zigbee stuff.
HOWEVER, as I have not demonstrated that I am smart enough to figure it out, another module may be in need.
Do they make these with an integrated antenna?

Tabsoft
- 10th May 2015, 00:31
Just curious.

Did you ever get these modules working for your project?

ecoli-557
- 11th May 2015, 16:10
No I did not. I had used up so much time on this 'friendly' project I wasn't getting any of my fun projects moved forward.
I have shelved it for the time.
Are you trying to do the same thing?
If you succeed, please share what you found out. I think my problem is in the interrupt settings - I think its transmitting, and receiving, just not getting out?!?

ecoli-557
- 11th June 2015, 15:45
Tabsoft-
Did you get anywhere ?

Tabsoft
- 12th June 2015, 03:47
Sorry for the delay.

No I didn't get anywhere with this as I didn't pursue it further.
Got off on different projects. :)

ecoli-557
- 13th June 2015, 18:42
I know, frustrating.
I have a ticket with Microchip, perhaps they can shed some light....
Regards.

astanapane
- 10th August 2018, 22:35
i've seen most of the RFM topics are not completed. I'm about to use the Adafruit RFM 69HCW (https://learn.adafruit.com/adafruit-rfm69hcw-and-rfm96-rfm95-rfm98-lora-packet-padio-breakouts) for sending GPS data from one side to the other. (embedded the modules and the code on this project http://www.picbasic.co.uk/forum/showthread.php?t=23951&p=143936#post143936)

I've seen other posts as well, whicht a guy tried to do the same thing with the GPS, but didnt see any luck.

Has anyone finally succeed to those modules? I'm on holidays right now, and the following days i will try to configure the registers at first.

It is sad that this amazing unique forum, not to have a start up code for each major application. Just for all the users to see and experiment with every single application.

There are still very helpful guys here but non of them have posted a startup code for those modules. And i believe that not only me would love to see that kind of help.

Thanks so much again for your time.

richard
- 11th August 2018, 15:21
It is sad that this amazing unique forum, not to have a start up code for each major application


[rant]
its not the fault of the forum its pbp's total lack of development that causes the issue.
pbp cannot easily manage memory/memory structures or most of the pic inbuilt hardware modules. its difficult to
make easy to use flexible pin definitions to use in include files so that library functionality can be created.
most of my stuff uses asm and usercommand to overcome some of these hurdles but that leads to another level
of complexity for code that translates between pic16/18 platforms. half the people here never even upgraded to pbp3
the lack of usercommand in pbp2 kills that sort of combability anyway. you would have to wonder if more people upgraded to
pbp3 in the past if development would have continued instead of becoming a backwater. all this stuff is dead easy in C .plug and play in Arduino


the rfm69 family of modules are a quite complex device to use , their range and speed make the effort worthwhile
if warranted. i have used them for several years now and did initially use them with pbp3. i did not publish
my code for a number of reasons :-
i wrote it specifically to suit my application , to be compatabile with rfm12bs[a retrograde step] , the code is completey undocumented .
you could write a small novel explaining usage of a rfm69w/cw/hcw... . i look back on other less complex things i have posted
code for like TFT modules, i went to a lot of trouble to make it easy-ish and adaptable . i think 3 people have had some
success in using the code . three people in the whole world FFS. the rfm69 code can be more complex and they are more exotic why would i
bother.
unless you really need the speed/range then there a many less complex devices to use. you thought my suggestions for your gps project
were overly complex rfm69 code is of the same ilk maybe more so.
i was going to say nrf24L01 is a candidate ,very cheap not too hard to use but just noticed i did not even bother to create a pbp include for them , its all C from here

astanapane
- 12th August 2018, 08:42
[rant]
its not the fault of the forum its pbp's total lack of development that causes the issue.
pbp cannot easily manage memory/memory structures or most of the pic inbuilt hardware modules. its difficult to
make easy to use flexible pin definitions to use in include files so that library functionality can be created.
most of my stuff uses asm and usercommand to overcome some of these hurdles but that leads to another level
of complexity for code that translates between pic16/18 platforms. half the people here never even upgraded to pbp3
the lack of usercommand in pbp2 kills that sort of combability anyway. you would have to wonder if more people upgraded to
pbp3 in the past if development would have continued instead of becoming a backwater. all this stuff is dead easy in C .plug and play in Arduino


the rfm69 family of modules are a quite complex device to use , their range and speed make the effort worthwhile
if warranted. i have used them for several years now and did initially use them with pbp3. i did not publish
my code for a number of reasons :-
i wrote it specifically to suit my application , to be compatabile with rfm12bs[a retrograde step] , the code is completey undocumented .
you could write a small novel explaining usage of a rfm69w/cw/hcw... . i look back on other less complex things i have posted
code for like TFT modules, i went to a lot of trouble to make it easy-ish and adaptable . i think 3 people have had some
success in using the code . three people in the whole world FFS. the rfm69 code can be more complex and they are more exotic why would i
bother.
unless you really need the speed/range then there a many less complex devices to use. you thought my suggestions for your gps project
were overly complex rfm69 code is of the same ilk maybe more so.
i was going to say nrf24L01 is a candidate ,very cheap not too hard to use but just noticed i did not even bother to create a pbp include for them , its all C from here

Hi Richard,

thanks once again for your kind reply. I'm not familiar with programming as you have already understood, so for me will be really difficult to make any of these modules to work. I always think, technology make things easier and as those modules are "new" then it would be much easier for a user to embed those small and nice systems.

I also thought that PBP, is capable of making thinks easier for most of the users. I've seen over the internet the Arduino users, have ready libraries for everything and even sample programs that are functioned. I was wonder why not here.

PBP is it quite friendly and can become complicated, but in arduino world, things looks much easier when libraries are documented and registered for every single application. To be honest now i'm quite old to start understanding C language, and as being on a completely different area of interest (3D printing in Medicine) i do not have much time.

I do what i do for my own experiments and hobby.

I dont want you share any of your code, but it would be really nice, if anyone could simply start developing a code for those applications using RFM69 or even Lora modules.

thanks a lot once again.

richard
- 12th August 2018, 14:23
but it would be really nice, if anyone could simply start developing a code for those applications using RFM69 or even Lora modules.

I think you have missed the point of my post , I don't think it can happen the pic environment is awash with veritable plethora of hardware combinations
the "simple" Arduino style libraries you seek exist because the Arduino is a rigid series of products , each one has a fixed osc ,fixed pin definitions ,
a fixed setup routine ,a fixed software shell , a fixed interrupt handler etc.... the user can change none of these things . the hardware is abstracted away from the user
hell even the pwm freq is fixed .you need some level skill to manipulate any of the hardware and the Arduino ide makes sure its going to stay that way and will
hide as much as it can from you

astanapane
- 12th August 2018, 22:43
I think you have missed the point of my post , I don't think it can happen the pic environment is awash with veritable plethora of hardware combinations
the "simple" Arduino style libraries you seek exist because the Arduino is a rigid series of products , each one has a fixed osc ,fixed pin definitions ,
a fixed setup routine ,a fixed software shell , a fixed interrupt handler etc.... the user can change none of these things . the hardware is abstracted away from the user
hell even the pwm freq is fixed .you need some level skill to manipulate any of the hardware and the Arduino ide makes sure its going to stay that way and will
hide as much as it can from you

Many people told me to stay away from arduino.

So you are saying that in pic environment will never happen something like this, because of its complexity. People do not bother to learn and configure a complex hardware, so they move to a fixed and standardized hardware, that effort is eliminated.

richard
- 13th August 2018, 01:53
People do not bother to learn and configure a complex hardware, so they move to a fixed and standardized hardware, that effort is eliminated.
its not that people don't bother , its that there are no pbp tools to do it properly.

i will give you an simple example of the problem that demonstrates why i don't bother making anymore "hardware module" code for pbp any longer
if you extrapolate this to include port/pin choices,on chip hardware and complex memory needs its no wonder that no "libraries" exist .
take my tm1637 demo
http://www.picbasic.co.uk/forum/showthread.php?t=23417
the code is small, efficient and feature rich and works wonderfully, usercommand allows it fit seemlessy into pbp as though it was a pbp function.
problem is it only works on enhanced core pic16 devices.
to use it on a older chip like a pic12f683 it needs a bit of work these chips have only got one 8 bit FSR and no BRW opcode
whereas the modern chips have 2 16 bit FSR's and a BRW opcode .
therefore my rjust function can't work on these old chips and the rest of the code needs a bit of a tweak too
the asm portion of the code becomes :-

SEG_val ;VALID INPUT 0-9 ,A-F, a-f ," " ,-
CHK?RP _TM_TMP
MOVWF _TM_TMP
SUBLW 0x21
btfsc STATUS, C
retlw 0 ;" "
MOVF _TM_TMP,W
SUBLW 0x2f
btfsc STATUS, C
retlw 64 ;"-"
MOVF _TM_TMP,W
MOVLW 0X40
SUBWF _TM_TMP,W
btfsC STATUS, C
GOTO TM_ALPHA
MOVF _TM_TMP,W
ANDLW 0X0F
GOTO TM_LU
TM_ALPHA
ANDLW 0xdf ;ucase
SUBLW 6
btfsS STATUS, C
retlw 0 ;ERROR
MOVLW 0X37
SUBWF _TM_TMP,W
ANDLW 0xdf ;ucase
TM_LU
addwf PCL, F
retlw 0X3F ;0
retlw 6
retlw 0X5B
retlw 0X4F
retlw 0X66
retlw 0X6D
retlw 0X7D
retlw 7
retlw 0X7F
retlw 0X67 ;9
retlw 0X77 ;A
retlw 0X7C ;b
retlw 0X39 ;C
retlw 0X5E ;d
retlw 0X79 ;E
retlw 0X71 ;F

TM_START
_TM_START
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
BSF TM_OUT_PORT,TM_DIO
NOP
BCF TM_OUT_PORT,TM_DIO
NOP
BCF TM_OUT_PORT,TM_CLK
;NOP
RETURN

TM_STOP
_TM_STOP
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
BCF TM_OUT_PORT,TM_DIO
NOP
BSF TM_OUT_PORT,TM_CLK
NOP
BSF TM_OUT_PORT,TM_DIO
;NOP
RETURN

TM_WRITE
_TM_WRITE
MOVLW 8
CHK?RP _TM_BIT
MOVWF _TM_BIT
NXBT
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
CHK?RP _TM_DAT
BTFSS _TM_DAT,0
GOTO TM_0
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_DIO
GOTO TM_NB
TM_0
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_DIO
TM_NB
CHK?RP _TM_DAT
RRF _TM_DAT,F
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
CHK?RP _TM_BIT
DECFSZ _TM_BIT,F
GOTO NXBT
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
CHK?RP TM_TRIS
BSF TM_TRIS,TM_DIO
CHK?RP TM_IN_PORT
BTFSC TM_IN_PORT,TM_DIO
BSF _TM_NAK,7
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
NOP
NOP
NOP
NOP
BCF TM_OUT_PORT,TM_CLK
CHK?RP TM_TRIS
BCF TM_TRIS ,TM_DIO
BANKSEL 0
RETURN
_TM_INIT
CHK?RP _TM_COLON
CLRF _TM_COLON
CLRF _TM_BRIGHT
CHK?RP TM_TRIS
BCF TM_TRIS ,TM_DIO
BCF TM_TRIS ,TM_CLK
BANKSEL 0
RETURN

_TM_DISP4
CHK?RP _TM_DAT
MOVLW _CMD_AUTO_ADDR
MOVWF _TM_DAT
CLRF _TM_NAK
CALL TM_START
CALL TM_WRITE
CALL TM_STOP
MOVLW _NUM_DIGITS
CHK?RP _TM_DIG
MOVWF _TM_DIG
MOVLW _START_ADDR
CHK?RP _TM_DAT
MOVWF _TM_DAT
CALL TM_START
CALL TM_WRITE
NXDIG
MOVF INDF,W
INCF FSR ,f
CALL SEG_val
CHK?RP _TM_DAT
IORWF _TM_COLON ,W
movwf _TM_DAT
CALL TM_WRITE
CHK?RP _TM_DIG
DECFSZ _TM_DIG,F
GOTO NXDIG
CALL TM_STOP
CHK?RP _TM_BRIGHT
MOVF _TM_BRIGHT ,W
ANDLW 7
IORLW _DISPLAY_ON
CHK?RP _TM_DAT
MOVWF _TM_DAT
CALL TM_START
CALL TM_WRITE
CALL TM_STOP
BANKSEL 0
RETURN
ENDASM
but it still wont work on a pic18 they have no MOVIW, MOVWI OR BRW opcodes.
so it needs a rework for them too. apita .its not easy to cover all the bases . i wrote the code to suit my app
at that time . if i need to use the code on a different chip i don't want to keep reinventing the wheel, a modular approach
is what i'm looking for. pbp simply has no tools to make that process a pleasant one.
to do the same thing in C needs no asm code other than a few NOPs for timing and is fully portable with no changes needed
eg
c source :-

#include "tm1637.h"
/*pin manager DEFINES :-
TM_DIO ,TM_CLK
*/
char TM_BRIGHT=1,TM_COLON=COLON_OFF ;
void SET_TM_COLON(char d){
if (d)
TM_COLON=COLON_ON;
else
TM_COLON=COLON_OFF;
}
void SET_TM_BRIGHT(char d){
TM_BRIGHT = d&7;
}
void TM_START(){
TM_CLK_LAT=1;
TM_DIO_LAT=1;
asm ("NOP");
TM_DIO_LAT=0;
asm ("NOP");
TM_CLK_LAT=0;
}

void TM_STOP(){
TM_CLK_LAT=0;
TM_DIO_LAT=0;
asm ("NOP");
TM_CLK_LAT=1;
asm ("NOP");
TM_DIO_LAT=1;
}
char TM_WRITE(char dat){
char bit_cnt;
for (bit_cnt=0;bit_cnt<8;bit_cnt++){
TM_CLK_LAT=0;
TM_DIO_LAT=dat&1;
dat>>=1;
TM_CLK_LAT=1;
}
TM_CLK_LAT=0;
TM_DIO_SetDigitalInput();
bit_cnt=TM_DIO_GetValue();
TM_CLK_LAT=1;
#asm
NOP
NOP
NOP
NOP
#endasm
TM_CLK_LAT=1;
TM_DIO_SetDigitalOutput();
return bit_cnt; //NAK IF SET
}

void TM_DISP(char* buff){
char dat,TM_DIG,tmp;
dat=CMD_AUTO_ADDR;
TM_START();
TM_WRITE(dat);
TM_STOP();
dat=START_ADDR;
TM_START();
TM_WRITE(dat);
for(TM_DIG=0;TM_DIG<NUM_DIGITS;TM_DIG++ ){
tmp=buff[TM_DIG];
dat=SEG_VAL(tmp)|TM_COLON;
TM_WRITE(dat);
}
TM_STOP();
dat=(TM_BRIGHT&7)|DISPLAY_ON;
TM_START();
TM_WRITE(dat);
TM_STOP();
}

char SEG_VAL(char dat){
const char seg_data[]={ 0X3F,6,0X5B,0X4F,0X66,0X6D,0X7D,7,0X7F,0X67,0X77,0 X7C,0X39,0X5E,0X79,0X71};
if (isdigit(dat))
return seg_data[dat-'0'];
else if (isxdigit(dat))
return seg_data[toupper(dat)-'A'+10];
else if (dat=='-')
return 64;
else
return 0;
}
and the header file :-

/*
* File: tm1637.h
* Author: rc
*
* Created on January 3, 2018, 4:42 PM
*/
#ifndef TM1637_H
#define TM1637_H
#ifdef __cplusplus
extern "C" {
#endif

#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>

#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pin_manager.h"
#define CMD_AUTO_ADDR 0x40
#define START_ADDR 0xc0
#define NUM_DIGITS 0x4 //number of 7seg leds
#define COLON_ON 0x80
#define DISPLAY_ON 0x88
#define COLON_OFF 0
void TM_START();
void TM_STOP();
char TM_WRITE(char);
char SEG_VAL(char);
void TM_DISP(char*);
void SET_TM_COLON(char);
void SET_TM_BRIGHT(char);
#ifdef __cplusplus
}
#endif
#endif /* TM1637_H */

and a C example of usage

#include <xc.h>
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pin_manager.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "tm1637.h"
#include "hx711.h"
/*pin manager DEFINES :-
TM_DIO ,TM_CLK
HX_OUT,HX_SCH
ZERO_SW
*/

void main(void)
{
short long cnt;
char buffer[5];
SYSTEM_Initialize();
SET_TM_BRIGHT(2);
while ( HX_OUT_GetValue()){} ;
while (1)
{
if(!ZERO_SW_GetValue() ) {
SET_HX_ZERO();
while (!ZERO_SW_GetValue() ) {};
}
cnt = READ_HX711();
cnt >>=5;
SET_TM_COLON(0);
sprintf(buffer,"%4d",cnt);
TM_DISP(buffer);
__delay_ms(500);
}
}

to do the same in pbp code is possible but twice the size and half as fast with less features . and that is for a very simple device
http://www.picbasic.co.uk/forum/showthread.php?t=23974&p=144196#post144196

astanapane
- 13th August 2018, 05:29
After all that, i have the simplest question.

Why after all these years, PBP havent improve itself with a newer and more competitive version? Then Everyone could buy the compiler with no thought.

Because as far as i see C is not only higher level language, but doesnt need asm.

Now i'm stack at this stage with the GPS project. Not that the code i have done is efficient or a super smart, but i thought i could send those GPS info, easier from one side to the other by using those modules. I thought that it would be a setup for TX -RX and then using only few command to send GPS data.

:( I think that i need to start learning C from the beginning.

Richard, thanks once again for all of your time and help.

mpgmike
- 18th August 2018, 16:32
After all that, i have the simplest question.

Why after all these years, PBP havent improve itself with a newer and more competitive version? Then Everyone could buy the compiler with no thought.
Daryl Taylor was involved in the development of PBP up till about 3 years ago when he passed away. Charles Leo now carries the entire burden of running ME Labs. ME Labs has been bought out by a racing products company. The real money is in the racing products. Charles continues to support PBP users in spite of the fact that the revenue from PBP sales barely pays the light bills. For above-and-beyond type support, we, as a community, must help each other. Creating cool modules and sharing them helps keep our group moving forward. It's a mixed bag I suppose.



:( I think that i need to start learning C from the beginning.
I just bought a couple books to do just that. I see many benefits from learning C.

Ioannis
- 25th August 2018, 19:08
There is an alternative to PBP, Proton Basic.

As for the lib's comparing to Arduino platform, Richard hit the point well. You have to accept using ONLY one or two chips, with a lot of peripherals to support as many as possible features.

But this takes away from you the choice. You cannot select a cheaper chip for mass production of a product, tailored to the project needs.

Can you accept that? I am not as this reduces my range of selection. Then I have to pay the price of doing myself the rest of programming and if I am lucky have some good friends here to help overcome any, usually, silly mistake.

So, you have to select the right tool for the job.

Go to Arduino and just download the library for the GPS, Fingerprint reader, RF communication module or Graphic LCD and just power up. Minimal effort on programming but very narrow hardware selection range. And also a strange lanquage.

++i? Not for me.

Ioannis

Ioannis
- 25th August 2018, 19:08
There is an alternative to PBP, Proton Basic.

As for the lib's comparing to Arduino platform, Richard hit the point well. You have to accept using ONLY one or two chips, with a lot of peripherals to support as many as possible features.

But this takes away from you the choice. You cannot select a cheaper chip for mass production of a product, tailored to the project needs.

Can you accept that? I am not as this reduces my range of selection. Then I have to pay the price of doing myself the rest of programming and if I am lucky have some good friends here to help overcome any, usually, silly mistake.

So, you have to select the right tool for the job.

Go to Arduino and just download the library for the GPS, Fingerprint reader, RF communication module or Graphic LCD and just power up. Minimal effort on programming but very narrow hardware selection range. And also a strange lanquage.

++i? Not for me.

Ioannis

LinkMTech
- 19th October 2018, 19:52
Been awhile since I been here and found this post while trying to bring the same module to life.

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

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

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

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

RX Mode:



' MRF89XAM9A Receiver mode

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

DEFINE OSC 4

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

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

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

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

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

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

PAUSE 500

GOTO Prestart

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

' DMODREG value ' 2.14.2
SSP1BUF = %00000010 ' Write bit with $01 address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %10100100 ' FSK Mod, Packet data and max IF gain
GOSUB SSP_INT ' Wait until MSSP module finishes task

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

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

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

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

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

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

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

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

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

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

' PACREG value ' 2.14.13
SSP1BUF = %00011000 ' Write bit with $0C address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %00000000 ' PA ramp control for OOK mode only
GOSUB SSP_INT ' Wait until MSSP module finishes task

' FTXRXIREG value ' 2.15.1
SSP1BUF = %00011010 ' Write bit with $0D address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %00100001 ' IRQ0RXS = PLReady, IRQ1RXS = RSSI
' IRQ1TX = TX Done, IRQ1TX = FIFO full
GOSUB SSP_INT ' Wait until MSSP module finishes task

' FTPRIREG value ' 2.15.2
SSP1BUF = %00011100 ' Write bit with $0E address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %00111001 ' 5:IRQ0 TX Done, 4:TX start FIFO !empty, 0: 1 = Clear PLL lock
GOSUB SSP_INT ' Wait until MSSP module finishes task

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CSCON = 1 ' Disable Chip Select

RETURN

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

'================================================= ========================
' RF module RX mode config
' This routine takes xxxms to complete where the receive time uses xxxms
' of it with 16 bytes at 10kbs.
'================================================= ========================
RX_mode:
CSCON = 0 ' Enable Chip Select

'************ Set IRQ0 to /FIFOEmpty and IRQ1 to FIFO Threshold ***********
' FTXRXIREG value (INT3 & 4) ' 2.15.1
SSP1BUF = %00011010 ' Write bit with $0D address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %00100001 ' 7:6 IRQ0 = PLReady, 5:4 IRQ1 = CRCOK 11000001
GOSUB SSP_INT ' Wait until MSSP module finishes task

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

CSCON = 1 ' Disable Chip Select

RETURN

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

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

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

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

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

CSCON = 1 ' Disable Chip Select

'************************* Fill FIFO **************************************
FOR x = 1 TO 16
CSDAT = 0 ' Enable Chip Select
SSP1BUF = x ' Write value
GOSUB SSP_INT ' Wait until MSSP module finishes task
CSDAT = 1 ' Disable Chip Select
NEXT x

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

WHILE !INT4: WEND ' Wait until transmission is complete
PAUSEUS 100 ' Wait a little

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

RETURN

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

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

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

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

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


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

Main:

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

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

GOTO Main


END


TX Mode:



' MRF89XAM9A Transmitter mode

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

DEFINE OSC 4

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

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

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

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

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

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


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

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

PAUSE 500

GOTO Prestart

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

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

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

'' DMODREG value ' 2.14.2
' SSP1BUF = %00000010 ' Write bit with $01 address
' GOSUB SSP_INT ' Wait until MSSP module finishes task
' SSP1BUF = %10000100 ' FSK Mod, Packet data and max IF gain
' GOSUB SSP_INT ' Wait until MSSP module finishes task

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

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

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

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

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

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

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

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

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

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

'' PACREG value ' 2.14.13
' SSP1BUF = %00011000 ' Write bit with $0C address
' GOSUB SSP_INT ' Wait until MSSP module finishes task
' SSP1BUF = %00000000 ' PA ramp control for OOK mode only
' GOSUB SSP_INT ' Wait until MSSP module finishes task

'' FTXRXIREG value ' 2.15.1
' SSP1BUF = %00011010 ' Write bit with $0D address
' GOSUB SSP_INT ' Wait until MSSP module finishes task
' SSP1BUF = %11001100 ' IRQ0RX = RX Sync match, IRQ1RX = RX CRC Okay
' ' IRQ1TX = TX Done, IRQ1TX = FIFO full
' GOSUB SSP_INT ' Wait until MSSP module finishes task

'' FTPRIREG value ' 2.15.2
' SSP1BUF = %00011100 ' Write bit with $0E address
' GOSUB SSP_INT ' Wait until MSSP module finishes task
' SSP1BUF = %00111001 ' 5:IRQ0 TX Done, 4:TX start FIFO !empty, 0: 1 = Clear PLL lock
' GOSUB SSP_INT ' Wait until MSSP module finishes task

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

' CSCON = 1 ' Disable Chip Select

'RETURN

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

'================================================= ========================
' RF module RX mode config
' This routine takes xxxms to complete where the receive time uses xxxms
' of it with 16 bytes at 10kbs.
'================================================= ========================
RX_mode:
CSCON = 0 ' Enable Chip Select

'************ Set IRQ0 to /FIFOEmpty and IRQ1 to FIFO Threshold ***********
' FTXRXIREG value (INT3 & 4) ' 2.15.1
SSP1BUF = %00011010 ' Write bit with $0D address
GOSUB SSP_INT ' Wait until MSSP module finishes task
SSP1BUF = %00100001 ' 7:6 IRQ0 = PLReady, 5:4 IRQ1 = CRCOK 11000001
GOSUB SSP_INT ' Wait until MSSP module finishes task

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

CSCON = 1 ' Disable Chip Select

RETURN

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

RETURN


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

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

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

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

CSCON = 1 ' Disable Chip Select

'************************* Fill FIFO **************************************
FOR x = 1 TO 16
CSDAT = 0 ' Enable Chip Select
SSP1BUF = x ' Write value
GOSUB SSP_INT ' Wait until MSSP module finishes task
CSDAT = 1 ' Disable Chip Select
NEXT x

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

WHILE !INT4: WEND ' Wait until transmission is complete
PAUSEUS 100 ' Wait a little

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

RETURN

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

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

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

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

Main:

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


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

' IF RX_data[15] != 16 THEN
' GOSUB TX_mode
' GOSUB RX_mode
' ENDIF

' FOR y = 0 TO 49
' IF INT3 THEN
' GOSUB Read_FIFO
' ENDIF
' PAUSE 1
' NEXT y

' IF RX_data[15] = 16 THEN
' RX_data[15] = 0
' PAUSE 200
' ENDIF

GOTO Main


END