Programming RFM radio modules in Basic - Page 2
+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 41 to 54 of 54
  1. #41
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    Regarding the comments on the program, i leave them there for me. Sorry for disturbing your reading by using those comments. Because of i use them for my children project GPS, i try to keep those to remind me what i have done.
    there is a big difference between comments that impart some information and visual white noise that masks the very few bits of data that are crucially different
    and worthy of notation
    This is more entertaining than Free to Air TV

  2. #42

    Default Re: Programming RFM radio modules in Basic

    My knowledge and time not helping my self to quickly develop a simple LED to light from one end of RFM69hcw to the other.

    But i will keep reading and studding all the information needed to achieve my goal.

  3. #43

    Default Re: Programming RFM radio modules in Basic

    Now a small step, in the code is to add the DIO0 pin from RFM69HCW to PIC18F26K22.

    As i read from the net, that pin is the:

    Received data ready interrupt signal from RFM69HCW to microcontroller

    TRIS register must also be configured as input at that pin i guess as the RFM69HCW is the one sending data to PIC.

    That i believe will complete the connections between the PIC and the RFM.

    Code:
    '**********************************************************************
    '*  Name    : 18F26K22.BAS                                            *
    '*  Author  : [Leonardo Bilalis]                                      *
    '*  Notice  : Copyright (c) 2018 [Leonardo Bilalis]                   *
    '*          : All Rights Reserved                                     *
    '*  Date    : 30/Jun/2018                                             *
    '*  Version : 1.0                                                     *
    '*  Notes   : This is a GPS Tracker based on the following components *
    '*          : PIC18F26K22 or PIC18F46K22 @ 64Mhz                      *
    '*          : MKT 3333 or 3339 GPS MODULE                             *
    '*          : 4D Systems ULCD Goldelox or Picasso Graphic Processor   *
    '*          : RFM69HCW the range will be approximatelly 1000 meters   *
    '**********************************************************************     
    
      #CONFIG   ;
         CONFIG FOSC     = HSHP	        ; HS oscillator (high power > 16 MHz)
        CONFIG PLLCFG    = ON	        ;Oscillator multiplied by 4  
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
        CONFIG FCMEN     = OFF	        ;Fail-Safe Clock Monitor disabled
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                     ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled  
        CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
      #ENDCONFIG
      
    define  OSC 64
            
    OSCCON    = %01110000   ; 64Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
    
    
    initialize:
    CLEAR                   
    
    TRISA = %11011111 
    TRISC = %11010111  
    
    
    
    SSPCON1 = %00100010 ' in here we se the 5th bit of the SSPCON1 register and the last 4 bits for the clock speed at 64Mhz.
    SSP1STAT = %11000000  ' in here i need a help to understand what bits must be configured
    
    
    
    CS1      VAR           LATA.5  ' chip select (SS) from PIC18F26K22 to RFM69HCW
    DIO0     VAR           PORTC.2 ' Received data ready interrupt signal from RFM69HCW to microcontroller
    SCK1     VAR           PORTC.3 ' clock from PIC18F26K22 to RFM69HCW
    SDI1     VAR           PORTC.4 ' data IN , MISO from PIC18F26K22 to RFM69HCW
    SDO1     VAR           PORTC.5 ' data OUT, MOSI from PIC18F26K22 to RFM69HCW
    
    SSPIF   VAR     PIR1.3          ' SPI interrupt flag
    SMP     VAR     SSP1STAT.7      ' Data input sample phase
    CKE     VAR     SSP1STAT.6      ' Clock Edge Select bit
    SSPEN   VAR     SSP1CON1.5      ' SSP Enable bit
    CKP     VAR     SSP1CON1.4      ' Clock Polarity Select
    
    CS1    = 1
    Last edited by astanapane; - 2nd September 2018 at 20:04.

  4. #44
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    As i read from the net, that pin is the:

    Received data ready interrupt signal from RFM69HCW to microcontroller
    not really, in rx mode its PayloadReady in tx mode its PacketSent



    That i believe will complete the connections between the PIC and the RFM.
    that's 1% of the job done


    cannot see any point to creating these vars , they will never be used
    Code:
    SSPIF   VAR     PIR1.3          ' SPI interrupt flag
    SMP     VAR     SSP1STAT.7      ' Data input sample phase
    CKE     VAR     SSP1STAT.6      ' Clock Edge Select bit
    SSPEN   VAR     SSP1CON1.5      ' SSP Enable bit
    CKP     VAR     SSP1CON1.4      ' Clock Polarity Select
    This is more entertaining than Free to Air TV

  5. #45

    Default Re: Programming RFM radio modules in Basic

    that's 1% of the job done
    That is what i meant

  6. #46

    Default Re: Programming RFM radio modules in Basic

    I will try to help myself and understand how to establish a connection between two RFM69HCW.

    Thanks to all of you trying to help me. I will upload a circuit diagram tomorrow afternoon for all of the people are interested to the same example.

    Here is a code in a really very early stage only trying to understand and configure the hardware ports.

    Code:
    #IF __PROCESSOR__ = "18F26K22" 
      #CONFIG   ;  The PBP configuration for the PIC18F26K22 is:
    ;    CONFIG FOSC     = RCIO6	    ; External RC oscillator
         CONFIG FOSC     = HSHP	        ; HS oscillator (high power > 16 MHz)
         
    
    ;*---------------------------------4x PLL ENABLE--------------------------------------*|
    ;*  4X PLL Enable                                                                     *|
    ;*    CONFIG PLLCFG  = OFF	        ;Oscillator used directly                         *|
        CONFIG PLLCFG    = ON	        ;Oscillator multiplied by 4                       *|
    ;*------------------------------------------------------------------------------------*|
    ;
    ;  Primary clock enable bit
    ;    CONFIG PRICLKEN = OFF	        ;Primary clock can be disabled by software
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
    ;
    ;  Fail-Safe Clock Monitor Enable bit
        CONFIG FCMEN     = OFF	        ;Fail-Safe Clock Monitor disabled
    ;    CONFIG FCMEN    = ON	        ;Fail-Safe Clock Monitor enabled
    ;
    ;  Internal/External Oscillator Switchover bit
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
    ;    CONFIG IESO     = ON	        ;Oscillator Switchover mode enabled
        
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        
    ;*--------------------------------------------------------------------------------------------------------;|
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                     ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
    ;*--------------------------------------------------------------------------------------------------------;|
        
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled
    CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    
      #ENDCONFIG
      
    #ELSE
        #MSG "Wrong Processor selected!"
    #ENDIF   
    ;*---------------------------------------------------------------------------------------------------------|
    ;*---------------------------------------------------------------------------------------------------------|
    
    define  OSC 64
    
            INCLUDE "modedefs.bas"
            INCLUDE "ALLDIGITAL.pbp"
            'INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
            'INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
            
    OSCCON    = %01110000   ; 64Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
    
    
    '------------------------------------------------------------------------------|
    '                            INITIALIZE RAM                                    |
    '------------------------------------------------------------------------------|
    initialize:
    	CLEAR                   
    
    TRISA = %00000000   'use TRISA to specify which pin is (1 = input) and which (0 = output)  
    TRISB = %00000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  
    TRISC = %00010000
    
    PORTA = 0            'make low all ports at A range                      |
    PORTB = 0            'make low all ports at B range                      |
    PORTC = 0            'make low all ports at C range                      |
    PORTE = 0            'make low all ports at E range
    
    '------------------------------------------------------------------------|
    '-------------------------- COMPARATORS OFF -----------------------------|
    '------------------------------------------------------------------------|
    CM1CON0.7 = 0 'Disable comparator1                                       |
    CM2CON0.7 = 0 'Disable comparator2                                       |
    '------------------------------------------------------------------------|
    
    SSP1CON1 = %00100010 ' in here we se the 5th bit of the SSPCON1 register and the last 4 bits for the clock speed at 64Mhz.
    
    SSP1STAT = %11000000
    
    '*-----------------------------------------------------------------------|
    '*-----------------------------------------------------------------------|
    
    RFM_CS      VAR     LATA.5      ' chip select (SS) from PIC18F26K22 to RFM69HCW
    RFM_DIO0    var     PORTC.1     ' Received data ready interrupt signal from RFM69HCW G0 to microcontroller pin 12 PORTC.1
    SCK1        VAR     PORTC.3     ' clock from PIC18F26K22 to RFM69HCW
    SDI1        VAR     PORTC.4     ' data IN , MISO from PIC18F26K22 to RFM69HCW
    SDO1        VAR     PORTC.5     ' data OUT, MOSI from PIC18F26K22 to RFM69HCW
    
    RFM_CS = 1
    
    '*************************************************************************
    '                                                                        *
    '                          IMPORTANT SETTINGS                            *
    '                                                                        *
    '*************************************************************************
    
    Define NETWORKID 10         'this must be the same on all nodes that talk to each other  (0 to 255)
    DEFINE SENDER    1          'in here we could have multiple senders (0 to 255)
    Define RECEIVER  2          'unique ID of the gateway/receiver (0 to 254, 255 = broadcast)
    define NODEID    sender     'if this is sender, we define the node
    
    Define FREQUENCY   ...............
    DEFINE ENCRYPTKEY  ...............
    I would like to setup first the basics as you see on the code above. So please let me know if that is ok at the moment.

    The frequency im using is the 433Mhz
    I guess the encrypted key can be anything.

  7. #47
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    i'm not liking what i see already


    #IF __PROCESSOR__ = "18F26K22"
    #CONFIG ; The PBP configuration for the PIC18F26K22 is:
    ; CONFIG FOSC = RCIO6 ; External RC oscillator
    CONFIG FOSC = HSHP ; HS oscillator (high power > 16 MHz) why use a crystal ? it just wastes pins in this case



    ;*---------------------------------4x PLL ENABLE--------------------------------------*|
    ;* 4X PLL Enable *|
    ;* CONFIG PLLCFG = OFF ;Oscillator used directly *|
    CONFIG PLLCFG = ON ;Oscillator multiplied by 4 *|
    ;*------------------------------------------------------------------------------------*|
    ;
    ; Primary clock enable bit
    ; CONFIG PRICLKEN = OFF ;Primary clock can be disabled by software
    CONFIG PRICLKEN = ON ;Primary clock enabled
    ;
    ; Fail-Safe Clock Monitor Enable bit
    CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    ; CONFIG FCMEN = ON ;Fail-Safe Clock Monitor enabled
    ;
    ; Internal/External Oscillator Switchover bit
    CONFIG IESO = OFF ;Oscillator Switchover mode disabled
    ; CONFIG IESO = ON ;Oscillator Switchover mode enabled

    CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)

    ;*--------------------------------------------------------------------------------------------------------;|
    CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect ;|
    CONFIG WDTPS = 32768 ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
    ;*--------------------------------------------------------------------------------------------------------;|

    CONFIG PWRTEN = ON
    CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status
    CONFIG MCLRE = EXTMCLR ; MCLR pin enabled, RE3 input pin disabled
    CONFIG LVP = OFF ; Single-Supply ICSP disabled
    CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    CONFIG DEBUG = OFF ; Disabled
    CONFIG CP0 = OFF ; Block 0 (000800-003FFFh) not code-protected
    CONFIG CP1 = OFF ; Block 1 (004000-007FFFh) not code-protected
    CONFIG CP2 = OFF ; Block 2 (008000-00BFFFh) not code-protected
    CONFIG CP3 = OFF ; Block 3 (00C000-00FFFFh) not code-protected
    CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
    CONFIG CPD = OFF ; Data EEPROM not code-protected
    CONFIG WRT0 = OFF ; Block 0 (000800-003FFFh) not write-protected
    CONFIG WRT1 = OFF ; Block 1 (004000-007FFFh) not write-protected
    CONFIG WRT2 = OFF ; Block 2 (008000-00BFFFh) not write-protected
    CONFIG WRT3 = OFF ; Block 3 (00C000-00FFFFh) not write-protected
    CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
    CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
    CONFIG WRTD = OFF ; Data EEPROM not write-protected
    CONFIG EBTR0 = OFF ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR1 = OFF ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR2 = OFF ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR3 = OFF ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks


    #ENDCONFIG

    #ELSE
    #MSG "Wrong Processor selected!"
    #ENDIF
    ;*---------------------------------------------------------------------------------------------------------|
    ;*---------------------------------------------------------------------------------------------------------|


    define OSC 64

    lets not get too complicated to start with leave this out
    INCLUDE "modedefs.bas"
    INCLUDE "ALLDIGITAL.pbp"
    'INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
    'INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts

    OSCCON = %01110000 ; 64Mhz
    OSCTUNE.6 = 1 ; Enable 4x PLL


    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code




    '------------------------------------------------------------------------------|
    ' INITIALIZE RAM |
    '------------------------------------------------------------------------------|
    initialize:
    CLEAR
    i fully disagree with making pins outputs unless they will be used as outputs when bread boarding
    TRISA = %00000000 'use TRISA to specify which pin is (1 = input) and which (0 = output)
    TRISB = %00000000 'use TRISB to specify which pin is (1 = input) and which (0 = output)
    portc.1 needs to be an input
    TRISC = %00010010

    lets no do this but set pins that matter in the initialisation code
    PORTA = 0 'make low all ports at A range |
    PORTB = 0 'make low all ports at B range |
    PORTC = 0 'make low all ports at C range |
    PORTE = 0 'make low all ports at E range

    missing entirely set ports digital
    ANSELB=0
    anselc =0
    ANSELa=0



    totally pointless they are already off
    '------------------------------------------------------------------------|
    '-------------------------- COMPARATORS OFF -----------------------------|
    '------------------------------------------------------------------------|
    CM1CON0.7 = 0 'Disable comparator1 |
    CM2CON0.7 = 0 'Disable comparator2 |
    '------------------------------------------------------------------------|


    totally pointless the rfm init code will set up the mssp module
    SSP1CON1 = %00100010 ' in here we se the 5th bit of the SSPCON1 register and the last 4 bits for the clock speed at 64Mhz.


    SSP1STAT = %11000000


    '*-----------------------------------------------------------------------|
    '*-----------------------------------------------------------------------|


    RFM_CS VAR LATA.5 ' chip select (SS) from PIC18F26K22 to RFM69HCW
    RFM_DIO0 var PORTC.1 ' Received data ready interrupt signal from RFM69HCW G0 to microcontroller pin 12 PORTC.1

    no need they will never be used

    SCK1 VAR PORTC.3 ' clock from PIC18F26K22 to RFM69HCW
    SDI1 VAR PORTC.4 ' data IN , MISO from PIC18F26K22 to RFM69HCW
    SDO1 VAR PORTC.5 ' data OUT, MOSI from PIC18F26K22 to RFM69HCW


    RFM_CS = 1


    all these setting are hard coded into the rfm69 init routine and cannot be changed in the code as it stands
    '************************************************* ************************
    ' *
    ' IMPORTANT SETTINGS *
    ' *
    '************************************************* ************************


    Define NETWORKID 10 'this must be the same on all nodes that talk to each other (0 to 255)
    DEFINE SENDER 1 'in here we could have multiple senders (0 to 255)
    Define RECEIVER 2 'unique ID of the gateway/receiver (0 to 254, 255 = broadcast)
    define NODEID sender 'if this is sender, we define the node


    Define FREQUENCY ...............
    DEFINE ENCRYPTKEY ...............
    This is more entertaining than Free to Air TV

  8. #48
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    the basic shell to work with


    Code:
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = OFF
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
        
    DEFINE OSC 64
    
    
    
    
    
    
    ;some vars the engine needs
    
    
    sdata  var byte
    tmpa   var word
    tmpb   var word
    tmp    var word
    rxflg  var byte
    i      var byte
    dest   var byte
    rfbuff var byte[17]
    
    
    
    
    rfm_int    var portc.1    ;dio0
    rfm_cs     var lata.5      ;nss
    button     var portc.0
    led          var portc.2
    
    goto overrfm  ; this is the rfm69 engine there is nothing here for users ,make no changes 
    
    
    rfm:
    
    
    asm
     dw 0x0104,0x0200,0x0306,0x0483,0x0503,0x06d7,0x076c,0x08c0
     dw 0x0900,0x131a,0x1942,0x2540,0x29dc,0x2c00,0x2d05,0x2e90
     dw 0x2fde,0x30ad,0x3163,0x3734,0x3811,0x3904,0x3a01,0x3C8c
     dw 0x6F30  
    
    
    
    
    GLetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1  
        BANKSEL 0
        endm 
     endasm    
    
    
    
    sendFrame:       ;tx to dest
        tmpb = $0104
        gosub writeReg 
        pauseus 800
        TMPB=$2810
        GOSUB WRITEREG
        TMPB=$2800
        GOSUB WRITEREG  
        TMPB=$2500
        GOSUB WRITEREG 
        RFM_CS=0
        sdata=$80
        gosub xspi
        sdata=dest
        gosub xspi 
        for i = 0 to 15 
            sdata=rfbuff[i]
            gosub xspi   
        next 
        RFM_CS=1
        tmpb = $010c
        GOSUB WRITEREG 
        while  rfm_int == 0  : wend
        tmpb = $0104
        gosub writeReg     
        pauseus 800
        TMPB=$2540
        GOSUB WRITEREG 
    return   
    
    xspi:             ;spi xfer 
        SSP1CON1.7 = 0
        SSP1BUF = sdata
        while(SSP1STAT.0 ==0) :wend
        sdata = SSP1BUF
        return  
    
    writeReg:   
        RFM_CS=0
        sdata=tmpb.highbyte|$80     ;reg
        gosub xspi
        sdata=tmpb                   ;data
        gosub xspi
        RFM_CS=1   
    return  
    
    readReg:   
        RFM_CS=0
        sdata=tmpb.highbyte&$7f    ;reg
        gosub xspi
        sdata=0
        gosub xspi
        RFM_CS=1
        tmpb=sdata             ;reply
    return 
    
    
    r69Init:
        @ GLetAddress _rfm ,_tmpa
        SSPCON1=$21  
        SSPSTAT=$c0
        for tmp=0 to 24  
        READCODE tmpa,tmpb
        tmpa=tmpa+2   ; +1 for pic16 +2 for pic18
        gosub writeReg
        next
        gosub rfm_set_highpower      ; "h" modules only
    return  
    
    rfm_set_highpower:      ; "h" modules only   turns on power amp 
        tmpb=$130F
        gosub writeReg
        tmpb=$1200
        gosub readReg 
        tmpb=tmpb&$1f    
        tmpb=tmpb|$1160
        gosub writeReg
        tmpb=$5a5d
        gosub writeReg
        tmpb=$5c7c
        gosub writeReg
    return    
    overrfm:     
        
    
    
    
    
    ;setup osc
    OSCCON=$70
    OSCTUNE.6=1
    while ! osccon2.7 :WEND    ;wait for pll
    
    ;setup pins
    trisa=%11011111 
    trisc=%11010011 
    ANSELB=0                          
    anselc =0
    ANSELa=0 
    
    
    
    
    
    
    rxflg =0
    
    
    gosub r69Init ;program module
    
    
    tmpb = $0110      ;set listen mode
    gosub writeReg
    pauseus 800
       
    
    
    loopy:
        if rfm_int then     ; poll for pkt recieved
            tmpb = $0104     ;standby
            gosub writeReg 
            pauseus 800 
            tmpb=0
            gosub readreg
            if tmpb = 4 then rxflg =1   ;a pkt for me ?      
            i=0 ;
            while (i<16)
                tmpb=0
                gosub readreg
                rfbuff[i] = tmpb
                i=i+1
            wend        
            tmpb = $0110      ;set listen mode
            gosub writeReg
            pauseus 800
    
    
        endif
        if  rxflg then
        ;insert your code here to parse packet and act on it
         rxflg=0
        endif
       ;insert your code here to run in this loop
    
    
        
    goto loopy
    Last edited by richard; - 17th March 2019 at 22:41.
    This is more entertaining than Free to Air TV

  9. #49

    Default Re: Programming RFM radio modules in Basic

    Hi Richard, just came back from a long day.

    Thanks for the comments on the code.

    You are right, there is no need to use external components and reserve ports. I will use the internal OSC at 64Mhz.

    #IF __PROCESSOR__ = "18F26K22"
    #CONFIG ; The PBP configuration for the PIC18F26K22 is:
    ; CONFIG FOSC = RCIO6 ; External RC oscillator
    CONFIG FOSC = HSHP ; HS oscillator (high power &gt; 16 MHz) why use a crystal ? it just wastes pins in this case
    sure i can leave them aside at the moment.

    lets not get too complicated to start with leave this out
    INCLUDE "modedefs.bas"
    INCLUDE "ALLDIGITAL.pbp"
    'INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
    'INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
    Ok, but what should i give as a state if not output? for the PORTC.1 it is clear to me as it will behave as an input.

    i fully disagree with making pins outputs unless they will be used as outputs when bread boarding
    TRISA = %00000000 'use TRISA to specify which pin is (1 = input) and which (0 = output)
    TRISB = %00000000 'use TRISB to specify which pin is (1 = input) and which (0 = output)
    portc.1 needs to be an input
    TRISC = %00010010

    Is there any problem when we set the ports at the very beggining of the program not to funtions at all and set the low? Then in the program we could assign any pin to be low or high

    lets no do this but set pins that matter in the initialisation code
    PORTA = 0 'make low all ports at A range |
    PORTB = 0 'make low all ports at B range |
    PORTC = 0 'make low all ports at C range |
    PORTE = 0 'make low all ports at E range
    That's is why we include at the beggining the: INCLUDE "ALLDIGITAL.pbp"

    but sure as we leave them on a side somehow here we have to tell that all ports are digital thanks.

    missing entirely set ports digital
    ANSELB=0
    anselc =0
    ANSELa=0
    I though that it is not off unless we configure them to be off.

    really didnt know. maybe i need to read better the datasheets.

    totally pointless they are already off
    '------------------------------------------------------------------------|
    '-------------------------- COMPARATORS OFF -----------------------------|
    '------------------------------------------------------------------------|
    CM1CON0.7 = 0 'Disable comparator1 |
    CM2CON0.7 = 0 'Disable comparator2 |
    '------------------------------------------------------------------------|

    OK

    totally pointless the rfm init code will set up the mssp module
    SSP1CON1 = %00100010 ' in here we se the 5th bit of the SSPCON1 register and the last 4 bits for the clock speed at 64Mhz.


    SSP1STAT = %11000000

    I though that we need to set those as somehow we need from those ports to send and receive data.

    no need they will never be used
    SCK1 VAR PORTC.3 ' clock from PIC18F26K22 to RFM69HCW
    SDI1 VAR PORTC.4 ' data IN , MISO from PIC18F26K22 to RFM69HCW
    SDO1 VAR PORTC.5 ' data OUT, MOSI from PIC18F26K22 to RFM69HCW

    I understand. In order to use the following statement someone need to create an include file. Then those configurations can be easily updated.

    all these setting are hard coded into the rfm69 init routine and cannot be changed in the code as it stands
    '************************************************* ************************
    ' *
    ' IMPORTANT SETTINGS *
    ' *
    '************************************************* ************************


    Define NETWORKID 10 'this must be the same on all nodes that talk to each other (0 to 255)
    DEFINE SENDER 1 'in here we could have multiple senders (0 to 255)
    Define RECEIVER 2 'unique ID of the gateway/receiver (0 to 254, 255 = broadcast)
    define NODEID sender 'if this is sender, we define the node


    Define FREQUENCY ...............
    DEFINE ENCRYPTKEY ...............
    As i see some of the ports are included in your code as the button and the LED. Let me fix the breadboard and i will come back with lots of questions based on your code starting with the first

    what is this for?

    Code:
    asm
     dw 0x0104,0x0200,0x0306,0x0483,0x0503,0x06d7,0x076c,0x08c0
     dw 0x0900,0x131a,0x1942,0x2540,0x29dc,0x2c00,0x2d05,0x2e90
     dw 0x2fde,0x30ad,0x3163,0x3734,0x3811,0x3904,0x3a01,0x3C8c
     dw 0x6F30
    of course i dont understand the asm you have written so if you could find time to make things easier for all of us, would be really helpfull.

    Will come back soon with lots of questions based on your code.

  10. #50

    Default Re: Programming RFM radio modules in Basic

    I also have plenty of questions regarding some of the Configs.

    not that i understand some of the other configs but those really cant figure out why we set them and what is the operation for each of them.

    CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
    CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
    CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5
    CONFIG T3CMX = PORTC0 ; T3CKI is on RC0

  11. #51
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    Ok, but what should i give as a state if not output? for the PORTC.1 it is clear to me as it will behave as an input.
    tris can have only two values for each bit , 0 or 1 . if bit =0 the pin is an output , it its not 0 its a 1 and thefore an input
    you do not give pins a "state " you clear the revejent bit to make apin an output

    That's is why we include at the beggining the: INCLUDE "ALLDIGITAL.pbp"
    since dt died who is keeping it uptodate ?

    I though that we need to set those as somehow we need from those ports to send and receive data.


    no need they will never be used
    SCK1 VAR PORTC.3 ' clock from PIC18F26K22 to RFM69HCW
    SDI1 VAR PORTC.4 ' data IN , MISO from PIC18F26K22 to RFM69HCW
    SDO1 VAR PORTC.5 ' data OUT, MOSI from PIC18F26K22 to RFM69HCW

    we never drive any of these pins directly , the mssp module is in charge of them . we use control and use the mssp module



    I understand. In order to use the following statement someone need to create an include file. Then those configurations can be easily updated.

    good luck with that , as i stated all these setting are hard coded into the rfm69 init routine and cannot be changed in the code as it stands


    what is this for?


    Code:
    asm
    dw 0x0104,0x0200,0x0306,0x0483,0x0503,0x06d7,0x076c,0 x08c0
    dw 0x0900,0x131a,0x1942,0x2540,0x29dc,0x2c00,0x2d05,0 x2e90
    dw 0x2fde,0x30ad,0x3163,0x3734,0x3811,0x3904,0x3a01,0 x3C8c
    dw 0x6F30
    that is the data to load into the rfm module's registes to make it behave in the manner we need

    these set the alternative pin options for the indicated module outputs [whether we use them or not a choice must be made]
    CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
    CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5
    CONFIG T3CMX = PORTC0 ; T3CKI is on RC0
    this set portb digital at boot up [technically anselb=0 is not required when this option used]
    CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
    This is more entertaining than Free to Air TV

  12. #52

    Default Re: Programming RFM radio modules in Basic

    I'm trying to figure out a way to understand this code. I guess all those coming from the datasheet?

    Code:
    asm
    dw 0x0104,0x0200,0x0306,0x0483,0x0503,0x06d7,0x076c,0 x08c0
    dw 0x0900,0x131a,0x1942,0x2540,0x29dc,0x2c00,0x2d05,0 x2e90
    dw 0x2fde,0x30ad,0x3163,0x3734,0x3811,0x3904,0x3a01,0 x3C8c
    dw 0x6F30
    So the first marked with blue is the register conrresponds to the following?

    0x01 RegOpMode 0x04 Operating modes of the transceiver

    Then i will try to make notes for each of these registers. Richard it is the only way i could understand things and then to help my self in order not to waste your time.

  13. #53
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Programming RFM radio modules in Basic

    i'm not prepared to support the code to that level of detail yet , remember the car analogy you are wanting to discuss engine fine tuning when it is yet to be proven that you can even drive it or even get it started . small steps . those settings are the result years of experience not to mention many months of trial and effort, not forgetting many hours studying the hope rf docs and sample code . don't lose sight that this a pbp forum not a hope rf forum . you are yet to in any way indicate how you expect to use the module ,what data you will send or anything . i have grave reservations that you have any idea how to use a simplex packet radio system for data transmission at all. a simple no frills lib was asked for i cannot make it any simpler.
    usage is quite simple , after the module is initialised it has two modes listen or standby ,when listening you need to monitor the rfm_int pin to see if a packet has been received , if it has then there is example code to demonstrate how to extract the data packet, at any time you can load up the data buffer and transmit a packet . thats it . [thats how these thing work]
    you keep quibbling around the edges, to me there is no point discussing the fine detail until you can prove that you can actually get somewhere with it.
    This is more entertaining than Free to Air TV

  14. #54

    Default Re: Programming RFM radio modules in Basic

    Hi Richard,

    thanks for the comments. Everything you said is totally rihgt, I know i have a long road until i fully understand how to use this module.

Similar Threads

  1. basic pic programming
    By sshanmugapriya in forum mel PIC BASIC
    Replies: 0
    Last Post: - 25th February 2010, 06:02
  2. Car radio (Car radio and electronics support forum)
    By freewillover in forum Forum Requests
    Replies: 1
    Last Post: - 1st July 2009, 19:41
  3. Smart Radio RF620A and RF620RA modules
    By Colin612 in forum Serial
    Replies: 0
    Last Post: - 8th May 2008, 15:47
  4. LPRS/miniature radio modules
    By fowardbias in forum Off Topic
    Replies: 1
    Last Post: - 20th September 2005, 01:03
  5. Help With Easy Radio Modules
    By hughgoodbody in forum General
    Replies: 5
    Last Post: - 25th May 2005, 09:14

Members who have read this thread : 36

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

Posting Permissions

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