Hallo Jungs!
Ich hab mir mal 2 RFM12 Module (868MHz) zugelegt und bin schon kräftig am rum experimentieren gewesen, aber ich komme leider nicht weiter.
Die Hardware besteht aus einem Mega32, einem RFM12 und einem 16*2 LCD. Das ganze 2 mal, einmal zum senden und einmal zum empfangen. Es soll erstmal nur eine unidirektionale Verbindung aufgebaut werden.
Ich habe mir als Grundlage mal den Artikel und den Code aus der Elektor 1/2009 (der Artikel von B. Kainka => Funk für den Controller) genommen.
Der Code ist bereits in den µCs drinne. Eigentlich werden in dem Programm Daten der µCs per UART ausgegeben, mangels serieller Schnittstelle am PC werden die bei mir einfach auf ein LCD ausgegeben.
Wenn ich das original Programm laufen lasse, dann erscheint eine Null auf beiden LCDs, welche regelmäßig neu geladen wird (quasi "blinkt").
Wenn ich nun aber folgendes Programm in den Transmitter flashe, dann bleibt das Display leer:
Code:
'Elektor RFM12
$regfile = "m32def.dat"
$hwstack = 32
$swstack = 10
$framesize = 40
$crystal = 8000000
$baud = 19200
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
' #### von mir hinzugefügt ###
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2
Cursor Off
'####################################
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
Cls
Lcd Data_in(n);
Lcd " ";
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
Lcd 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
Lcd Chr(d);
Next N
Do
Loop
Das Display vom Receiver zeigt nur 3 kleine, senkrechte Striche an, mehr nicht:
Code:
'Elektor RFM12
$regfile = "m32def.dat"
$hwstack = 32
$swstack = 10
$framesize = 40
$crystal = 8000000
$baud = 19200
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
' ### von mir hinzugefügt ####
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2
Cursor Off
'#################################
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
Cls
Lcd Data_in(n);
Lcd " ";
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
Lcd 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
Lcd Chr(d);
Next N
Do
Loop
Ich würde gerne den Original-Artikel uploaden, ich weiß aber nicht inwiefern es da Ärger mit Elektor geben könnte..http://www.elektor.de/jahrgang/2009/...08.lynkx?tab=4
Könnt ihr mir evt. helfen, die Module zum laufen zu bekommen?
Lesezeichen