Hallo,
ich habe 2 RFM12 Funkmodule mit dem Code von Elektor getestet. Nun habe ich eine Verständnissfrage zur Baudrateneinstellung.
Wie stellt man die Baudrate für die Funkübertragung ein bzw was muss ich ändern um zb. auf 9600 Baud zu kommen?
Code:
'Init
Nsel = 1
Sck = 0
'D = Spi16(&H80d7) ' El , Ef , 11.5pf, 433 MHz band
D = Spi16(&H80e7) ' El , Ef , 11.5pf, 868 MHz band
D = Spi16(&H82d9) '!er , !ebb , Et , Es , Ex , !eb , !ew , Dc
D = Spi16(&Ha67c) ' 434,15 MHz / 868,3 MHz
D = Spi16(&Hc647) ' 4.8kbps
D = Spi16(&H94a4) ' Vdi , Fast , 134 kHz , 0db , -79dbm
D = Spi16(&Hc2ac) ' Al , !ml , Dig , Dqd4
D = Spi16(&Hca81) ' Fifo8 , Sync , !ff , Dr
D = Spi16(&Hc483) ' @pwr , No Rstric , !st , !fi , Oe , En
D = Spi16(&H9850) ' 90 kHz , power - 0 dB
D = Spi16(&He000) '
D = Spi16(&Hc800) '
D = Spi16(&Hc000) ' 1 MHz , 2.2V
Freq = 868.300
bzw. hier der ganze Code:
Code:
$regfile = "m32def.dat"
$hwstack = 32
$swstack = 10
$framesize = 40
$crystal = 14745600
$baud = 9600
Nsel Alias Portb.4
Sdi Alias Portb.5
Sdo Alias Pinb.6
Sck Alias Portb.7
Dim D As Word
Dim Data_in(10) As Byte
Dim Data_out(10) As Byte
Dim N As Byte
Dim Timeout As Word
Dim T As Word
Dim Tt As Word
Dim Freq As Single
Declare Sub Send_rfm12
Declare Sub Receive_rfm12
Declare Sub Freq_rfm12
Declare Sub Wait_rfm12
Declare Function Spi16(byval Dout As Word) As Word
Config Nsel = Output
Config Sdi = Output
Config Sck = Output
Config Portc = Output
Porta = &HFF
'Init
Nsel = 1
Sck = 0
'D = Spi16(&H80d7) ' El , Ef , 11.5pf, 433 MHz band
D = Spi16(&H80e7) ' El , Ef , 11.5pf, 868 MHz band
D = Spi16(&H82d9) '!er , !ebb , Et , Es , Ex , !eb , !ew , Dc
D = Spi16(&Ha67c) ' 434,15 MHz / 868,3 MHz
D = Spi16(&Hc647) ' 4.8kbps
D = Spi16(&H94a4) ' Vdi , Fast , 134 kHz , 0db , -79dbm
D = Spi16(&Hc2ac) ' Al , !ml , Dig , Dqd4
D = Spi16(&Hca81) ' Fifo8 , Sync , !ff , Dr
D = Spi16(&Hc483) ' @pwr , No Rstric , !st , !fi , Oe , En
D = Spi16(&H9850) ' 90 kHz , power - 0 dB
D = Spi16(&He000) '
D = Spi16(&Hc800) '
D = Spi16(&Hc000) ' 1 MHz , 2.2V
Freq = 868.300
Freq_rfm12
'start transmitter, no data
'Goto Test1:
'transmit data
'Goto Test2:
'transmit key data
'Goto Test3:
'start receiver, all data
'Goto Test4:
'start receiver, matched data
'Goto Test5:
Do
For N = 1 To 10
Data_out(n) = N
Next N
Send_rfm12
Waitms 500
For N = 1 To 10
Data_in(n) = 0
Next N
Timeout = 400 + Rnd(1000)
Receive_rfm12
For N = 1 To 10
Print Data_in(n) ; " "
'Print " ";
Next N
Waitms 700
Loop
Sub Freq_rfm12
If Freq < 800 Then Freq = Freq * 2
Freq = Freq - 860
D = Freq / 0.0050
If D < 96 Then D = 96
If D > 3903 Then D = 3903
D = D + &HA000
D = Spi16(d)
End Sub
Sub Send_rfm12
D = Spi16(&H8238)
Wait_rfm12
D = Spi16(&Hb8aa)
Wait_rfm12
D = Spi16(&Hb8aa)
Wait_rfm12
D = Spi16(&Hb8aa)
Wait_rfm12
D = Spi16(&Hb82d)
Wait_rfm12
D = Spi16(&Hb8d4)
For N = 1 To 10
Wait_rfm12
D = &HB800 + Data_out(n)
D = Spi16(d)
Next N
Wait_rfm12
D = Spi16(&Hb8aa)
Wait_rfm12
D = Spi16(&Hb8aa)
Wait_rfm12
D = Spi16(&H8208)
End Sub
Sub Wait_rfm12
Nsel = 0
Do
Loop Until Sdo = 1
End Sub
Sub Receive_rfm12
Tt = Timeout * 10
D = Spi16(&H82c8)
D = Spi16(&Hca83)
For N = 1 To 10
Nsel = 0
T = 0
Do
T = T + 1
Waitus 100
If T > Tt Then Goto Nosignal
Loop Until Sdo = 1
D = Spi16(&Hb000)
Data_in(n) = D
Next N
Nosignal:
D = Spi16(&H8208)
End Sub
Function Spi16(byval Dout As Word) As Word
Local Nspi As Integer
Local Dspi As Integer
Local Dsdo As Word
Nsel = 0
Dsdo = 0
For Nspi = 1 To 16
Dspi = Dout And &H8000
If Dspi = 0 Then
Sdi = 0
Else
Sdi = 1
End If
Dout = Dout * 2
Dsdo = Dsdo * 2
Dsdo = Dsdo + Sdo
Sck = 1
Waitus 5
Sck = 0
Next Nspi
Nsel = 1
Spi16 = Dsdo
End Function
'transceiver tests
'start transmitter, no data
Test1:
D = Spi16(&H8238)
Do
Loop
'transmit data
Test2:
D = Spi16(&H8238)
Do
Wait_rfm12
D = Spi16(&Hb8aa)
Loop
'transmit key data
Test3:
D = Spi16(&H8238)
Do
Wait_rfm12
D = Spi16(&Hb82d)
Wait_rfm12
D = Spi16(&Hb8d4)
Loop
'start receiver, all data
Test4:
D = Spi16(&H82c8)
D = Spi16(&Hca87)
For N = 1 To 100
Wait_rfm12
D = Spi16(&Hb000)
Data_in(n) = D
Print Chr(d);
Next N
Do
Loop
'start receiver, matched data
Test5:
D = Spi16(&H82c8)
D = Spi16(&Hca83)
For N = 1 To 100
Wait_rfm12
D = Spi16(&Hb000)
Data_in(n) = D
Print Chr(d);
Next N
Do
Loop
Lesezeichen