Thanks TABSoft-
The setup is I have 2 units which should be the same (I have checked pinouts on PCB but I have made many cut and re-eoutes). Both units are running same code as shown earlier;
1. Units powerup - sets registers and programming fuses
Code:
'RF Section:
'Transmit is by fixed packet length of 3 bytes; Adress byte (2) and a Message byte.
'Packet looks like: 3-byte preamble - 3-byte Sync Word - 2-byte Address - 1-byte Message - 2-byte CRC
' |(added by pkt handler)| 'SCS' | (provided by code) | (added by pkt handler)
'Everything but the 3-byte payload is processed on receive and removed........
'PIC is PIC18F66J11
'Using PBP3 GOLD 3.0.7.0
'Microcode Studio Plus 5.0.0.5
#CONFIG
CONFIG WDTEN = OFF ; WDT NOT enabled
CONFIG STVREN = ON ; Reset on stack overflow/underflow enabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Program memory is not code-protected
CONFIG FOSC = INTOSC ; Internal oscillator, port function on RA6 and RA7
; CONFIG FOSC = INTOSCPLL ; INTOSC with PLL enabled, port function on RA6 and RA7
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Two-Speed Start-up disabled
CONFIG WDTPS = 512 ; 1:512
CONFIG CCP2MX = DEFAULT ; ECCP2/P2A is multiplexed with RC1
CONFIG MSSPMSK = MSK7 ; 7-Bit Address Masking mode enable
#ENDCONFIG
Asm
ERRORLEVEL -306
Endasm
'---------------------------------------------------------------------------------------
'Define the oscillator, INCLUDE files, A2D setup
DEFINE OSC 8 '8 MHz oscillator, internal x 4 via PLL = 32MHz
include "modedefs.bas"
INCLUDE "DT_INTS-18.bas" 'Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" 'Include if using PBP interrupts
' DEFINE RX2_INT PIR4,RC2IF,PIE4,RC2IE 'Used to ADD the 2nd serial port to the interrupt scheme
'---------------------------------------------------------------------------------------
'OKAY, Lets set up the registers.....
OSCCON=%01110000 'Sleep mode when sleep instr, 8MHz, System clock is via CONFIG BITS
' OSCTUNE.6=1 'PLL ENABLED
'---------------------------------------------------------------------------------------
'Direction registers
TRISA = %00001001 'Set PORTA for mixed
TRISB = %11011111 'PORTB is INPUT, except for RB5
TRISC = %10010011 'Mixed
TRISD = %00101110 'Mixed
TRISE = %00000000 'Set PORTE for all OUTPUTS
TRISF = %11111000 'Set PORTF for use with comparitor direction
TRISG = %10000000 'Set PORTG for all OUTPUTS, PORTD pullups ENABLED
'----------------------------------------------------------------------------------------
2. Setup debug stuff
Code:
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
DEFINE DEBUG_BAUD 38400
DEFINE DEBUG_MODE 0
3. Setup I/O, aliases, vars, and constants
Code:
SDO var PORTC.5
SDI var PORTC.4
SCLK var PORTC.3
Active var PORTD.0 'Active LED, Active LOW
MRFReset var PORTA.1 'MRF module reset
MRFDataSel var PORTA.4 'MRF module serial interface data chip select, active LOW
MRFConfigSel var PORTA.5 'MRF module serial interface configure chip select, active LOW
MRFIrq0 var PORTB.0 'MRF module interupt 0
MRFIrq1 var PORTC.2 'MRF module interupt 1
'Variable List
i var byte
RF_Init_Values var byte[32] 'An array to initialize the RF unit
MRFSPIdata var byte 'Data to/from MRF module
MRFregister var byte 'MRF register we want to read/write
MRFaddr var byte 'MRF address which is 5 bytes
I2CData var byte 'Data byte to/from I2C buffer
junk var byte 'Hold dummy data from MRF
data1 var byte '1st byte from MRF payload
data2 var byte '2nd byte from MRF payload
data3 var byte '3rd byte from MRF payload
'------------------------------------------------------------------------------------------
'Constants here
' RF_Init_Values[0] = $28 'Standby mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
RF_Init_Values[0] = $68 'RECEIVE mode, 915-928 MHz, VTune by inductors, ENABLE R1/P1/S1
RF_Init_Values[1] = $8C 'FSK, max IF gain, Packet Mode
RF_Init_Values[2] = $01 '200KHz Freq Dev
RF_Init_Values[3] = $63 '2KBps
RF_Init_Values[4] = $0C 'for OOK mode, not apliable
RF_Init_Values[5] = $03 '16Bytes FIFO, 3 Bytes threshold FIFO transmit interrupt
RF_Init_Values[6] = $77 '915MHz R1 Reg
RF_Init_Values[7] = $64 '915MHz P1 Reg
RF_Init_Values[8] = $32 '915MHz S1 Reg
RF_Init_Values[9] = $74 '920MHz R2 Reg
RF_Init_Values[10] = $62 '920MHz P2 Reg
RF_Init_Values[11] = $32 '920MHz S2 Reg
RF_Init_Values[12] = $38 'config mode for OOK, not apliable
RF_Init_Values[13] = $0D 'RCV:IRQ0=payload ready + IRQ1=CRC OK
'TX: mostly normal
RF_Init_Values[14] = $39 '00111001
RF_Init_Values[15] = $00 '
RF_Init_Values[16] = $A3 'default filters config
RF_Init_Values[17] = $38 'default filters config
RF_Init_Values[18] = $30 'sync word ON, 24bits, 0 errors tolerance
RF_Init_Values[19] = $00 'reserved reg
RF_Init_Values[20] = $00 'RSII status read register, 0.5dB / bit
RF_Init_Values[21] = $00 'OOK config reg
RF_Init_Values[22] = $53 '"S" 1st byte of sync word
RF_Init_Values[23] = $43 '"C" 2nd byte of sync word
RF_Init_Values[24] = $53 '"S" 3rd byte of sync word - my initials!
RF_Init_Values[25] = $00 '
RF_Init_Values[26] = $70 'utoff fcy = 200KHz, output power = 13dBm 0b000
RF_Init_Values[27] = $BC 'clk out by default 427KHz
RF_Init_Values[28] = $02 '3 bytes payload
RF_Init_Values[29] = $01 'initial MAC ADDRESS, only for test
RF_Init_Values[30] = $5E 'Fix Packet Lenght, 3 bytes preamble, whitening ON, CRC ON, Node ADDR|0x00|0xFF filtering
RF_Init_Values[31] = $00 'FIFO autocreal enable if CRC fails, Write to FIFO in stby mode for (i = 0; i < 32; i++)
4. MRF initialization
Code:
'MRF initialization here
debug "@ MRF init", 10
MRFConfigSel=0 'Select the chip
'Going to try using shiftout before using hardware SPI
for i=0 to 31 'Sets up the index var for data
MRFaddr=(i << 1) 'Shifts address 1 bit to left, automatically gets start,write, and stop bits
SHIFTOUT SDO, SCLK, 1,[MRFaddr,RF_Init_Values(i)] 'send data to register
debug "Addr=",bin8 MRFaddr," Value=",hex2 RF_Init_Values[i],13
next i
MRFConfigSel=1 'Deselect the chip
'Try to read back some registers as a test to see if they were written correctly
MRFConfigSel=0 'Select the chip
for i = 0 to 7 'Sets up address to read
MRFaddr=((i << 1) | $40) 'Shifts left 1 bit, sets $40 bit, automatically gets start, READ, and stop bits
SHIFTOUT SDO, SCLK, 1,[MRFaddr] 'Address to read
SHIFTIN SDI, SCLK, 0,[MRFSPIdata] 'Get data from reg
debug "MRF Config data: i=", dec1 i, " Register ", bin8 MRFaddr, " Data=", hex2 MRFSPIdata,13
next i
5. Then I try to send something via MRF
Code:
'Try sending something
debug "Try sending 3 bytes",13
XMIT_EN: i=0 'Register of interest
MRFaddr=(i<<1) 'Gets register address format
MRFConfigSel=0 'Select the chip
SHIFTOUT SDO, SCLK, 1,[MRFaddr,$88] 'send data, TRANSMIT, 915-928, Vtune by tank caps, Enable R1 P1 S1
MRFConfigSel=1 'Deselect the chip
XMIT: MRFDataSel=0
SHIFTOUT SDO, SCLK, 1,[$A1]
MRFDataSel=1
MRFDataSel=0
SHIFTOUT SDO, SCLK, 1,[$B1]
MRFDataSel=1
MRFDataSel=0
SHIFTOUT SDO, SCLK, 1,[$C1]
MRFDataSel=1
6. Then MRF switches to receive to try to receive the 3 bytes (from the other unit of course).
Code:
RCV: i=0 'Register of interest
MRFaddr=(i<<1) 'Gets register address format
MRFConfigSel=0 'Select the chip
SHIFTOUT SDO, SCLK, 1,[MRFaddr,$68] 'send data, RECEIVE, 915-928, Vtune by tank caps, Enable R1 P1 S1
MRFConfigSel=1 'Deselect the chip
Wait4Pkt: If MRFIrq0=1 and MRFIrq1=1 then
MRFDataSel=0 'Select chip cuz we have a packet ready and CRC is good
SHIFTIN SDI, SCLK, 0,[data3] 'Get data from reg
MRFDataSel=1 'De-Select chip
MRFDataSel=0 'Select chip cuz we have a packet ready and CRC is good
SHIFTIN SDI, SCLK, 0,[data2] 'Get data from reg
MRFDataSel=1 'De-Select chip
MRFDataSel=0 'Select chip cuz we have a packet ready and CRC is good
SHIFTIN SDI, SCLK, 0,[data1] 'Get data from reg
MRFDataSel=1 'De-Select chip
debug "MRF payload: Data3=",hex2 data3," Data2=",hex2 data2," Data1=",hex2 data1,13
endif
goto Wait4Pkt
My method is this:
I turn on both units and watch for debug information.
At this time both units should be in receive mode - not very helpful.
So then I reset one of the units which will make it go through everything again including transmit the 3 bytes.
Nothing comes up on the debug window.
No interrupt gets set
I do see IRQ1 (I think - from memory) go high briefly on the transmitting unit which should be transmission done.
I think its in my NOT understanding the transmission/reception registers - I'm more of a digi-head with some analog.
The DS is not too helpful and the Microchip boards and forum are also not very helpful.
Most of the work seems to be using the 2.4 GHz unit but I wanted to use the sub-ghz unit due to my desire to go throughout the house.
You can PM instead of taking up forum space, I will post my final code using hardware SPI and working code for the MRF - as I am certain there HAS to be others struggling!
Regards.
Bookmarks