Hallo
Es funktioniert !!! \/ \/ \/
Habe die Dinger zum Laufen gebracht. Ich habe einfach die Baudrate auf 1200 Baud gesetzt und seit dem kommts auch an. Zwar ist immer noch des letzte übertragene Zeichen Müll, aber das ist eine Kleinigkeit. Seltsamerweise setzt die erste Übertragung auch nicht an der ersten Stelle auf, sondern irgendwo mittendrin. Es sind immer ein paar Blanks am Anfang. Naja, halt beim ersten Mal senden.
OK, hab Programm noch ein wenig angepaßt.
Sender:
Code:
' Atmega8
' VDD -> VCC
' GND -> GND
' SDI -> MOSI (PB3, Pin 17)
' SDO -> MISO (PB4, Pin 18)
' SCK -> SCK (PB5, Pin 19)
' nSel -> SS (PB2, Pin 16)
' Fsk - > R 10k nach VDD
' Atmega16
' VDD -> VCC
' GND -> GND
' SDI -> MOSI (PB5, Pin 6)
' SDO -> MISO (PB6, Pin 7)
' SCK -> SCK (PB7, Pin 8)
' nSel -> SS (PB4, Pin 5)
' Fsk - > R 10k nach VDD
$regfile = "m8def.dat"
$crystal = 1000000 '
$hwstack = 32
$swstack = 32
$framesize = 40
Declare Sub Rf12_init
Declare Function Rf12_trans(byval Wert As Word) As Word
Declare Sub Rf12_setfreq(byval Freq As Single)
Declare Sub Rf12_setbandwith(byval Bandwith As Byte , Byval Gain As Byte , Byval Drssi As Byte)
Declare Sub Rf12_setbaud(byval Rfbaud As Long)
Declare Sub Rf12_setpower(byval Outpower As Byte , Byval Fskmod As Byte)
Declare Sub Rf12_ready
Declare Sub Rf12_readys
Declare Sub Rf12_txdata(byval Maxchar As Byte)
Declare Sub Rf12_rxdata(byval Maxchar As Byte)
Declare Sub Senden
Declare Sub Empfangen
Const Rf12freq = 433.92
Const Rf12baud = 1200
Const Maxchar = 16
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 , Chipset = Dogm162v3
Cursor Off Noblink
Cls
' config the SPI in master mode.The clock must be a quarter of the slave cpu
' Hier ggf. den SoftSPI reinmachen
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1
Config Portb.1 = Output ' LED zur Schleifenkontrolle
' werden benötigt für rf12_ready
Spi_cs Alias Portb.2 ' SS-Pin
Config Spi_cs = Output
Spi_sdo Alias Pinb.4 ' MISO-PIN
Set Spi_cs
' init the spi pins
Spiinit
Dim Count As Byte
Dim Temp As Word
Dim Rfdata(32) As Byte
Dim Text As String * Maxchar At Rfdata Overlay
Dim J As Byte
Locate 1 , 1 : Lcd "Init RFM12 "
Waitms 100
Call Rf12_init ' ein paar Register setzen (z.B. CLK auf 10MHz)
Locate 1 , 1 : Lcd "Set Frequenz "
Waitms 100
Call Rf12_setfreq(rf12freq) ' Sende/Empfangsfrequenz auf 433,92MHz einstellen
Locate 1 , 1 : Lcd "Set Bandwith "
Waitms 100
Call Rf12_setbandwith(4 , 1 , 4) ' 200kHz Bandbreite, -6dB Verstärkung, DRSSI threshold: -79dBm
Locate 1 , 1 : Lcd "Set Baudrate "
Waitms 100
Call Rf12_setbaud(rf12baud) ' 19200 baud
Locate 1 , 1 : Lcd "Set Tx-Power "
Waitms 100
Call Rf12_setpower(0 , 6) ' 1mW Ausgangangsleistung, 120kHz Frequenzshift
'Text = "Dies ist ein 433MHz Test !!!!!{013}{010}"
' Je nachdem ob Sender oder Empfänger die entsprechenden Zeilen aktivieren
Do ' Ewigschleife
Pulseout Portb , 1 , 500 ' Schleifenkontrolle
Text = "433MHz Test #" + Str(j)
Senden
Locate 1 , 1 : Lcd "Ready "
Incr J
Wait 3
Loop
End
' ########################################################################
' ####### Tranceiverroutinen
' ########################################################################
Sub Empfangen
Locate 2 , 1 : Lcd "Empfange "
Waitms 100
Call Rf12_rxdata(maxchar)
Locate 2 , 1 : Lcd " "
Locate 2 , 1
For Count = 1 To Maxchar
Lcd Chr(rfdata(count)) ;
Waitms 100
Next Count
End Sub
Sub Senden
Locate 1 , 1 : Lcd "Sende "
Waitms 100
Call Rf12_txdata(maxchar)
Waitms 10
End Sub
' ########################################################################
' ###### Unterroutinen
' ########################################################################
Sub Rf12_init:
Waitms 150
Temp = Rf12_trans(&Hc0e0)
Temp = Rf12_trans(&H80d7)
Temp = Rf12_trans(&Hc2ab)
Temp = Rf12_trans(&Hca81)
Temp = Rf12_trans(&He000)
Temp = Rf12_trans(&Hc800)
Temp = Rf12_trans(&Hc4f7)
End Sub
Sub Rf12_setfreq(byval Freq As Single)
Freq = Freq - 430.00
Temp = Freq / 0.0025
If Temp < 96 Then
Temp = 96
Elseif Temp > 3903 Then
Temp = 3903
End If
Temp = Temp + &HA000
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setbandwith(byval Bandwith As Byte , Byval Gain As Byte , Byval Drssi As Byte)
Drssi = Drssi And 7
Gain = Gain And 3
Temp = Bandwith And 7
Shift Temp , Left , 2
Temp = Temp + Gain
Shift Temp , Left , 3
Temp = Temp + Drssi
Temp = Temp + &H9400
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setbaud(byval Rfbaud As Long )
Local Ltemp As Long
If Rfbaud < 663 Then Exit Sub
If Rfbaud < 5400 Then
Temp = 43104 / Rfbaud
Temp = Temp + &HC680
Else
Ltemp = 344828 / Rfbaud
Temp = Ltemp
Temp = Temp + &HC600
End If
Decr Temp
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setpower(byval Outpower As Byte , Byval Fskmod As Byte)
Outpower = Outpower And 7
Temp = Fskmod And 15
Shift Temp , Left , 4
Temp = Temp + Outpower
Temp = Temp + &H9800
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_txdata(byval Maxchar As Byte)
Temp = Rf12_trans(&H8238)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb82d)
Rf12_ready
Temp = Rf12_trans(&Hb8d4)
Rf12_ready
For Count = 1 To Maxchar
Rf12_ready
Temp = &HB800 + Rfdata(count)
Temp = Rf12_trans(temp)
Next Count
Rf12_ready
Temp = Rf12_trans(&H8208)
End Sub
Sub Rf12_rxdata(byval Maxchar As Byte)
Temp = Rf12_trans(&H82c8)
Temp = Rf12_trans(&Hca81)
Temp = Rf12_trans(&Hca83)
For Count = 1 To Maxchar
Rf12_ready
Temp = Rf12_trans(&Hb000)
Rfdata(count) = Temp
Next Count
Temp = Rf12_trans(&H8208)
End Sub
Function Rf12_trans(byval Wert As Word) As Word
Local Lowbyte As Byte
Local Highbyte As Byte
Lowbyte = Wert And 255
Shift Wert , Right , 8
Reset Spi_cs
Highbyte = Spimove(wert)
Lowbyte = Spimove(lowbyte)
Set Spi_cs
Temp = Highbyte * 256
Temp = Temp + Lowbyte
Rf12_trans = Temp
End Function
Sub Rf12_ready
Local I As Word
Reset Spi_cs
For I = 1 To 65000
If Spi_sdo = 1 Then Exit For
Next
End Sub
Empfänger:
Code:
' Atmega8
' VDD -> VCC
' GND -> GND
' SDI -> MOSI (PB3, Pin 17)
' SDO -> MISO (PB4, Pin 18)
' SCK -> SCK (PB5, Pin 19)
' nSel -> SS (PB2, Pin 16)
' Fsk - > R 10k
' Atmega16
' VDD -> VCC
' GND -> GND
' SDI -> MOSI (PB5, Pin 6)
' SDO -> MISO (PB6, Pin 7)
' SCK -> SCK (PB7, Pin 8)
' nSel -> SS (PB4, Pin 5)
' Fsk - > R 10k
$regfile = "m16def.dat"
$crystal = 1000000 '
$hwstack = 32
$swstack = 32
$framesize = 40
Declare Sub Rf12_init
Declare Function Rf12_trans(byval Wert As Word) As Word
Declare Sub Rf12_setfreq(byval Freq As Single)
Declare Sub Rf12_setbandwith(byval Bandwith As Byte , Byval Gain As Byte , Byval Drssi As Byte)
Declare Sub Rf12_setbaud(byval Rfbaud As Long)
Declare Sub Rf12_setpower(byval Outpower As Byte , Byval Fskmod As Byte)
Declare Sub Rf12_ready
Declare Sub Rf12_readys
Declare Sub Rf12_txdata(byval Maxchar As Byte)
Declare Sub Rf12_rxdata(byval Maxchar As Byte)
Declare Sub Senden
Declare Sub Empfangen
Const Rf12freq = 433.92
Const Rf12baud = 1200
Const Maxchar = 16
Config Lcdpin = Pin , Db4 = Porta.7 , Db5 = Porta.6 , Db6 = Porta.5 , Db7 = Porta.4 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2 , Chipset = Dogm162v3
Cursor Off Noblink
Cls
' config the SPI in master mode.The clock must be a quarter of the slave cpu
' Hier ggf. den SoftSPI reinmachen
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1
Config Portd.7 = Output ' LED zur Schleifenkontrolle
' werden benötigt für rf12_ready
Spi_cs Alias Portb.4 ' SS-Pin
Config Spi_cs = Output
Spi_sdo Alias Pinb.6 ' MISO-PIN
Set Spi_cs
' init the spi pins
Spiinit
Dim Count As Byte
Dim Temp As Word
Dim Rfdata(32) As Byte
Dim Text As String * Maxchar At Rfdata Overlay
'Dim J As Byte
Locate 1 , 1 : Lcd "Init RFM12 "
Waitms 100
Call Rf12_init ' ein paar Register setzen (z.B. CLK auf 10MHz)
Locate 1 , 1 : Lcd "Set Frequenz "
Waitms 100
Call Rf12_setfreq(rf12freq) ' Sende/Empfangsfrequenz auf 433,92MHz einstellen
Locate 1 , 1 : Lcd "Set Bandwith "
Waitms 100
Call Rf12_setbandwith(4 , 1 , 4) ' 200kHz Bandbreite, -6dB Verstärkung, DRSSI threshold: -79dBm
Locate 1 , 1 : Lcd "Set Baudrate "
Waitms 100
Call Rf12_setbaud(rf12baud) ' 19200 baud
Locate 1 , 1 : Lcd "Set Tx-Power "
Waitms 100
Call Rf12_setpower(0 , 6) ' 1mW Ausgangangsleistung, 120kHz Frequenzshift
'Text = "Dies ist ein 433MHz Test !!!!!{013}{010}"
'Text = "433MHz Test #" + J
' Je nachdem ob Sender oder Empfänger die entsprechenden Zeilen aktivieren
Do ' Ewigschleife
Empfangen
Pulseout Portd , 7 , 500 ' Schleifenkontrolle
Locate 1 , 1 : Lcd "Ready "
Wait 1
Loop
End
' ########################################################################
' ####### Tranceiverroutinen
' ########################################################################
Sub Empfangen
Locate 1 , 1 : Lcd "Empfange "
Waitms 100
Locate 2 , 1 : Lcd " "
Locate 2 , 1
Call Rf12_rxdata(maxchar)
For Count = 1 To Maxchar
Lcd Chr(rfdata(count)) ;
Waitms 100
Next Count
End Sub
Sub Senden
Locate 1 , 1 : Lcd "Sende "
Waitms 100
Call Rf12_txdata(maxchar)
Waitms 10
End Sub
' ########################################################################
' ###### Unterroutinen
' ########################################################################
Sub Rf12_init:
Waitms 150
Temp = Rf12_trans(&Hc0e0)
Temp = Rf12_trans(&H80d7)
Temp = Rf12_trans(&Hc2ab)
Temp = Rf12_trans(&Hca81)
Temp = Rf12_trans(&He000)
Temp = Rf12_trans(&Hc800)
Temp = Rf12_trans(&Hc4f7)
End Sub
Sub Rf12_setfreq(byval Freq As Single)
Freq = Freq - 430.00
Temp = Freq / 0.0025
If Temp < 96 Then
Temp = 96
Elseif Temp > 3903 Then
Temp = 3903
End If
Temp = Temp + &HA000
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setbandwith(byval Bandwith As Byte , Byval Gain As Byte , Byval Drssi As Byte)
Drssi = Drssi And 7
Gain = Gain And 3
Temp = Bandwith And 7
Shift Temp , Left , 2
Temp = Temp + Gain
Shift Temp , Left , 3
Temp = Temp + Drssi
Temp = Temp + &H9400
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setbaud(byval Rfbaud As Long )
Local Ltemp As Long
If Rfbaud < 663 Then Exit Sub
If Rfbaud < 5400 Then
Temp = 43104 / Rfbaud
Temp = Temp + &HC680
Else
Ltemp = 344828 / Rfbaud
Temp = Ltemp
Temp = Temp + &HC600
End If
Decr Temp
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_setpower(byval Outpower As Byte , Byval Fskmod As Byte)
Outpower = Outpower And 7
Temp = Fskmod And 15
Shift Temp , Left , 4
Temp = Temp + Outpower
Temp = Temp + &H9800
Temp = Rf12_trans(temp)
End Sub
Sub Rf12_txdata(byval Maxchar As Byte)
Temp = Rf12_trans(&H8238)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb8aa)
Rf12_ready
Temp = Rf12_trans(&Hb82d)
Rf12_ready
Temp = Rf12_trans(&Hb8d4)
Rf12_ready
For Count = 1 To Maxchar
Rf12_ready
Temp = &HB800 + Rfdata(count)
Temp = Rf12_trans(temp)
Next Count
Rf12_ready
Temp = Rf12_trans(&H8208)
End Sub
Sub Rf12_rxdata(byval Maxchar As Byte)
Temp = Rf12_trans(&H82c8)
Temp = Rf12_trans(&Hca81)
Temp = Rf12_trans(&Hca83)
For Count = 1 To Maxchar
Rf12_ready
Temp = Rf12_trans(&Hb000)
Rfdata(count) = Temp
Next Count
Temp = Rf12_trans(&H8208)
End Sub
Function Rf12_trans(byval Wert As Word) As Word
Local Lowbyte As Byte
Local Highbyte As Byte
Lowbyte = Wert And 255
Shift Wert , Right , 8
Reset Spi_cs
Highbyte = Spimove(wert)
Lowbyte = Spimove(lowbyte)
Set Spi_cs
Temp = Highbyte * 256
Temp = Temp + Lowbyte
Rf12_trans = Temp
End Function
Sub Rf12_ready
Local I As Word
Reset Spi_cs
For I = 1 To 65000
If Spi_sdo = 1 Then Exit For
Next
End Sub
@Wigbert:
Die 1 Sekunde Warten war offensichtlich kein Problem. Ja OK, wenn während der Zeit was gesendet wurde gings natürlich ins Nirwana.
Ist da eigentlich ein Schreibfehler ?
Sub Rf12_setbaud(byval Rfbaud As Long )
Local Ltemp As Long
If Rfbaud < 663 Then Exit Sub
If Rfbaud < 5400 Then
Temp = 43104 / Rfbaud
Temp = Temp + &HC680
Else
Ltemp = 344828 / Rfbaud
Temp = Ltemp
Temp = Temp + &HC600
Decr Temp
Temp = Rf12_trans(temp)
End Sub
Das rot markierte meine ich. Das würde zumindest bei mir den Fehler mit der herunter gesetzten Baudrate erklären.
Thomas
Lesezeichen