Programming RFM radio modules in Basic


Closed Thread
Results 1 to 40 of 45

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    Quote Originally Posted by richard View Post
    rfm69 and rfm12 modules don't work that way , they retain no settings when powered off so they to be fully configured every power up .
    they communicate via spi bus to the host and are most suited to packet transmissions . they can do ook but why would you
    I use rfm12 and 69's a lot they are very reliable fast and have a good range ,but they are not for the faint hearted
    Hi Richard,
    I'm picking my way through the clues! And there don't seem many clues

    OK, so I need a circuit with the module plus a PIC for configuring them.

    It's something I want to do so I'll have to find out how faint hearted I am.

    I would appreciate any circuits or minimal programs please. As for programs, I only speak in BASIC, so I bet I also have to translate any

    Cheers, Camerart.
    Last edited by camerart; - 7th October 2016 at 11:07.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,681


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    here's a pgm I did some years back to let my pic projects talk to the Arduino things its based on and compatible with the Arduino

    rfm12b lowpowerlab library. I would not develop anything new with rfm12b's , rfm69's are much better once you get the knack of it

    I have developed libraries for pic, Arduino and raspberry_pi's [python2.7] to all yak to each other with rfm69 modules [rfm12b also] but
    they are complex ,undocumented and beyond my resources to support for novices








    Code:
    '****************************************************************
    '*  Name    : rfm12b.BAS                                        *
    '*  Author  : richard                                  *
    '*  Notice  : Copyright (c) 2013                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 9/4/2013                                          *
    '*  Version : 1.0    16f1825     @3.3 volts                               *
    '*  Notes   : talk to arduino rfm12b lib with encrypt=null      *
    '*          :  pkt size up to maxl , will  ack also             *
    '****************************************************************
      
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
     
     
      include "dt_ints-14.bas"
      Include "REENTERPBP.bas"
    asm
    INT_LIST macro
          
         
         
          INT_HANDLER INT_INT, _RX, PBP ,NO
          endm
           INT_CREATE
           
          
           
    ENDASM   
     
    DEFINE OSC 32
     SSPIF VAR PIR1.3     ' SPI interrupt flag
     ssc var  PORTC.3    ;..... rf12b ss
     RNINT VAR PORTA.2    ;.... rf12b irqn // int int
     ;SDI=  PORTC.1  .... rf12b sdo
     ;SDO PORTC.2    .... rf12b sd1
    ;SCK  PORTC.3    .... rf12b ssk
     net con 99
     node con 2
     MAXL CON 34   ;buffer size    ie 0 to 34
      
      
     RXBUFF VAR BYTE[maxl+1]
     BCNT VAR BYTE
     GRP VAR RXBUFF[0]   ;net sync 
     DEST  VAR RXBUFF[1]
     SOURCE  VAR RXBUFF[2]
     LEN     VAR RXBUFF[3]
     ;data  rxbuff[4] to   rxbuff[maxl-2] 
     FLG VAR BYTE
     RXDONE VAR FLG.7
     CMD VAR WORD
     crc var word
     CRC_IN   var byte
     i VAR BYTE           ' loop counter
     j var byte
     
     
     
       OSCCON=$70
       ANSELA=0
       ANSELC=0
       OPTION_REG.6=0
       
       
       TRISA = %001110
       TRISC = %00000010        ' set PORTC I/O
       SSP1CON1=$21  ;$22 works too
       SSP1CON2=0
       SSP1CON3=0
       SSP1STAT=$40
        
       high ssc      '
       serout2 PORTA.0,84,[ "RFM12",13,10]
       SSPIF = 0
       GOSUB RM12INIT
       BCNT=1
       INTCON=$90
       FLG=0
       grp=net  
              
    mainloop:
    IF   RXDONE  THEN
    CMD=$820D  ;receive    $820D IDLE
     GOSUB SNDCMD 
      INTCON=0
       crc=-1
        
        FOR I= 0 TO LEN+3
        
         CRC_IN = RXBUFF[i]
        gosub crc16
        next
    if  rxbuff[len+4]=crc.lowbyte then   ;only matching the crc lowbyte seems ok
        
         I=RXBUFF[2]
       if    ( i.7 )   then gosub ack     ; acknowlege reception if   asked
        
       ;  should check   here for  node id match
        
        
      serout2 PORTA.0,84, [ HEX2 RXBUFF[1] ,",", HEX2 RXBUFF[2] ,",",HEX2 RXBUFF[3] ,"," ]
     FOR I= 4 TO LEN+2
      serout2 PORTA.0,84, [ RXBUFF[I] ,"," ]
     
      NEXT
     ; serout2 PORTA.0,84, ["XXX", RXBUFF[len+3],"  ", HEX2 RXBUFF[len+5],  HEX2 RXBUFF[len+4],"  ",hex4 crc, 13,10]   ;len+4=lowbyte
      serout2 PORTA.0,84, [RXBUFF[len+3], 13,10] 
     endif
     
      FOR I= 1 TO MAXL
       RXBUFF[I]=0      ;clear buffer
      NEXT
      
     
        CMD=0           ;reset fifo  sequence
        GOSUB SNDCMD   ;  
        CMD=$CA80 
        GOSUB SNDCMD   ;  
        CMD=$CA83           ;reset fifo 
        GOSUB SNDCMD
      FLG=0
      BCNT=1
      
      INTCON=$90 ; enable rx int 
      CMD=$82DD  ;receive on   
      GOSUB SNDCMD 
     ENDIF
     I=0 ; something in main loop for the wdt
           
    GoTo mainloop     ' do it forever
     
       End
       
       
    SNDCMD:     ;word size send  ,note rfm12b dose not drop irq when ready for cmd
      LOW SSC
         SSPIF = 0
       SSPBUF = CMD.HIGHBYTE  
          WHILE   SSPIF =0 ' wait for SPI interupt flag
     WEND  ' wait for send
        SSPIF = 0
       SSPBUF = CMD.LOWBYTE
          WHILE   SSPIF =0 ' wait for SPI interupt flag
     WEND  ' wait for send
       
       
        HIGH SSC
        Return
        
        
     RM12INIT:            ;leaves radio in rxmode
     CMD=0
     GOSUB SNDCMD   
    CMD=$8205   ;SLEEP
     GOSUB SNDCMD   
    PAUSE 1
     CMD=$80D7
     GOSUB SNDCMD   
    CMD=$A640
     GOSUB SNDCMD 
      CMD=$C608
     GOSUB SNDCMD   
    CMD=$94A2
     GOSUB SNDCMD 
     CMD=$C2AC
     GOSUB SNDCMD   
    CMD=$CA83
     GOSUB SNDCMD 
      CMD=$CE63
     GOSUB SNDCMD   
    CMD=$C483
     GOSUB SNDCMD 
     CMD=$9850
     GOSUB SNDCMD   
    CMD=$CC77
     GOSUB SNDCMD 
      CMD=$E000     
     GOSUB SNDCMD   
    CMD=$C800
     GOSUB SNDCMD 
     CMD=$C043
     GOSUB SNDCMD  
     PAUSE 1
     CMD=$82DD  ;receive $82dd '  XMIT $823D 
     GOSUB SNDCMD      
      RETURN  
      
      
     RX:  
       LOW SSC 
      SSPIF = 0  
       SSPBUF = $B0     ' 
     WHILE   SSPIF=0  ' wait for SPI interupt flag
     WEND
       SSPIF = 0   
         SSPBUF = 0      ' write to SSPBUF 
        WHILE   SSPIF =0 ' wait for SPI interupt flag
     WEND  
      RXBUFF[BCNT] = SSPBUF   ' store received character in array
      BCNT=BCNT+1
     
      IF (BCNT > MAXL) OR (BCNT > (LEN+5) )THEN   RXDONE=1  
          HIGH SSC
          INTCON=$90
    @ INT_RETURN  
      
      
       
     
     crc16:
      
      CRC = CRC ^  CRC_IN 
          for j=0to 7
       if crc.0 then
       crc= ((crc>>1) ^$a001 )   ; 
        
      else
        crc= crc>>1
       endif
       next
       return
       
       
    xmit:     ;tx a byte
    WHILE   RNINT =1  ' wait for irq interupt flag  from rfm12b
     WEND
     cmd =cmd |$b800
      GOSUB SNDCMD 
     return 
       
    
     ack:          ;leaves radio idle
     CMD=$823d    ;tx on
     GOSUB SNDCMD 
     pause 3
     crc=-1
      CMD=$aa      ;preamble
     GOSUB xmit  
     CMD=$aa        ;preamble
     GOSUB SNDCMD 
     CMD=$aa      ;preamble
     GOSUB  xmit 
     
       
    CMD=$2d       ;sync 
     GOSUB  xmit 
      CMD=net         ;network 
     CRC_IN=cmd 
     gosub crc16
     GOSUB  xmit 
    CMD=node       ;node id
    cmd.7=1
     CRC_IN=cmd 
     gosub crc16
      GOSUB  xmit 
    CMD=rxbuff[1]    ;ack from 
     CRC_IN=cmd 
     gosub crc16 
     GOSUB  xmit   
    CMD=00           ;nill length
     CRC_IN=cmd 
     gosub crc16
     GOSUB  xmit  
     CMD=crc.lowbyte
       GOSUB  xmit 
      CMD=crc.highbyte
       GOSUB  xmit 
       CMD=$aa          ;postamble
     GOSUB  xmit   
     CMD=$aa            ;postamble
     GOSUB  xmit 
     pause 4
        CMD=$820d
     GOSUB SNDCMD 
     
     
      return  
      
      
     sndbuff:    ;leaves radio idle and rx int off  , to use   load  dest ,data   and   len , len is the data payload size and call this sub
     INTCON=0   ; watch this
      grp=net
      source=node 
     CMD=$823d    ;tx on
     GOSUB SNDCMD 
     pause 3
     crc=-1
      CMD=$aa      ;preamble
     GOSUB xmit  
     CMD=$aa        ;preamble
     GOSUB SNDCMD 
     CMD=$aa      ;preamble
     GOSUB  xmit 
     
       
    CMD=$2d       ;sync 
     GOSUB  xmit 
             
     
    for i=0 to  len + 3
     CMD= rxbuff[i]
     CRC_IN=cmd 
     gosub crc16
     GOSUB  xmit
      next
     
       CMD=crc.lowbyte
       GOSUB  xmit 
      CMD=crc.highbyte
       GOSUB  xmit 
       CMD=$aa          ;postamble
     GOSUB  xmit   
     CMD=$aa            ;postamble
     GOSUB  xmit 
     pause 4
        CMD=$820d
     GOSUB SNDCMD 
     return
    Warning I'm not a teacher

  3. #3
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    Hi Richard,
    Next I've got to squeeze your code into my Oshonsoft simulator, should be fun
    I have to choose a future proof PIC. Apart from having an spi bus, are there any other considerations to note? e,g, speed, memory etc.
    I already have modules with RFN22 on them, but I have some RFM69 and some RFM96 on order.
    Thanks very much, C.
    EDIT Hi again. I notice "Copyright (c) 2013 All Rights Reserved Can I have permission to post it on an Oshonsoft assistance forum, please?
    Last edited by camerart; - 7th October 2016 at 17:39.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,681


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    EDIT Hi again. I notice "Copyright (c) 2013 All Rights Reserved Can I have permission to post it on an Oshonsoft assistance forum, please?
    No problem , but I don't particularly want to support it [ there is a slight bug in the reset fifo sequence too ,should be $ca81 from memory I think]
    you realise of course that rfm69's are quite a different animal
    Warning I'm not a teacher

  5. #5
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    Quote Originally Posted by richard View Post
    No problem , but I don't particularly want to support it [ there is a slight bug in the reset fifo sequence too ,should be $ca81 from memory I think]
    you realise of course that rfm69's are quite a different animal
    Hi Richard,
    I have been using: http://www.hobbyking.com/hobbyking/s..._Receiver.html for a couple of years. They are programmed using a Chrome APP and have RFM22 chips on them, so I can play with them, while I learn how to program later modules RFM69 and 96 for example.

    I hoped they would be similar, so once learnt, a different module could be programmed with few adjustments to the program.

    I now have 4 BASIC programs, gleaned from the net, that I can follow, and as you say it does look daunting. I have to convert one or more into Oshonsoft basic, for my system and skills.
    I've just got this one into Oshonsoft (compiles), but there are errors. So I commented out those bits with >>>>>>>>>>>>>>>>>>>> for correction later. I've enclosed it in case you see obvious mistakes (Clutching at straws!!)

    I realise your time is valuable.
    Regards, Eric.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,681


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    I found this useful , saves a lot of typing


    ps use word or wordpad to view
    Attached Files Attached Files
    Last edited by richard; - 10th October 2016 at 05:23. Reason: ps
    Warning I'm not a teacher

  7. #7
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Programming RFM radio modules in Basic

    Quote Originally Posted by richard View Post
    I found this useful , saves a lot of typing


    ps use word or wordpad to view
    Hi Richard,
    Thanks most useful.
    C.

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, 20:41
  3. Smart Radio RF620A and RF620RA modules
    By Colin612 in forum Serial
    Replies: 0
    Last Post: - 8th May 2008, 16:47
  4. LPRS/miniature radio modules
    By fowardbias in forum Off Topic
    Replies: 1
    Last Post: - 20th September 2005, 02:03
  5. Help With Easy Radio Modules
    By hughgoodbody in forum General
    Replies: 5
    Last Post: - 25th May 2005, 10:14

Members who have read this thread : 1

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