Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

rfm12b configuration...

Status
Not open for further replies.

majid_valentine

Junior Member level 3
Joined
Dec 10, 2006
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,430
rfm12b

hi all

can any body help me to initial rfm12 module with bascom or codvision please????
 

rfm12 bascom

hi majid
if your rfm12b is 434mhz come here

https://www.eca.ir/forum2/index.php?board=161.0
here u can find your problem because they have a full bascom sorce and schematic's
;)



'************************ TxRx_1.05.bas ***********************
'
'Test program for using the RFM12 or RFM12B
'433MHz Radio Data Transceivers.
'These transceivers sell for about $8.00 US.
'from: https://www.futurlec.com/Radio.shtml
'
'This code + hardware takes serial data from a PC and converts
'it to RF. A second indentical device receives the RF signal and
'converts it back to serial.
'
'This code is not ment to be a complete RF serial link. It is
'for testing and evaluating the RFM12 modules only. However with
'the addition of error detection and correction, I beleve a
'reliable RF link could be relized.
'
'July 28, 2008
'By: David Carr
'***************************************************************

$regfile = "m8def.dat"
$hwstack = 32
$swstack = 10
$framesize = 40

$crystal = 16000000
$baud = 9600

Const File = "TxRx 1.05 .bas"
Const Description = "RFM12 monitor program"

Print
Print Description
Print File
Print Version()

Rfm12_rst Alias Portc.5
Config Rfm12_rst = Input

Config Portb = &B0010_1101

Test_pin Alias Portb.0

Rfm12_cs Alias Portb.2
Set Rfm12_cs

Rfm12_sdi Alias Portb.3

Rfm12_sdo Alias Pinb.4
Set Portb.4

Rfm12_sck Alias Portb.5

Rx_led Alias Portd.5
Config Pind.5 = Output

Tx_led Alias Portd.6
Config Pind.6 = Output

Error_led Alias Portd.7
Config Pind.7 = Output

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , _
Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
Spiinit

Declare Sub Rfm12_spi_wrt
Declare Sub Rfm12_tx(txarray As Byte)
Declare Sub Rfm12_rx(rxarray As Byte)
Declare Sub Rfm12_tx_ready
Declare Sub Rfm12_rx_wait
Declare Sub Rfm12_get_status_bit
Declare Sub Saveflags
Declare Sub Rfm12_clear_fifo
Declare Sub Rfm12_rx_on
Declare Sub Rfm12_init
Declare Sub Printflags

'From: RF12 Programing Guide
'Min Freq 430.24
'Max Freq 439.75
'in 2.5KHz steps
'
'That makes 3800 possible frequencies
'to choose from.

'Fc = the center Freq. in MHz
'Fr = the Freq. register value.
'Fc = 430 + Fr * 0.0025 (MHz)
'Fr = (Fc - 430) * 400
Const Fc = 915.00
Const Fr =(fc - 430) * 400
Const Fcmnd = &HA000 + Fr

'Payload can be up to 254 bytes.
'I have tested up to 128 bytes only.
'const Payload_Size = 128
Const Payload_size = 32
'const Payload_Size = 16
Const Pls_plus1 = Payload_size + 1

'make the test beacon length Payload_Size - 2
Const Beacon = "111111789012345678901234567890"

Dim Tempbit As Bit
Dim Temp As Byte
Dim Tempw As Word

Dim Spi_tx_wrd As Word
Dim Spi_tx_l As Byte At Spi_tx_wrd Overlay
Dim Spi_tx_h As Byte At Spi_tx_wrd + 1 Overlay
Dim Spi_rx_wrd As Word
Dim Spi_rx_l As Byte At Spi_rx_wrd Overlay
Dim Spi_rx_h As Byte At Spi_rx_wrd + 1 Overlay

Dim Rx_status_bit As Bit
Dim Rxbuffer(pls_plus1) As Byte
Dim Rxstring As String * Payload_size At Rxbuffer(1) Overlay
Rxbuffer(pls_plus1) = 0

Dim Txindex As Byte
Dim Txbuffer(pls_plus1) As Byte
Dim Txstring As String * Payload_size At Txbuffer(1) Overlay
Txbuffer(pls_plus1) = 0

Dim Timeout As Word
Dim Cmnd As String * 4
Dim Flags As Byte

Echoflag Alias Flags.0
Beaconflag Alias Flags.1
Sermsgflag Alias Flags.2
Rxonflag Alias Flags.3
Txonflag Alias Flags.4

'I have read somewhere that eram address 0 has a bug
'so I don't use it.
Dim Dummy As Eram Word At 0
'ProgCntr must be at eram address 2.
'ProgCntr is incramented by the bootloader
'each time the chip is flashed.
Dim Progcntr As Eram Word At 2
Dim Savedflags As Eram Byte


Tempw = Progcntr
Print "uC flashed " ; Tempw ; " times."
Print

'kill some time here while
'rfm12 does a power on reset.
Reset Rx_led
Reset Tx_led
Reset Error_led
Waitms 500
Set Rx_led
Set Tx_led
Set Error_led

Rfm12_init
Rfm12_rx_on

Flags = Savedflags
Print "Echo = " ; Echoflag
Print "Beacon = " ; Beaconflag
Cmnd = ""

Do
If Beaconflag = 1 Then
'Tx a test beacon about once a second.
Txstring = Beacon
Print "Tx: " ; Txstring
Rfm12_tx Txbuffer(1)
'now loop waiting for a reply msg.
For Temp = 1 To 255
'poll RFM12 for Rx data.
Rfm12_get_status_bit
If Rx_status_bit = 1 Then
'Rx RxBuffer
Rfm12_rx Rxbuffer(1)
Print "Rx: " ; Rxstring
If Rxstring <> Txstring Then
Reset Error_led
Print "<>"
End If
Rxstring = ""
Exit For
End If
If Temp = 255 Then
Reset Error_led
Print "no echo"
End If
'this delay gives the other module time to echo
'back the beacon.
'waitus 50 'at 38.3kbps, 32 byte payload
'waitus 350 'at 19.2kbps, 128 bytes
Waitus 150 'at 19.2kbps, 32 bytes
Set Error_led
Next Temp
Else
'poll RFM12 for Rx data.
Rfm12_get_status_bit
If Rx_status_bit = 1 Then
'reset RX_LED
'Rx RxBuffer
Rfm12_rx Rxbuffer(1)
Print "Rx: " ; Rxstring
If Echoflag = 1 Then
Print "Ec: " ; Rxstring
'Tx RxBuffer.
Rfm12_tx Rxbuffer(1)
End If
'set RX_LED
End If
End If

Temp = Inkey()
If Temp <> 0 Then

If Temp = 27 Then
'press "esc" to get a command prompt.
Spi_tx_wrd = 0
Rfm12_spi_wrt
Print
Print Description
Print File
Print Version()
Print
Tempw = Progcntr
Print "uC flashed " ; Tempw ; " times."
'print
'print "Status word = " ; bin(SPI_Rx_H) ; "_" ; bin(SPI_Rx_L)
Printflags
Print
Input "Command >" , Cmnd
Print
Rfm12_rx_on
Elseif Temp = 13 Then
Print
Print "Tx: " ; Txstring
'Tx TxBuffer.
Rfm12_tx Txbuffer(1)
Txstring = ""
Txindex = 0
Else
'fill the TxBuffer until <cr> or full.
If Txindex < Payload_size Then
Print Chr(temp);
Incr Txindex
Txbuffer(txindex) = Temp
Temp = Txindex + 1
Txbuffer(temp) = 0
End If
End If
End If


If Cmnd <> "" Then
Select Case Cmnd
Case "u"
'To start the bootloader without using the reset button.
'Press "u <CR>"
'then within 2+3=5 seconds press F4 to start the programer.
Print
Print "Press F4 to start upload."
Waitms 3000
'address of boot loader.
'for mega168
'goto &H1C00

'for mega88
Goto &HC00

Case "c"
'Input a hex command word value to send to RFM12.
'For example enter: c0e0 <enter> will set the
'ouput CLK to 10MHZ.
'see the RFM12 Programing guide for commands.
Print
Input "Enter a Command Word in HEX >" , Cmnd
Spi_tx_wrd = Hexval(cmnd)
Rfm12_spi_wrt
Print "RFM12 returned >" ; Hex(spi_rx_wrd)

Case "b"
Toggle Beaconflag
If Beaconflag = 1 Then Echoflag = 0
Saveflags
Printflags

Case "e"
Toggle Echoflag
If Echoflag = 1 Then Beaconflag = 0
Saveflags
Printflags

Case Else
Print "Unknown Command"

End Select
Print
Cmnd = ""
End If
Loop

Sub Printflags
If Beaconflag = 1 Then
Print "Beacon ON"
Else
Print "Beacon OFF"
End If
If Echoflag = 1 Then
Print "Echo ON"
Else
Print "Echo OFF"
End If
End Sub

Sub Saveflags
'save to eram
Flags = Flags And 3
Savedflags = Flags
End Sub

Sub Rfm12_init
Local I As Byte
Print "Init values:"
'Initialize RFM12
Restore Init_data
For I = 1 To 14
Read Spi_tx_wrd
Print Hex(spi_tx_wrd)
'send init data to RFM12.
Rfm12_spi_wrt
'waitms 100
Next I
Print
End Sub

'***********************************************************************
'The following data lines are RFM12 commands used to initialize the device.
'read the RFM12 progamming guide and data sheets for a complete
'description of these commands.
'
'Configuration settings:
'
'&h80D8 = Configure module for 433Mhz band.
'
'RF center Freq. setting
'select freq with const "Fc" above.
'Fcmnd is a constant that holds the Freq command.
'see the "const" statments at the top of this code.
'example: &hA000 + Fr = &hA7D0 for 435MHz
'
'To change the data rate the following values will need to be adjusted.
'
'bit rate
'&hC611 = 19.2kbps works well at 8MHz
'&hC608 = 38.3kbps works at 8MHz
'
'Rx band width
'&h94A0 = Rx BW = 134KHz works at 8MHz
'&h9480 = 200kHz works at 8MHz
'
'Tx deviation
'&h9850 = 90kHz works at 8MHz
'&h9870 = 120kHz works at 8MHz

Init_data:
Data &H80D8% , &H8298% , Fcmnd% , &HC611% , &H94A0% , &HC2AC% , &HCA81%
Data &HCED4% , &HC483% , &H9850% , &HCC17% , &HE000% , &HC800% , &HC040%
'*************************************************************************

Sub Rfm12_clear_fifo
'Clear FIFO
Spi_tx_wrd = &HCA81
Rfm12_spi_wrt
Spi_tx_wrd = &HCA83
Rfm12_spi_wrt
End Sub

Sub Rfm12_tx(txarray As Byte)
Local I As Byte
Reset Tx_led
'turn on Tx
Spi_tx_wrd = &H8239
Rfm12_spi_wrt
Txonflag = 1
Waitus 150
'Send Preamble.
Restore Txpreamble_data
For I = 1 To 5
Read Spi_tx_wrd
Rfm12_tx_ready
If Timeout = 0 Then Exit For
Rfm12_spi_wrt
Next I
'Send payload.
For I = 1 To Payload_size
Rfm12_tx_ready
If Timeout = 0 Then Exit For
Spi_tx_wrd = &HB800 + Txarray(i)
Rfm12_spi_wrt
Next I
Rfm12_tx_ready
Rfm12_rx_on
Set Tx_led
End Sub

Txpreamble_data:
Data &HB8AA% , &HB8AA% , &HB8AA% , &HB82D% , &HB8D4%

Sub Rfm12_tx_ready
Reset Rfm12_cs
Timeout = 65500
While Rfm12_sdo = 0
Decr Timeout
Waitus 6
If Timeout = 0 Then
Print "Tx Timeout"
Exit While
End If
Wend
End Sub

Sub Rfm12_rx_on
'Start Rx
Spi_tx_wrd = &H8299
Rfm12_spi_wrt
Rfm12_clear_fifo
Rxonflag = 1
Waitus 80
End Sub

Sub Rfm12_rx(rxarray As Byte)
Local I As Byte
Timeout = 1
Reset Rx_led
Spi_tx_wrd = &HB000
For I = 1 To Payload_size
Rfm12_rx_wait
If Timeout = 0 Then
Set Rx_led
Set Error_led
Exit For
End If
Rfm12_spi_wrt
Rxarray(i) = Spi_rx_l
Next I
Rxarray(i) = 0
Rfm12_clear_fifo
Set Rx_led
End Sub

Sub Rfm12_rx_wait
Timeout = 35500
Do
Rfm12_get_status_bit
'timeout if nothing happens.
Decr Timeout
If Timeout = 0 Then
Reset Error_led
Print "Rx Timeout"
Exit Do
End If
Loop Until Rx_status_bit = 1
End Sub

Sub Rfm12_get_status_bit
Reset Rfm12_sdi
Reset Rfm12_cs
Set Rfm12_sck
Rx_status_bit = Rfm12_sdo
Reset Rfm12_sck
Set Rfm12_cs
End Sub

Sub Rfm12_spi_wrt
'Send word (SPI_Tx_wrd) to RFM12.
'Also receive word (SPI_Rx_wrd).
'RFM12 Chip select
Reset Rfm12_cs
'send hi byte.
Spi_rx_h = Spimove(spi_tx_h)
'send lo byte.
Spi_rx_l = Spimove(spi_tx_l)
'deselect chip.
Set Rfm12_cs
End Sub
 

rfm12b bascom

is these codes for transmiter or reciver?
and i how to use this codes for transmiter &reciver?
 

Is samone there who tryd this code because i am playing with rfm12bp modules and then dont lett me reed data from fifo if i first not read status registar and after then u can access to data in fifo, without reading status registar i didnt be able transmitt anything (what i think mesuring current when transmitting). Here is my code in bascom bt canot get why reciever not work, can any one help plz?

p.s. sorry for my bad english.

transmitter:
Code:
$regfile = "m88def.dat"
$hwstack = 40
$swstack = 40
$framesize = 40
$crystal = 8000000
$baud = 4800


Declare Sub Init_rfm12bp
Declare Sub Spi16(byval Dout As Word)
Declare Sub Send_buffer
Dim Dout As Word
Dim Dspi As Integer
Dim Dsdo As Integer
Dim Freq As Single
Dim Param As Word
Nsel Alias Portb.2
Config Nsel = Output
Sdi Alias Portb.3
Config Sdi = Output
Sdo Alias Pinb.4
Config Sdo = Input
Sck Alias Portb.5
Config Sck = Output
Nres Alias Portb.0
Config Nres = Output
Config Portc = Output
Config Portd.5 = Output
Dim Buffer As String * 10
Dim Shulp As String * 3
Dim Bhulp As Byte
Dim Bhulp2 As Byte
Dim Bhulp3 As Byte
Dim Bhulp4 As Byte
Dim Ihulp As Integer
Dim Whulp As Word




Wait 1
Nres = 1
Gosub Init_rfm12bp

Do
      Buffer = "mulac"
      Print Buffer
      Call Send_buffer
      Wait 10
      Buffer = "ljudi"
      Print Buffer
      Call Send_buffer
Wait 10
Loop

Sub Spi16(dout As Word)
   Nsel = 0
   Dsdo = 0
   For Ihulp = 1 To 16
      Dspi = Dout And &H8000
      If Dspi = 0 Then
         Sdi = 0
      Else
         Sdi = 1
      End If
      Dout = Dout * 2
      Dsdo = Dsdo * 2
      If Sdo = 1 Then
         Dsdo = Dsdo + 1
      End If
      Sck = 1
      Nop : Nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop
      Sck = 0
      Print Sdi
   Next Ihulp
   Nsel = 1
   Print "----------------------------------"
End Sub



Sub Init_rfm12bp
Nsel = 1
Sck = 0
Call Spi16(&H80d8)
Call Spi16(&H8209)
Call Spi16(&Ha640)
Call Spi16(&Hc647)
Call Spi16(&Hcc77)
Call Spi16(&H94a0)
Call Spi16(&Hc2ac)
Call Spi16(&Hca80)
Call Spi16(&Hca83)
Call Spi16(&Hc49b)
Call Spi16(&H9850)
Call Spi16(&He000)
Call Spi16(&Hc80e)
Call Spi16(&Hc000)
End Sub



Sub Send_buffer
Set Portd.5
Call Spi16(&H0000)
Waitus 5
Call Spi16(&H8228)
Waitus 5
Call Spi16(&H8238)
Waitus 5
Call Spi16(&Hb8aa)
Waitus 5
Call Spi16(&Hb8aa)
Waitus 5
Call Spi16(&Hb8aa)
Waitus 5

Call Spi16(&Hb82d)
Waitus 5
Call Spi16(&Hb8d4)

Bhulp3 = Len(buffer)
For Bhulp = 1 To Bhulp3
    Shulp = Mid(buffer , Bhulp , 1)
    Bhulp2 = Asc(shulp)
    Param = &HB800 + Bhulp2
    Call Spi16(param)
    Print shulp
    Waitus 5
Next Bhulp
Waitus 5

Call Spi16(&Hb8aa)
Waitus 5
Call Spi16(&Hb8aa)
Waitus 5
Call Spi16(&H8208)
Reset Portd.5
End Sub

Reciever:
Code:
$regfile = "m88def.dat"
$hwstack = 128
$swstack = 128
$framesize = 128
$crystal = 8000000
$baud = 4800

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcdmode = Port
Prr = 0
'*******************************************************************************
Declare Sub Init_rfm12bp
Declare Sub Spi16(byval Dout As Word)
Dim Dout As Word
Dim Dspi As Word
Dim Dsdo As Word
Dim Param As Word
Config Portd.7 = Output
Config Portd.6 = Output
Nsel Alias Portb.2
Config Nsel = Output
Sdi Alias Portb.3
Config Sdi = Output
Sdo Alias Pinb.4
Config Sdo = Input
Sck Alias Portb.5
Config Sck = Output
Nres Alias Portb.0
Config Nres = Output
Dim Buffer As String * 10
Dim Shulp As String * 3
Dim Nspi As Integer
Dim Wd As Word
Dim E As Byte
Dim F As Byte
Dim Rxt As Bit
Dim N As Byte
Locate 1 , 1
Lcd "Simple Rx"
Wait 2
Cls
Gosub Init_rfm12bp
On Int0 Rfmpart
Enable Int0
Config Int0 = Low Level
Enable Interrupts


Do
If Rxt = 1 Then
Rxt = 0
Locate 1 , 1
Lcd Buffer
End If
Loop


Rfmpart:
    Buffer = ""
    Locate 2 , 1
    For N = 1 To 5
      Call Spi16(&H0000)
      Call Spi16(&Hb000)
      Buffer = Buffer + Chr(dsdo)
      Lcd Dsdo
    Next N
    Call Spi16(&Hca80)
    Call Spi16(&Hca83)
    Toggle Portd.7
     Rxt = 1
Return


Sub Spi16(dout As Word)                                     'RFM12BP write routine
   Nsel = 0
   Dsdo = 0
   For Nspi = 1 To 16                                       'clock 16 bits out
      Dspi = Dout And &H8000
      If Dspi = 0 Then
         Sdi = 0                                            'shiftout a 0
      Else
         Sdi = 1                                            'shiftout a 1
      End If
      Print Sdi
      Dout = Dout * 2
      Dsdo = Dsdo * 2
      If Sdo = 1 Then
         Dsdo = Dsdo + 1
      End If
      Sck = 1
      Nop : Nop : nop                                       'small wait
      nop : nop : nop
      nop : nop : nop
      nop : nop : nop
      nop : nop:  nop
      Sck = 0
   Next Nspi
   Nsel = 1
End Sub

Sub Init_rfm12bp                                            'Init the RFM12BP transceiver
Nsel = 1
Sck = 0
Call Spi16(&H80d8)
Call Spi16(&H82d9)
Call Spi16(&Ha640)
Call Spi16(&Hc647)
Call Spi16(&H94a0)
Call Spi16(&Hc2ac)
Call Spi16(&Hcc77)
Call Spi16(&Hca80)
Call Spi16(&Hca83)
Call Spi16(&Hc49b)
Call Spi16(&H9850)
Call Spi16(&Hced4)
Call Spi16(&He000)
Call Spi16(&Hc800)
Call Spi16(&Hc000)
End Sub
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top