RFM12 with picbasic_pro


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default RFM12 with picbasic_pro

    Good day to all of you in the forum,
    I would like to know if there ia a sample picbasic pro program capable of operating the RFM12 receiver transmitter.
    Any hel is appreciated.
    Thanks
    Ambrogio

  2. #2
    Join Date
    Oct 2011
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hi Ambrogio

    Have a look at the thread http://www.picbasic.co.uk/forum/showthread.php?t=8962 there is a writeup on the RFM12 Transceiver there.
    Hope this helps
    Craig

  3. #3
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hello Ambrogio,

    I've worked with the RFM22B, which I believe is similar. I can post some demo code if you think it is similar enough.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  4. #4
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Thanks very much for having reply to my mail,
    Yes, it will be very useful to me if you can post your code.
    My e_mail is : [email protected]
    Best regards,
    Ambrogio


    Quote Originally Posted by prstein View Post
    Hello Ambrogio,

    I've worked with the RFM22B, which I believe is similar. I can post some demo code if you think it is similar enough.

    Best Regards,
    Paul

  5. #5
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Quote Originally Posted by iw2fvo View Post
    Yes, it will be very useful to me if you can post your code.
    Here you go. Please let us know how it works out.

    Code:
    '****************************************************************
    '*  Name    : Transceiver.pbp                                   *
    '*  Author  : Paul R. Steinmeyer                                *
    '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 11/02/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Target uC:  16F88, using 18F1320                  *
    '*          : Interface with RFM22                              *
    '*          : Waits in RX Mode unless button is pressed, at     *
    '*          : which point it transmits the packet and returns   *
    '*          : to RX mode.                                       *
    '*          : At any valid packet reception the LED blinks      *
    '*          :                                                   *
    '*          : Un-rem lines with SEROUT2 for debugging serial    *
    '*          : transmissions at 9600 baud                        *
    '*          :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    
    '------------------------------------------------------------------------------------------------------------------------------------
    ' # Name          |I/O| Alias       | Var    | Description
    '------------------------------------------------------------------------------------------------------------------------------------
    ' 1 RA0/AN0       |D 1| nButton     |        | Goes low when button is pressed
    ' 2 RA1/AN1       |D 0| LED         |        | LED on when high
    ' 3 RA4/T0CKI     |D 1|             |        | N/C
    ' 4 RA5/MCLR      |D 1|             |        | N/C
    ' 5 Vss           |   |             |        | Ground
    ' 6 RA2/AN2       |D 1|             |        | N/C
    ' 7 RA3/AN3       |D 1|             |        | N/C
    ' 8 RB0/AN4       |D 1| nIRQ        |        | Goes low on interrupt from RFM
    ' 9 RB1/TX        |  0| nSel        |        | Bring low to select RFM
    '------------------------------------------------------------------------------------------------------------------------------------
    '10 RB4/RX        |D 1|SDO          |        | Input from RFM output
    '11 RB5/SS        |D 0|TX_ANT       |        | Selector for TX Mode
    '12 RB6/T1CKI     |D 0|RX_ANT       |        | Selector for RX Mode
    '13 RB7           |D 0|             |        | N/C
    '14 Vdd           |   |             |        | +3V
    '15 RA6/OSC2      |D 1|             |        | N/C
    '16 RA7/OSC1      |D 1|             |        | N/C
    '17 RB2           |D 0|SCK          |        | Clock signal to RFM
    '18 RB3           |D 0|SDI          |        | Output to RFM input
    '------------------------------------------------------------------------------------------------------------------------------------
    'Be sure to REM out the line "__CONFIG    _CONFIG1H, _XT_OSC_1H" in the \PBP\18F1320.INC file!
    '@ __CONFIG    _CONFIG1H, _INTIO2_OSC_1H
    '@ __CONFIG  _CONFIG3H, _MCLRE_OFF_3H
    
    
    '**********
    ' DEFINES
    '**********
    DEFINE OSC 4
    
    
    '***********
    ' CONSTANTS
    '***********
    PacketSize    CON 3
    
    
    '****************
    ' Hardware Setup
    '****************
    'All Ports Digital
    'un-rem this line for 18F1320...
    ADCON1 = $7F    
    '...or un-rem these two for 16F88
    'ANSEL = 0
    'CMCON = 7
    
    
    OSCCON = 100000    '4MHz
    PORTA = 110111
    TRISA = 000001
    PORTB = 000010
    TRISB = 010001
    
    
    '*********
    ' ALIASES
    '*********
    nButton VAR PORTA.0
    LED     VAR PORTA.1
    SDO     VAR PORTB.4
    SDI     VAR PORTB.3
    SCK     VAR PORTB.2
    nSEL     VAR PORTB.1
    nIRQ     VAR PORTB.0
    TX_ANT     VAR PORTB.5
    RX_ANT     VAR PORTB.6
    
    
    '***********
    ' VARIABLES
    '***********
    nAddress    VAR BYTE
    nOutData    VAR BYTE
    nInData        VAR BYTE
    nStatus1    VAR BYTE
    nStatus2    VAR BYTE
    i            var byte
    anRxBuf        var byte[35] 'at least 2x the packet length
    anTxBuf        VAR BYTE[PacketSize]
    nCheckSum    var byte
    
    
    '**********************
    ' Initialize Variables
    '**********************
    nSEL = 1
    LED = 1
    PAUSE 1000
    LED = 0
    
    
    for i = 0 to 34
      anRxBuf[i] = $ff
    next i
    
    
    for i = 0 to PacketSize-1
      anTxBuf[i] = $30+i
    next i
    
    'Initialize the RFM22 Registers
    GOSUB InitRFM
    'Set up to receive data
    GOSUB To_RX_Mode
    'Jump to the main program loop
    GOTO MainLoop
    
    
    '*******************************************************************************
    ' HELPER FUNCTIONS
    '*******************************************************************************
    
    
    'Write a single byte to the RFM22
    SPI_Out:
      nSel = 0        'Select the RFM22
      PAUSEUS 50  'Give it a moment
      nAddress.7 = 1    'Tell the RFM22 we're doing a WRITE transaction
      SHIFTOUT SDI,SCK,1,[nAddress,nOutData]  'Stuff the datum into the RFM22
      nSel = 1  'De-select the RFM22
      PAUSEUS 100  'Unnecessary?
    RETURN
    
    
    'Read a single byte from the RFM22
    SPI_In:
      nSel = 0        'Select the RFM22
      PAUSEUS 50  'Give it a moment
      nAddress.7 = 0    'Tell the RFM22 we're doing a READ transaction
      SHIFTOUT SDI,SCK,1,[nAddress]  'First, write the ADDRESS we want to read from
      SHIFTIN SDO,SCK,0,[nInData]    'Second, take in the datum
      nSel = 1  'De-select the RFM22
      PAUSEUS 100 'Unnecessary?
    RETURN
    
    
    'Send the data contained in the anTXBuf array
    To_TX_Mode:
      'SEROUT2 PORTA.3,49236,["Entering RX Mode...",13,10]
      NAddress = $07 : noutData = $01 : GOSUB SPI_Out  'Set READY mode in RFM22
      RX_ANT = 0 'Configure for transmission
      TX_ANT = 1 'Configure for transmission
      Pause 50   'Give it a moment
      nAddress = $08 : noutData = $03 : GOSUB SPI_Out   'Tell it we want to reset the FIFO
      nAddress = $08 : noutData = $00 : GOSUB SPI_Out   'Reset the FIFO
      nAddress = $34 : noutData = 64 : GOSUB SPI_Out    'Set the preamble = 64nibble
      nAddress = $3E : noutData = PacketSize : GOSUB SPI_Out     'Set the packet length
      nCheckSum = 0
      for i = 0 to PacketSize-2
        nAddress = $7F : noutData = anTXBuf[i] : GOSUB SPI_Out    'Write the data to the TX FIFO
        nCheckSum = nChecksum + antxbuf[i]                        'Calculate the checksum
      next i
      nAddress = $7F : noutData = nCheckSum : GOSUB SPI_Out       'Write the checksum as the last byte
      nAddress = $05 : noutData = $04 : GOSUB SPI_Out             'Enable the packet sent interrupt
      nAddress = $03 : GOSUB SPI_In : nStatus1 = nInData   'Clear interrupts part 1
      nAddress = $04 : GOSUB SPI_In : nStatus2 = nInData   'Clear interrupts part 2
      LED = 1  'Turn on LED immediatly prior to start of transmission
      nAddress = $07 : noutData = 9 : GOSUB SPI_Out  'Tell the RFM22 to start the transmission
      'wait for the interrupt to tell us the transmission is complete
      TXWait:
      if nirq = 1 then
          goto TXWait
      endif
      pause 100  'This pause exists only to make the LED blink long enough to see
      LED = 0    'turn off the LED
    RETURN
    
    
    'Set up RFM22 hardware to receive mode
    To_RX_Mode:
      'SEROUT2 PORTA.3,49236,["Entering RX Mode...",13,10]
      RX_ANT = 0 'Turn off receiver
      TX_ANT = 0 'Turn off transmitter
      nAddress = $03 : GOSUB SPI_In : nStatus1 = nInData 'Clear interrupts part 1
      nAddress = $04 : GOSUB SPI_In : nStatus2 = nInData 'Clear interrupts part 2
      nAddress = $07 : noutData = $01 : GOSUB SPI_Out    'Set READY mode in RFM22
      pause 50    'Give it a moment
      RX_ANT = 1  'Configure for reception
      TX_ANT = 0  'Configure for reception
      pause 50    'Give it a moment
      GOSUB RX_Reset  'Configure RFM22 registers for reception
      PAUSEUS 10   'Give it a moment
    RETURN
    
    
    'Configure RFM22 registers for reception
    RX_Reset:
      'Set READY Mode (Xtal is ON)
      nAddress = $07 : noutData = $01 : GOSUB SPI_Out
      'Set the RX FIFO Almost Full interrupt level to 17 (same as the packet size)
      nAddress = $7E : noutData = PacketSize : GOSUB SPI_Out
      'Clear the RX FIFO and disable multi-packet
      nAddress = $08 : noutData = $03 : GOSUB SPI_Out
      'Second write to complete clearing FIFO buffers    
      nAddress = $08 : noutData = $00 : GOSUB SPI_Out
      'READY mode set, RX on in Manual Receiver Mode
      nAddress = $07 : noutData = $05 : GOSUB SPI_Out
      'Disable extra/oddball interrupts
      nAddress = $06 : noutData = 000000 : GOSUB SPI_Out    
      'Valid Packet Received interrupt is enabled
      nAddress = $05 : noutData = $02 : GOSUB SPI_Out
      'Read the interrupt registers (in order to clear them)
      nAddress = $03 : GOSUB SPI_In : nStatus1 = nInData
      nAddress = $04 : GOSUB SPI_In : nStatus2 = nInData
    RETURN
    
    
    'Initial configuration of RFM22 Registers
    InitRFM:
      'Disable Interrupts
      nAddress = $06 : noutData = $00 : GOSUB SPI_Out
      'Set READY mode
      nAddress = $07 : nOutData = $01    : GOSUB SPI_Out
      'cap = 12.5 pF
      nAddress = $09 : nOutData = $7F : GOSUB SPI_Out
      'Clk output is 2 MHz
      nAddress = $0A : nOutData = $05 : GOSUB SPI_Out
      'GPIO0 is RX data output
      nAddress = $0B : nOutData = $F4    : GOSUB SPI_Out
      'GPIO1 Tx/Rx data clk output
      nAddress = $0C : nOutData = $EF    : GOSUB SPI_Out
      'GPIO2 for MCLK output
      nAddress = $0D : nOutData = $00 : GOSUB SPI_Out
      'GPIO port use default value
      nAddress = $0E : nOutData = $00 : GOSUB SPI_Out
      'no ADC used
      nAddress = $0F : nOutData = $70 : GOSUB SPI_Out
      nAddress = $10 : nOutData = $00 : GOSUB SPI_Out
      'no temp sensor used
      nAddress = $12 : nOutData = $00 : GOSUB SPI_Out
      nAddress = $13 : nOutData = $00 : GOSUB SPI_Out
      'no manchester code, no data whiting, data rate < 30Kbps
      nAddress = $70 : nOutData = $20 : GOSUB SPI_Out
      'IF filter bandwidth
      nAddress = $1C : nOutData = $1D : GOSUB SPI_Out
      'AFC loop
      nAddress = $1D : nOutData = $40 : GOSUB SPI_Out
      'Clock Recovery
      nAddress = $20 : nOutData = $A1    : GOSUB SPI_Out
      nAddress = $21 : nOutData = $20    : GOSUB SPI_Out
      nAddress = $22 : nOutData = $4E    : GOSUB SPI_Out
      nAddress = $23 : nOutData = $A5    : GOSUB SPI_Out
      'Clock Recovery timing
      nAddress = $24 : nOutData = $00    : GOSUB SPI_Out
      nAddress = $25 : nOutData = $0A    : GOSUB SPI_Out
      'zero OOK counter
      nAddress = $2C : nOutData = $00 : GOSUB SPI_Out
      nAddress = $2D : nOutData = $00 : GOSUB SPI_Out
      'slicer peak hold
      nAddress = $2E : nOutData = $00 : GOSUB SPI_Out
      'TX data rate (4800 baud)
      nAddress = $6E : nOutData = $27 : GOSUB SPI_Out
      nAddress = $6F : nOutData = $52    : GOSUB SPI_Out
      'Data Access Control
      nAddress = $30 : nOutData = $8C : GOSUB SPI_Out
      'Header Control
      nAddress = $32 : nOutData = $FF : GOSUB SPI_Out
      ' header 3, 2, 1,0 used for head length, fixed packet length, synchronize word length 3, 2,
      nAddress = $33 : nOutData = $42 : GOSUB SPI_Out
      '64 nibble = 32byte preamble
      nAddress = $34 : nOutData = 64 : GOSUB SPI_Out
      '0x35 need to detect 20bit preamble
      nAddress = $35 : nOutData = $20 : GOSUB SPI_Out
      ' synchronize word
      nAddress = $36 : nOutData = $2D : GOSUB SPI_Out
      nAddress = $37 : nOutData = $D4 : GOSUB SPI_Out
      nAddress = $38 : nOutData = $00 : GOSUB SPI_Out
      nAddress = $39 : nOutData = $00 : GOSUB SPI_Out
      ' set tx header
      nAddress = $3A : nOutData = "h" : GOSUB SPI_Out
      nAddress = $3B : nOutData = "o" : GOSUB SPI_Out
      nAddress = $3C : nOutData = "p" : GOSUB SPI_Out
      nAddress = $3D : nOutData = "e" : GOSUB SPI_Out
      ' total tx 17 byte
      nAddress = $3E : nOutData = PacketSize : GOSUB SPI_Out
      ' set rx header
      nAddress = $3F : nOutData = "h" : GOSUB SPI_Out
      nAddress = $40 : nOutData = "o" : GOSUB SPI_Out
      nAddress = $41 : nOutData = "p" : GOSUB SPI_Out
      nAddress = $42 : nOutData = "e" : GOSUB SPI_Out
      ' all the bits to be checked
      nAddress = $43 : nOutData = $FF : GOSUB SPI_Out
      nAddress = $44 : nOutData = $FF : GOSUB SPI_Out
      nAddress = $45 : nOutData = $FF : GOSUB SPI_Out
      nAddress = $46 : nOutData = $FF : GOSUB SPI_Out
      'Reserved
      nAddress = $56 : nOutData = $01 : GOSUB SPI_Out
      ' tx power to Max
      nAddress = $6D : nOutData = $07    : GOSUB SPI_Out
      ' no frequency hopping
      nAddress = $79 : nOutData = $00 : GOSUB SPI_Out
      nAddress = $7A : nOutData = $00 : GOSUB SPI_Out
      ' Gfsk, fd[8] =0, no invert for Tx/Rx data, fifo mode, txclk -->gpio
      nAddress = $71 : nOutData = $22    : GOSUB SPI_Out
      ' frequency deviation setting to 35k = 56*625
      nAddress = $72 : nOutData = $38    : GOSUB SPI_Out
      ' no frequency offset
      nAddress = $73 : nOutData = $00 : GOSUB SPI_Out
      nAddress = $74 : nOutData = $00 : GOSUB SPI_Out
      ' frequency set to 434MHz
      nAddress = $75 : nOutData = $53    : GOSUB SPI_Out
      nAddress = $76 : nOutData = $64    : GOSUB SPI_Out
      nAddress = $77 : nOutData = $00    : GOSUB SPI_Out
    
    
      'NOTE:
      'The following 5 registers are listed as RESERVED in the RFM22B v1.1
      'datasheet.  Try remming them if problems are experienced
      nAddress = $5A : nOutData = $7F : GOSUB SPI_Out
      nAddress = $59 : nOutData = $40 : GOSUB SPI_Out
      nAddress = $58 : nOutData = $80 : GOSUB SPI_Out
      nAddress = $6A : nOutData = $0B : GOSUB SPI_Out
      nAddress = $68 : nOutData = $04 : GOSUB SPI_Out
    
    
      'Clock Recovery Gearshift Override
      nAddress = $1F : nOutData = $03 : GOSUB SPI_Out
      PAUSEUS 1000 'Let the settings settle
    return    
    
    
    '*******************************************************************************
    ' END OF HELPER FUNCTIONS, BEGIN MAIN PROGRAM LOOP
    '*******************************************************************************
    MainLoop:
      'nIRQ Pin Indicates that we have received a packet
      if nIRQ = 0 then 'Packet received
        'Clear the interrupt
        nAddress = $03 : GOSUB SPI_In : nStatus1 = nInData
        nAddress = $04 : GOSUB SPI_In : nStatus2 = nInData
        'Read in the data
        for i = 0 to PacketSize-1
          nAddress = $7F : GOSUB SPI_In : anRxBuf[i] = nInData
        next i
        nSel = 1 'unncecessary?
        'Calculate the checksum...
        nCheckSum = 0
        for i =  0 to PacketSize-2
          nCheckSum = nCheckSum + anRxBuf[i]
          'SEROUT2 PORTA.3,49236,[Ihex2 anRxBuf[i]," "]
          anRxBuf[i] = 0
        next i
        'SEROUT2 PORTA.3,49236,[13,10,"ChkSum=",Ihex2 anRxBuf[i],13,10]
        'Verify that the calculate checksum matches the last byte in the packet                
        if  nChecksum = anRxBuf[PacketSize-1] then
          LED = 1
          'SEROUT2 PORTA.3,49236,["ChkSum MATCH!",13,10]
          PAUSE 500
          LED = 0;
        ENDIF
        GOSUB rx_reset; // rx reset
      endif
      'Check for button press
      if nButton = 0 then 'the button is pressed...
        'SEROUT2 PORTA.3,49236,["Xmitting",13,10]
        'Here would be a good place to load the relevant data into anTxBuf
        gosub To_TX_Mode
        'and return back to RX_Mode
        GOSUB To_RX_Mode
      endif
    GOTO MainLoop
    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  6. #6
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Thanks a lot Paul: it is great !

    Best regards,
    Ambrogio
    Iw2FVO

  7. #7
    Join Date
    Sep 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Thanks Paul. I was looking for something similar to this.

  8. #8
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Ambrogio and lyoung298,

    Glad you like it. I'm pretty happy with the RFM22 and I'm glad others are using them too.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  9. #9
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Paul,
    just a question: what is the max operative range of those RFm22 devices ?
    I do have a couple of RFM12b but one is broken ( shipment problem ! ) so at the moment i can not test them.
    Thanks
    Ambrogio



    Quote Originally Posted by prstein View Post
    Ambrogio and lyoung298,

    Glad you like it. I'm pretty happy with the RFM22 and I'm glad others are using them too.

    Best Regards,
    Paul

  10. #10
    Join Date
    Sep 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    The datasheet for the RFM22 reads sensitivity of -121dBm. So line of sight range of 3000ft should be possible. Similar modules from Linx has a typical receiver sensitivity of -112 dBm. Baud rate also can effect range. Higher baud rates normally decrease range.

  11. #11
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    The choice of antenna makes a huge difference as well. My RFM22s are 916MHz and I'm using a tiny little antenna (here). I've only tested to about 30 meters but under awful conditions (through trees and several walls). That was also after setting the transmit power low enough to comply with the U.S. FCC requirements.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  12. #12
    Join Date
    Feb 2012
    Location
    Meico,D.F.
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    This is my code

    '************************************************* ***************
    '* Name : TRANSPONDEDOR.BAS *
    '* Author : Leonardo Castillo *
    '* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 26/12/2011 *
    '* Version : 2.0 *
    '* Notes rograma terminado pero aun no probado fisicamente *
    '* :se le adecuo un display para poder probarlo *
    '************************************************* ***************
    include "modedefs.bas"
    'Device 16F627
    'Config WDT_OFF, PWRTE_ON
    DEFINE OSC 4
    DATO VAR Word
    DATO2 VAR word
    RGIT VAR byte
    I VAR Byte
    Boton1 var byte
    Bandera var byte
    ChkSum var byte
    Symbol SDO=PORTA.0 'SDO , en el microcontrolador se configura como entrada
    Symbol SDI=PORTA.1 'SDI , en el microcontrolador se configura como salida
    Symbol SCK=PORTA.2 'SCK , en el microcontrolador se configura como salida
    Symbol nSEL=PORTA.3 'nSEL , en el microcontrolador se configura como salida
    Symbol nIRQ=PORTB.0 'nIRQ , en el microcontrolador se configura como entrada
    symbol Boton=PORTB.2 'Boton de seleccion
    goto inicio
    Configs:
    nSEL = 0
    ShiftOut SDi,SCK,msbfirst,[DATO\16]
    nSEL = 1
    asm ;pauseus 10
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    endasm
    Return
    Inicio:
    CMCON=7
    '76543210
    PORTA = %00000001
    PORTB = %00000101
    boton1=0
    Pulsar:
    pause 200
    if boton=1 then pulsar
    boton1=boton1+1
    pause 1000
    if boton=0 then boton1=boton1+1
    Esperadejapulsar:
    if boton=0 then esperadejapulsar
    'Inicializa dispositivo transpondedor
    PAUSE 500
    DATO = $8038 : GoSub CONFIGS 'habilita registros, 915Mhz, 12.5pF
    if boton1=1 then
    DATO = $8208 : GoSub CONFIGS 'activas cristal oscilador, !PA
    elseif boton1=2 then
    DATo = $82D8 : GoSub CONFIGS 'activa cristal, !PA, habilita resepcion
    endif
    DATO = $a640 : GoSub CONFIGS 'frec centrada en 912 MHz
    DATO = $c647 : GoSub CONFIGS 'velocidad de datos 4789 Kbps
    DATO = $94a0 : GoSub CONFIGS 'VDI, FAST, 134kHz, 0dBm, -103dBm
    DATO = $c2ac : GoSub CONFIGS 'modo de recuperacion de reloj auto, velocidad de recuperacion de reloj lenta, filtro de datos digital, nivel de calidad de datos (Threshold) 4
    DATO = $ca80 : GoSub CONFIGS 'nivel FIFO 8, longitud de sincronizacion 2 bytes, fifo fill inicio de sincronizacion, sensivilidad de reset alta
    DATO = $ca83 : GoSub CONFIGS 'FIFO8, sync (sensivilida de reset fifo lenta y habilita fifo fill
    DATO = $c49b : GoSub CONFIGS 'habilita afc, strobe, habilita registro de frecuencia offset (registro offset 15 a -16 ) solo mientras vdi=high
    DATO = $9850 : GoSub CONFIGS '!mp, 9810=30kHz, MAX OUT post frec shift, 90 KHz deviation and power out 0 db -txt control command
    DATO = $e000 : GoSub CONFIGS 'comando wake up timer no usado
    DATO = $c800 : GoSub CONFIGS 'comando low duty-cycle no usado
    DATO = $c000 : GoSub CONFIGS '1.0Mhz, 2.2v
    if boton1=1 then
    gosub transmicion
    else
    gosub resepcion
    endif
    boton1=0
    goto Pulsar
    Transmicion:
    if boton=1 then transmicion 'espera a iniciar el envio de datos
    DATO = $8228 : GoSub CONFIGS 'activa cristal oscilador, habre PA
    @ nop ;retardo de 4 us 1 instruccion = 1 us a 4 Mhz
    @ nop
    @ nop
    @ nop
    DATo = $8238 : GoSub CONFIGS 'activa cristal, habilita transmicion
    @ nop ;retardo de 2 us
    @ nop
    loop1:
    if nirq = 0 then
    ChkSum=0
    i=0
    repeat
    ' lookup2 i,[$AA,$AA,$AA,$2D,$D4,"LeonardoCastillo",ChkSum,$AA, $55],dato2 'de esta forma en una sola linea se pone todo el formato pero consume mas bytes de memoria
    lookup i,[$AA,$AA,$AA,$2D,$D4,"LeonardoCastillo",$55],dato2
    if dato2<>$AA or dato2<>$55 then ChkSum=(ChkSum+16)&$FF
    if dato2<>$55 then gosub enviar
    i=i+1
    until dato2=$55
    dato2=chksum : gosub enviar'si se usa instruccion lookup2 se elimina esta instruccion
    dato2=$AA : gosub enviar 'si se usa instruccion lookup2 se elimina esta instruccion
    endif
    DATO = $8208 : GoSub CONFIGS 'activa cristal, sierra PA
    DATO = $8200 : GoSub CONFIGS 'finaliza resepcion, entra en reposo
    pause 1000
    GoTo inicio
    'siempore que un comando de lectura sea identificado se podra leer el registro
    'STATUS a travez del pin SDO y embiando los pulsos de reloj requeridos
    'Como solo nos interesa leer el bit RGIT (FIN DE TRANSMICION) que corresponde al
    'bit 16 del registrto y como siempre el primer bit en salir es el 16, solo se
    'requiere de un pulso de reloj, para poder leer dicho registro, el pin SDI debe
    'ponerse a nivel bajo (SDI=0)

    Enviar:
    RGIT=0
    dato=DATo2|$B800 'se suma al comando de lectura (OxB800 el byte de la letra o dato enviado
    Loop2:
    SCK=0 'baja señal de reloj
    nSEL=0 'baja señal y habilita el dispositibo para injiciar la transmicion
    SDI=0 'baja señal de dato para habilitar la lectura del registro STATUS
    SCK=1 'eleba señal de reloj para iniciar el pulso y obtyener la lectura por el pin SDO
    if SDO=1 then 'checa el bit 16 (RGIT) del reg status mediante el pin SDO y que es el
    RGIT=1 'que primero se lee y si esta en alto entonces significa que termino la transmicion
    else
    RGIT=0 'si hay transmicion en progreso(SDO=0), coloca esta otra bandera
    endif
    SCK=0 'baja señal de reloj para finalizar pulso
    SDI=1 'eleva señal de datos
    nSEL=1 'deshabilita dispositivo transpòndedor
    if RGIT==0 then 'si sigue transmitiendo se vuelbe a habilitar el dispositivo para
    goto Loop2 'iniciar la lectura del reg status hasta completar la transmicion
    else 'pero si termino de transmitir (se enviaron los 16 bits)
    RGIT=0 'el microcontrolador almacena los siguientes byts en el
    gosub configs 'transpondedor en forma serial mediante esta rutina
    endif
    return
    ' Resepcion empleando interrupcion nIRQ
    Resepcion:
    if boton=1 then resepcion 'espera a iniciar resepcion
    ' Define LCD registros y bits
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 2
    Define LCD_EREG PORTB
    Define LCD_EBIT 3
    Parcial var word
    Result var word [25]
    BStatus var word
    pause 500
    i=0 'inicializa contador
    nsel=1
    sdi=1
    sck=0
    sdo=0
    IniciaResep:
    while nIRQ=0 '(!nIRQ)
    gosub leeFIFO 'LeeFIFO
    result[i]=parcial 'almacena en registros
    i=i+1
    if i=16 then i=0 : GOTO ESCRIBELCD
    DATo = $ca80 : GoSub CONFIGS
    DATo = $ca83 : GoSub CONFIGS ' //reset a FIFO y lee el siguiente Byte resibido
    wend
    goto iniciaresep
    LeeFIFO: 'Rutina FIFO
    SCK=0;
    SDI=0;
    nSEL=0;
    SHiftIn SDo, SCK, msbpre, [bstatus\16] 'lee y salta bits status, quedan almacenados
    SHiftIn SDo, SCK, msbpre, [parcial\8] 'lee y almacena byte de datos del registro FIFO
    nSEL=1
    RETURN
    EscribeLCD:
    lcdout $FE,1 'limpia pantalla
    Escribe: 'escribe en la pantalla el mensaje almacenado en las variables
    for i=0 to 16
    LCDOUT result[i]
    next i
    goto inicio 'regresa al inicio del programa
    end

  13. #13
    Join Date
    Oct 2011
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hi Paul

    I Have bought some RFM22B's and connected up to a 16F883 Pic and connected up as per your setup and code.
    Everything seems to be working until I press the TX button It does transmit but, stays in that mode with Led On.
    It gets stuck in To_TX_Mode: at the TXWait: Loop, I have read the Serout2 to my Pc too see if the packet is being sent.etc.

    I have tried changing address $05 to $02 but, I seem to get stuck here.
    Could you Please tell me if you have any suggestions as to why I am getting stuck?

    Thanks In advance!

    Kind Regard
    Craig

  14. #14
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hello Craig,

    Have you made any changes to the code? Perhaps added an interrupt that might be pulling it out? If you have made some changes please post your code, it might be somewhat easier than guessing...

    Just to test something, try replacing
    Code:
    TXWait:
      if nirq = 1 then
          goto TXWait
      endif
    with "pause 100" or something like that.

    Also, check with a meter or scope that nIrq actually goes low.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  15. #15
    Join Date
    Oct 2011
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hi Paul

    Thanks for the reply, I have used the code exactly like you have written it without any extra interupts etc.
    What I did was remove the TXWait and just put a PAUSE 100 in then it does transmit.
    What is funny is if I put a meter on the nIRQ pin then it keeps sending info on the SEROUT2 and the TX Led remains ON,
    If I take the meter off the pin then it settles down ant the TX Led switches off. What I did was wire an extra LED onto a unused pin on the PIC and then
    monitor this in relation to the nIRQ pin when it goes High or Low.

    I read no voltage on the nIRQ pin but the extra led stays on so there is something weird with this pin?
    Maybe I should rebuild the PCB onto a Veraboard instead on leaving it all on a Bread Board as there seems
    to be a lot of capacitance floating around, I suppose that this could cause a problem on the nIRQ pin?

    What can you suggest Paul?

    Kind Regards

    Craig
    Last edited by craigwb; - 13th March 2014 at 14:56.

  16. #16
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hello Craig,

    I suspect you've found the problem--capacitance (or other leakage) in the setup. Good job! I think you'll do better on veraboard... For a quick fix try putting relatively high value pull-down resistors (~10k to 1M) on the nIrq and LED pins. From what you describe something is causing one of those pins to float high.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  17. #17
    Join Date
    Oct 2011
    Posts
    10


    Did you find this post helpful? Yes | No

    Cool Re: RFM12 with picbasic_pro

    Thanks Paul

    I will rebuild and see how it goes.

    Kind Regards

    Craig

  18. #18
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: RFM12 with picbasic_pro

    Hi All,
    I've just ordered some similar RFM modules, and hope to get them working. The code above looks good, and thanks.
    Camerart.

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