PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Datenübertragung (Rs232 oder RS485)



elkokiller
01.10.2006, 21:05
Hallo,

ich möchte Texte über RS485 übertragen.
Auf dem terminalprogramm erhalte ich aber nur irgent welche Zeichen.
Wie finde ich die richtige Einstellung für das Terminalfenster heraus?

Meine Daten: Atmega8, 7,3728 MHz, Max485

Im Programm habe ich folgendes in den Code aufgenommen
$regfile = "m8def.dat"
$crystal = 7372800
$baud = 9600

Wär toll wenn ihr mir ein paar Tips geben könntet

Tobias

Vitis
01.10.2006, 22:03
Wenn Dein Mega8 auf 7,3728MHz läuft, dann läuft die UART auf
9600 baud, 8 Datenbit, 1 Stopbit, keine Parität.

also 9600,8,n,1

veit
02.10.2006, 13:05
welches proggie benutzt du denn?

gibts da optionen für ascii-zeichen oder sowas?

elkokiller
02.10.2006, 16:46
Hallo,

hier mein Code.
Bisher sehe ich nur etwas wenn ich in Terminalfenster 1200Baud einstelle.
leider nicht mein Text sonder nur wirre Zeichen

Hier mein Code



$regfile = "m8def.dat"
$crystal = 7372800
$baud = 9600


Config Pinc.0 = Input ' Schaltport
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Pinc.5 = Input ' N.N.

Config Portb.0 = Output ' Schaltport
Config Portb.1 = Output
Config Portb.2 = Output
Config Portd.7 = Output
Config Portd.6 = Output

Config Portb.5 = Output ' Kontrollport

Config Portd.2 = Output ' RS485


Dim I As Byte
Dim Key As Byte

Dim S As String * 7
Dim A As String * 4
Dim X1 As Boolean
Dim X2 As Boolean
Dim X3 As Boolean
Dim X4 As Boolean
Dim Z As String * 1

' **** Timer *********************************************

Dim T1 As Long
Dim T2 As Long
Dim T3 As Long
Dim T4 As Long
Dim T5 As Long


Dim R1 As Bit
Dim R2 As Bit
Dim R3 As Bit
Dim R4 As Bit
Dim R5 As Bit


T1 = 0
T2 = 0
T3 = 0
T4 = 0
T5 = 0


Const Keys = 5

'Schaltstelle "$O001" ' Name der Schaltstelle
' Format: $O = Output
' $I = Input
' $IO = InOut

' **** Programmstart **************************************

Do


R1 = Portb.0
R2 = Portb.1
R3 = Portb.2
R4 = Portd.6
R5 = Portd.7



' **** RS485 Aktivieren und Bus prüfen

On Urxc Onrxd
Enable Urxc
Enable Interrupts


If Len(s) > 3 Then
A = S
S = ""
Goto Pruefung


Else

Disable Interrupts
Disable Urxc
'Portd.2 = 1
'Print
'Portd.2 = 0
End If


'Zeitschalter (Zähler) 10.000.000 = 30 Minute

If T1 > 0 Then T1 = T1 + 1

If T1 > 30000000 Then
Portd.6 = 0
T1 = 0
Else
End If


If T2 > 0 Then T2 = T2 + 1

If T2 > 80000000 Then
Portb.0 = 0
T2 = 0
Else
End If


If T3 > 0 Then T3 = T3 + 1

If T3 > 30000000 Then
Portb.2 = 0
T3 = 0
Else
End If


If T4 > 0 Then T4 = T4 + 1

If T4 > 15000000 Then
Portd.7 = 0
T4 = 0
Else
End If


If T5 > 0 Then T5 = T5 + 1

If T5 > 30000000 Then
Portb.1 = 0
T5 = 0
Else
End If


Portb.5 = 1

For I = 1 To Keys
Key = I
Select Case Key
Case 1 : Debounce Pinc.0 , 0 , Key_o1 , Sub 'Port 1.
Case 2 : Debounce Pinc.1 , 0 , Key_o2 , Sub 'Port 2
Case 3 : Debounce Pinc.2 , 0 , Key_o3 , Sub 'Port 3
Case 4 : Debounce Pinc.3 , 0 , Key_o4 , Sub 'Port 4
Case 5 : Debounce Pinc.4 , 0 , Key_o5 , Sub 'Port 5


End Select
Next

Loop

Key_o1:
Toggle Portb.0 'Buchse 1

Gosub Zustand

If T2 = 0 Then
T2 = 1
Else
T2 = 0
End If
Return


Key_o2:
Toggle Portb.1 'Buchse 2

Gosub Zustand

If T5 = 0 Then
T5 = 1
Else
T5 = 0
End If
Return


Key_o3:
Toggle Portb.2 'Buchse 3

Gosub Zustand

If T3 = 0 Then
T3 = 1
Else
T3 = 0
End If
Return


Key_o5:

Toggle Portd.6 'Buchse 4

Gosub Zustand

If T1 = 0 Then
T1 = 1
Else
T1 = 0
End If
Return


Key_o4:
Toggle Portd.7 'Buchse 5

Gosub Zustand

If T4 = 0 Then
T4 = 1
Else
T4 = 0
End If
Return


'************************************************* ***


Onrxd:
S = S + Chr(udr)
Return

'************************************************* ***


Pruefung:

Z = Mid(a , 1 , 1 )
If Z = "!" Then
Goto Auswerter
A = Mid(s , 1 , 6)
Else

S = ""
End If
Return

'************************************************* ***

Zustand:
Disable Interrupts
Disable Urxc
Waitms 100

R1 = Portb.0
R2 = Portb.1
R3 = Portb.2
R4 = Portd.6
R5 = Portd.7

Disable Interrupts
Disable Urxc
Waitms 5
Portd.2 = 1
Waitms 10
Print
Print "$O001" ; R1 ; R2 ; R3 ; R4 ; R5
Waitms 5
Portd.2 = 0

Return



'************************************************* ***

Auswerter:
Disable Interrupts
Disable Urxc
Waitms 100
Portd.2 = 1

Waitms 10
Print
'Print A

Print "$O001" ; R1 ; R2 ; R3 ; R4 ; R5


Waitms 100
Portd.2 = 0

Return


End

Vitis
02.10.2006, 21:25
tja, dann stimmt vermutlich Deine Taktquelle nicht.
Ich vermute mal du hast die fuses nicht auf
external crystal umgestellt, oder?
Dann läuft die Kiste nämlich nur mit 1MHz und entsprechend stimmt dann
die Baudrate nicht

elkokiller
03.10.2006, 08:41
Schau mal bitte in der Anlage.
So sollte der Atmega 8 doch mit dem Quarztakt arbeiten, oder?

Vitis
03.10.2006, 13:22
für was brauchste denn das Pony?
Bascom hat doch nen programmer intus