Hi,
ich hab mal ne Frage und die Erklärung was ich die ganze Zeit hier mache.
Der Plan ist das der Joystick alle 0,25 Sek. (vlt ändert sich die Zeit auch noch --> je nach dem welche Zeiten sich als günstig rausstellen) dem MW ein Telegramm sendet in dem steht wie schnell gefahren, ob und wie stark ne Kurve gefahren oder was anderes gemacht werden soll. Wenn das MW nach 0,5 Sek noch kein Tele bekommen hat soll es stehen bleiben <-- Sicherheitsmechanismus.
Momentan möchte ich einfach PWM-Stufe und Servoposition senden und das MW soll das stur ausführen --> zum Testen.
Also hab ich mich dran gemacht und das Sende- und Empfangsprogramm geschrieben. Da aber das MW kein LCD und mein Laptop auch keine Serielle Schnittstelle hat konnte ich das Empfangsprog nicht beim MW selbst ausprobieren (da keine Ausgabemöglichkeit). Da aber der Joystick ein LCD besitzt hab ich gedacht da programmier ich das einfach verkehrt herum und tausche die Programme dann am Ende um. Das hat auch super geklappt. Hab das Sendeprog einfach stur bestimmte Zeichenfolgen ausgeben lassen und mit dem Empfangsprog aufm Joystick bekommen.
Dann hatte ich das erste kleine Problemchen. Wenn ich mir alle Zeichen die empfangen wurden auf dem LCD ausgeben lies hab ich festgestellt das nach jedem Zeichen eine 13 und ne 10 gesendet wurde. Nach ein bischen stöbern im RN hab ich einige Codes gefunden (ich find die aber nicht wieder) die auch mit diesen 13 und 10 gearbeitet haben --> da hab ich mir gedacht das die 13-10-Kombi wahrscheinlich ne Art "Zeichen-Ende" oder "Zeichen-empfangen" ist. Also mein Prog auf die 13-10 angepasst und auch gleich genutzt --> wenn die 13-10 nicht richtig empfangen wurde wurde das Datenbyte als nicht gültig gekennzeichnet.
Dann die Programme getauscht --> nix geht. Zuerst Hardware gesucht aber da ging alles. Dann die Software hin- und herkopiert. (Das hat so ewig gedauert.) Vom MW zum Joystick gings aber nicht vom Joystick zum MW.
Heute hab ich dann festgestellt was das Problem ist. Der Joystick sendet die 13-10-Kombo nicht. Wenn ich die 13-10 aus dem Prog gelöscht habe gings auf einmal.
Nun meine Frage: Was ist diese 13-10-Kombo? Wie kann ich die An- oder Abstellen? Und warum kommt die vom MW aber nicht vom Joystick?
Joystick-Sende-Code:
MW-Empfangsprog (ohne 13-10, aber noch mit Resten von 13-10-Auswertung):Code:$regfile = "m32def.dat" $framesize = 32 $swstack = 32 $hwstack = 32 $crystal = 16000000 $baud = 9600 'LCD Anschluss über 20pol Stecker' Config Lcd = 20 * 4a , Chipset = Ks077 Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portb.1 , Rs = Portb.0 Config Lcdbus = 4 'LCD Config' Config Portc.4 = Output Config Portc.5 = Output Config Portc.6 = Output Config Portc.7 = Output Config Portb.0 = Output Config Portb.1 = Output Do Wait 1 Print 2 Waitms 25 Print 4 Waitms 25 Print 5 Wait 1 Print 2 Waitms 25 Print 5 Waitms 25 Print 4 Loop
MW-Empfangsprog (mit 13-10):Code:$regfile = "m32def.dat" $framesize = 64 $swstack = 64 $hwstack = 64 $crystal = 16000000 $baud = 9600 'LEDs konfigurieren: Config Portb.0 = Output Led_gruen Alias Portb.0 'grüne LED Config Portb.1 = Output Led_rot Alias Portb.1 'rote LED 'Motoren-Ansteuerung konfigurieren: Config Portc.2 = Output Mo1_1 Alias Portc.2 Config Portc.3 = Output Mo1_2 Alias Portc.3 Config Portc.4 = Output Mo2_1 Alias Portc.4 Config Portc.5 = Output Mo2_2 Alias Portc.5 Config Pind.4 = Output 'OC1B, PWM-Ausgang Config Pind.5 = Output 'OC1A, PWM-Ausgang Config Timer1 = Pwm , Pwm = 9 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 8 Pwm1a = 0 Pwm1b = 0 Mo1_1 = 0 Mo1_2 = 0 Mo2_1 = 0 Mo2_2 = 0 Dim Pwm_stufe As Integer Pwm_stufe = 0 'Servos konfigurieren: Config Portc.6 = Output 'Servo1 Config Portc.7 = Output 'Servo2 Config Servos = 2 , Servo1 = Portc.6 , Servo2 = Portc.7 , Reload = 10 'benutzt timer0 Dim Servo_pos As Byte Dim Servo1 As Byte Servo1 = 150 Dim Servo2 As Byte Servo2 = 150 'ADC konfigurieren Config Pina.0 = Input Config Pina.1 = Input Config Pina.2 = Input Config Pina.3 = Input Config Pina.4 = Input Config Pina.5 = Input Dim Acc_x As Integer Dim Acc_y As Integer Dim Acc_z As Integer Dim Gyro_x As Integer Dim Gyro_y As Integer Dim Gyro_z As Integer Config Adc = Single , Prescaler = Auto 'Timer Konfigurieren Config Timer2 = Timer , Prescale = 8 'alle 0,000128 Sek. wird in die ISR gesprungen Enable Timer2 On Timer2 Zaehlstand Dim Zeit As Word 'zählt von 0 bis 65535, 65535 entspricht 8,38848 Sek. 'Globales: Disable Interrupts Start Adc Dim Puffer(10) As Byte Dim Puffer_index As Byte Puffer_index = 1 Dim Aktion As Byte Dim Aktion_wert_1 As Byte Dim Aktion_wert_2 As Byte Dim Aktion_wert As Integer 'Notizen: 'Servo: Braun-Masse, Rot-6V, Orange-Signal 'Timer0 für Servos 'Timer1 für Motoren 'Timer2 '###Hauptprogramm############################################################## Do If Ischarwaiting() <> 0 Then Gosub Empfangen End If If Puffer_index = 2 Then If Puffer(1) <> 0 Then 'And Puffer(2) <> 0 And Puffer(3) <> 0 Then Aktion = Puffer(1) Else If Puffer(1) <> 0 Then Aktion = 0 End If End If Puffer(1) = 0 'Puffer(2) = 0 'Puffer(3) = 0 End If If Puffer_index = 3 Then If Puffer(2) <> 0 Then 'And Puffer(5) <> 0 And Puffer(6) <> 0 Then Aktion_wert_1 = Puffer(2) Else If Puffer(2) <> 0 Then Aktion_wert_1 = 0 End If End If Puffer(2) = 0 'Puffer(5) = 0 'Puffer(6) = 0 End If If Puffer_index = 4 Then If Puffer(3) <> 0 Then 'And Puffer(8) <> 0 And Puffer(9) <> 0 Then Aktion_wert_2 = Puffer(3) Else If Puffer(3) <> 0 Then Aktion_wert_2 = 0 End If End If Puffer(7) = 0 'Puffer(8) = 0 'Puffer(9) = 0 End If If Puffer_index >= 4 Then Puffer_index = 1 End If Select Case Aktion Case 49 'Geschwindigkeit setzen, aus wert_1 und wert_2 bilden Case 50 Servo_pos = Aktion_wert_1 Case 51 'noch nicht belegt, könnte für batteriespg genutzt werden End Select If Servo_pos = 52 Then 'für Test Led_gruen = 1 Led_rot = 0 End If If Servo_pos = 53 Then 'für Test Led_gruen = 0 Led_rot = 1 End If 'Servo1 = Servo_pos + 59 'Servo2 = 150 - Servo_pos 'Servo(1) = Servo1 'Servo(2) = Servo2 'Pwm1b = Pwm_stufe Loop '###Hauptprogramm Ende######################################################### '###Sub´s###################################################################### Zaehlstand: Incr Zeit Return Empfangen: Puffer(puffer_index) = Inkey() Incr Puffer_index Return
GrußCode:$regfile = "m32def.dat" $framesize = 64 $swstack = 64 $hwstack = 64 $crystal = 16000000 $baud = 9600 'LEDs konfigurieren: Config Portb.0 = Output Led_gruen Alias Portb.0 'grüne LED Config Portb.1 = Output Led_rot Alias Portb.1 'rote LED 'Motoren-Ansteuerung konfigurieren: Config Portc.2 = Output Mo1_1 Alias Portc.2 Config Portc.3 = Output Mo1_2 Alias Portc.3 Config Portc.4 = Output Mo2_1 Alias Portc.4 Config Portc.5 = Output Mo2_2 Alias Portc.5 Config Pind.4 = Output 'OC1B, PWM-Ausgang Config Pind.5 = Output 'OC1A, PWM-Ausgang Config Timer1 = Pwm , Pwm = 9 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 8 Pwm1a = 0 Pwm1b = 0 Mo1_1 = 0 Mo1_2 = 0 Mo2_1 = 0 Mo2_2 = 0 Dim Pwm_stufe As Integer Pwm_stufe = 0 'Servos konfigurieren: Config Portc.6 = Output 'Servo1 Config Portc.7 = Output 'Servo2 Config Servos = 2 , Servo1 = Portc.6 , Servo2 = Portc.7 , Reload = 10 'benutzt timer0 Dim Servo_pos As Byte Dim Servo1 As Byte Servo1 = 150 Dim Servo2 As Byte Servo2 = 150 'ADC konfigurieren Config Pina.0 = Input Config Pina.1 = Input Config Pina.2 = Input Config Pina.3 = Input Config Pina.4 = Input Config Pina.5 = Input Dim Acc_x As Integer Dim Acc_y As Integer Dim Acc_z As Integer Dim Gyro_x As Integer Dim Gyro_y As Integer Dim Gyro_z As Integer Config Adc = Single , Prescaler = Auto 'Timer Konfigurieren Config Timer2 = Timer , Prescale = 8 'alle 0,000128 Sek. wird in die ISR gesprungen Enable Timer2 On Timer2 Zaehlstand Dim Zeit As Word 'zählt von 0 bis 65535, 65535 entspricht 8,38848 Sek. 'Globales: Disable Interrupts Start Adc Dim Puffer(10) As Byte Dim Puffer_index As Byte Puffer_index = 1 Dim Aktion As Byte Dim Aktion_wert_1 As Byte Dim Aktion_wert_2 As Byte Dim Aktion_wert As Integer 'Notizen: 'Servo: Braun-Masse, Rot-6V, Orange-Signal 'Timer0 für Servos 'Timer1 für Motoren 'Timer2 Led_gruen = 0 Led_rot = 1 Wait 1 Led_gruen = 1 Led_rot = 0 Wait 1 '###Hauptprogramm############################################################## Do If Ischarwaiting() <> 0 Then Gosub Empfangen End If If Puffer_index = 4 Then If Puffer(1) <> 0 And Puffer(2) = 13 And Puffer(3) = 10 Then Aktion = Puffer(1) Else If Puffer(3) <> 0 Then Aktion = 0 End If End If Puffer(1) = 0 Puffer(2) = 0 Puffer(3) = 0 End If If Puffer_index = 7 Then If Puffer(4) <> 0 And Puffer(5) = 13 And Puffer(6) = 10 Then Aktion_wert_1 = Puffer(4) Else If Puffer(6) <> 0 Then Aktion_wert_1 = 0 End If End If Puffer(2) = 0 Puffer(5) = 0 Puffer(6) = 0 End If If Puffer_index = 10 Then If Puffer(7) <> 0 And Puffer(8) = 13 And Puffer(9) = 10 Then Aktion_wert_2 = Puffer(7) Else If Puffer(9) <> 0 Then Aktion_wert_2 = 0 End If End If Puffer(7) = 0 Puffer(8) = 0 Puffer(9) = 0 End If If Puffer_index >= 10 Then Puffer_index = 1 End If Select Case Aktion Case 49 'Geschwindigkeit setzen, aus wert_1 und wert_2 bilden Case 50 Servo_pos = Aktion_wert_1 Case 51 'noch nicht belegt, könnte für batteriespg genutzt werden End Select If Servo_pos = 52 Then Led_gruen = 1 Led_rot = 0 End If If Servo_pos = 53 Then Led_gruen = 0 Led_rot = 1 End If 'Servo1 = Servo_pos + 59 'Servo2 = 150 - Servo_pos 'Servo(1) = Servo1 'Servo(2) = Servo2 'Pwm1b = Pwm_stufe Loop '###Hauptprogramm Ende######################################################### '###Sub´s###################################################################### Zaehlstand: Incr Zeit Return Empfangen: Puffer(puffer_index) = Inkey() Incr Puffer_index Return







) die auch mit diesen 13 und 10 gearbeitet haben --> da hab ich mir gedacht das die 13-10-Kombi wahrscheinlich ne Art "Zeichen-Ende" oder "Zeichen-empfangen" ist. Also mein Prog auf die 13-10 angepasst und auch gleich genutzt --> wenn die 13-10 nicht richtig empfangen wurde wurde das Datenbyte als nicht gültig gekennzeichnet.
)
Zitieren

Lesezeichen