Forum: Mikrocontroller und Digitale Elektronik PSX-Pad an AVR (Bascom) Problem


von Georg W. (souschl)


Lesenswert?

Hallo Leute bin neu hier und hätte da eine kleine Frage.
Ich arbeite momentan daran einen Playstation One Controller an meinem 
mega32 mit Bascom auszulesen.
Dazu hab ich den Code von dieser Seite 
http://www.grote.net/bascom/msg18553.html
den Code mal einfach kopiert und an meinen Controller angepasst.
Nun habe ich das Problem das etwas mit dem Attention (ATT) Byte nicht 
stimmt.

Das Problem ist wenn das Kabel eingesteckt ist (egal welcher Port am µC) 
bekomme ich immer die Meldung "No Response from PSX-PAD" was ja laut 
Programm dafür steht das der PSX-Controller nicht eingesteckt ist.

Wenn ich aber das ATT Kabel auf meinem Steckbrett ausstecke bekomme ich 
kurz eine Verbindung und im Terminal werden mir für 1-2 mal die Print 
Befehle für die Tasten  angezeigt, dann wieder 1-5 "No Response" und 
sobald ich das ATT Kabel wieder einsteckte geht wieder nichts!

Habe es jetzt mit einem mega8 und 2 verschiedenen mega32 ausprobiert, 
immer das gleiche.

Vieleicht könnt ihr mir ja helfen und sagen was ich falsch mache.

Hier noch mein Bascom Code:
1
  Konfiguration                                                          ***
2
'*******************************************************************************
3
'AVR
4
$regfile = "M32def.dat"
5
$crystal = 16000000
6
$hwstack = 100
7
$swstack = 100
8
$framesize = 100
9
$baud = 19200
10
11
12
'**************************************************************************
13
'*** Ein-Ausgängedefinieren                                             ***
14
'**************************************************************************
15
Config Portd.6 = Output
16
Pad_att_line Alias Portd.6
17
18
'**************************************************************************
19
'***  Variablen                                                         ***
20
'**************************************************************************
21
Dim Cmdstart As Byte
22
    Cmdstart = &H01
23
Dim Cmdstatus As Byte
24
    Cmdstatus = &H42
25
26
'PSX Type ID
27
Const Cnstid_digital = &H41
28
Const Cnstid_negocn = &H23
29
Const Cnstid_analogred = &H73
30
Const Cnstid_analoggreen = &H53
31
32
'These are for local storage of last read packet from PSX PAD
33
Dim Pspad_present As Byte
34
Dim Pspad_mode As Byte
35
Dim Pspad_byte1 As Byte
36
Dim Pspad_byte2 As Byte
37
38
'PSX PAD Joysticks
39
'Horizontal
40
Dim Pspad_rjoy_h_pos As Byte                    '0 = Left , 255 = Right
41
Dim Pspad_ljoy_h_pos As Byte                    '0 = Left , 255 = Right
42
43
'Vertikal
44
Dim Pspad_rjoy_v_pos As Byte                    '0 = Up , 255 = Down
45
Dim Pspad_ljoy_v_pos As Byte                    '0 = Up , 255 = Down
46
47
48
'**************************************************************************
49
'***  Alias Namen für PSX-PAD Tasten                                    ***
50
'**************************************************************************
51
Pspad_key_select Alias Pspad_byte1.0
52
Pspad_key_joyr Alias Pspad_byte1 .1
53
Pspad_key_joyl Alias Pspad_byte1.2
54
Pspad_key_start Alias Pspad_byte1.3
55
Pspad_key_up Alias Pspad_byte1.4
56
Pspad_key_right Alias Pspad_byte1.5
57
Pspad_key_down Alias Pspad_byte1.6
58
Pspad_key_left Alias Pspad_byte1.7
59
60
Pspad_key_l2 Alias Pspad_byte2.0
61
Pspad_key_r2 Alias Pspad_byte2.1
62
Pspad_key_l1 Alias Pspad_byte2.2
63
Pspad_key_r1 Alias Pspad_byte2.3
64
Pspad_key_triangle Alias Pspad_byte2.4
65
Pspad_key_circle Alias Pspad_byte2.5
66
Pspad_key_x Alias Pspad_byte2.6
67
Pspad_key_square Alias Pspad_byte2.7
68
69
'**************************************************************************
70
'***  Subroutine Declaration                                            ***
71
'**************************************************************************
72
Declare Sub Query_pspad
73
74
'**************************************************************************
75
'***  SPI-Mode in Hardware konfigurieren                                ***
76
'**************************************************************************
77
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , _
78
        Polarity = High , Phase = 1 , Clockrate = 128
79
Spiinit
80
81
'**************************************************************************
82
'***  HAUPTPROGRAMM                                                     ***
83
'**************************************************************************
84
85
Do
86
'Buttons are active low
87
   'Update langsam zum testen im Terminal
88
   Waitms 1000
89
   'Get current Button states from PSX-Controller
90
   Gosub Query_pspad
91
      'Now do something base on the results
92
If Pspad_present = 1 Then                  '0 = not present , 1 = present
93
94
         Print "Select:" ; Pspad_key_select
95
         Print "JoyR:" ; Pspad_key_joyr
96
         Print "JoyL:" ; Pspad_key_joyl
97
         Print "Start:" ; Pspad_key_start
98
         Print "Up:" ; Pspad_key_up
99
         Print "Right:" ; Pspad_key_right
100
         Print "Down:" ; Pspad_key_down
101
         Print "Left:" ; Pspad_key_left
102
         Print "L2:" ; Pspad_key_l2
103
         Print "R2:" ; Pspad_key_r2
104
         Print "L1:" ; Pspad_key_l1
105
         Print "R1:" ; Pspad_key_r1
106
         Print "Triangle:" ; Pspad_key_triangle
107
         Print "Circle:" ; Pspad_key_circle
108
         Print "X Key:" ; Pspad_key_x
109
         Print "Square:" ; Pspad_key_square
110
         Print "Right Joystick H Position:" ; Pspad_rjoy_h_pos
111
         Print "Right Joystick V Position:" ; Pspad_rjoy_v_pos
112
         Print "Left Joystick H Position:" ; Pspad_ljoy_h_pos
113
         Print "Left Joystick V Position:" ; Pspad_ljoy_v_pos
114
115
Else
116
   Print " No Response From PSX-PAD"
117
End If
118
119
Loop
120
121
'**************************************************************************
122
123
Sub Query_pspad
124
   Reset Pad_att_line                       'Get PSX-PAD Attention
125
      Spiout Cmdstart , 1                   'Send Start
126
   Pspad_mode = Spimove(cmdstatus)          'Send Request, Receive ID Byte
127
128
   Spiin Pspad_present , 1                  'Is PAD Responding
129
      'Now see if the Controller is going to send something
130
131
132
   If Pspad_present = 90 Then               '90 = Data on its way
133
      Pspad_present = 1                     'Set the global bit
134
      Spiin Pspad_byte1 , 1                 'Byte 1 and 2 are always used
135
      Spiin Pspad_byte2 , 1
136
      Spiin Pspad_rjoy_h_pos , 1            'Byte 3-6 are for Analog Modes
137
      Spiin Pspad_rjoy_v_pos , 1
138
      Spiin Pspad_ljoy_h_pos , 1
139
      Spiin Pspad_ljoy_v_pos , 1
140
      Set Pad_att_line
141
142
   Else
143
144
Pspad_present = 0                           'Set the   global state set  Pad_Att_Line 'Release Attention Line to the PS2 PAD
145
146
  End If
147
148
End Sub
149
150
151
'*******************************************************************************

von Karl H. (kbuchegg)


Lesenswert?

Georg Wolfsteiner schrieb:


> Nun habe ich das Problem das etwas mit dem Attention (ATT) Byte nicht
> stimmt.

Das ist kein Byte sondern eine Ausgangsleitung.

Hier
1
Config Portd.6 = Output
2
Pad_att_line Alias Portd.6
steht eindeutig an welchem Port-Pin die Leitung rauskommt.

> Das Problem ist wenn das Kabel eingesteckt ist (egal welcher Port am µC)

Du kannst nicht einfach an irgendeinen Port anstecken. Du musst schon 
den Pin nehmen, der auch im Programm benutzt wird.

> bekomme ich immer die Meldung "No Response from PSX-PAD" was ja laut
> Programm dafür steht das der PSX-Controller nicht eingesteckt ist.

Nö.
Das steht dafür, dass sich der Controller nicht gemeldet hat. Warum auch 
immer. Da gibt es ja auch noch andere Gründe.

zb. kannst du nicht einfach
1
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , _
2
        Polarity = High , Phase = 1 , Clockrate = 128

irgendwelche Portpins für die Datenübertragung benutzen, sondern musst 
natürlich schon die vom Mega vorgegebenen SPI Pins dafür benutzen und 
dann auch noch richtig mit dem Controller verbinden. Sonst kommt keine 
Kommunikation zu Stande und dein Programm gibt "No Response From 
PSX-PAD" aus.

: Bearbeitet durch User
von Georg W. (souschl)


Lesenswert?

Hallo Karl, ich glaube ich hätte mich genauer ausdrücken sollen!

> Das ist kein Byte sondern eine Ausgangsleitung.

Da habe ich wohl falsch gedacht, danke für die Ausbesserung

> Du kannst nicht einfach an irgendeinen Port anstecken. Du musst schon
> den Pin nehmen, der auch im Programm benutzt wird.

Das ist mir natürlich klar, ich habe damit gemeint egal welchen Pin/Port 
ich im Programm angebe (und die ATT-Leitung an dem definiertem Pin 
anstecke) , es funktioniert nicht

> Nö.
> Das steht dafür, dass sich der Controller nicht gemeldet hat. Warum auch
> immer. Da gibt es ja auch noch andere Gründe.
>
> zb. kannst du nicht einfach
>
1
> Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , 
2
> _
3
>         Polarity = High , Phase = 1 , Clockrate = 128
4
> 
5
>
>
> irgendwelche Portpins für die Datenübertragung benutzen, sondern musst
> natürlich schon die vom Mega vorgegebenen SPI Pins dafür benutzen und
> dann auch noch richtig mit dem Controller verbinden. Sonst kommt keine
> Kommunikation zu Stande und dein Programm gibt "No Response From
> PSX-PAD" aus.

Wie ist das gemeint? Muss ich bei Config Spi also die Portpins MOSI, 
MISO und SCK (an die das PSX-PAD natürlich angeschlossen ist) also extra 
angeben oder reicht es so wie ich es im Programm gemacht habe? (Ist 
meine erste Anwendung mit SPI)

Danke für die Hilfe

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.