Hallo!
Bin schon fast am verzweifeln. Folgende Situation: An meiner RN-Control hab ich das SRF10-Modul+Sevo hängen und möchte es über einen gesendeten RS232 Befehl vom PC abfragen.
Erstmal ne Routine ohne RS232, sondern nur die Entfernung von drei Servopositionen abgefragt. Funktioniert wunderbar.
Wenns interessiert ist hier der Code:
Ist das bekannte Programm vom SRF10.Code:'################################################### 'srf10_ultraschallbeispiel2.bas 'für 'RoboterNetz Board RN-Control (ab Version 1.1) 'und das SRF10 Ultraschallmodul für Entfernungsmessung 'Datenblatt zu SRF10: 'https://www.roboternetz.de/phpBB2/dload.php?action=file&file_id=310 'Bezug: Robotikhardware.de 'Aufgabe: ' Gibt die Entfernung von Objekten in Zentimetern aus ' Die Messungen werden mit fest vorgegebenen Verstärkungsfaktor ' ermittelt 'Autor: Frank (Roboternetz) 'Weitere Beispiele und Beschreibung der Hardware 'unter http://www.Roboternetz.de oder robotikhardware.de '####################################################### Declare Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Declare Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Declare Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) Declare Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte $regfile = "m32def.dat" $crystal = 9216000 'Quarzfrequenz $baud = 19200 Config Scl = Portc.2 'Ports fuer IIC-Bus Config Sda = Portc.3 Config Pinc.0 = Output Config Servos = 1 , Servo1 = Portc.0 , Reload = 10 Enable Interrupts Dim Entfernung As Integer Servo(1) = 080 Wait 3 'Warte 3 Sekunden I2cinit Print "SRF10 Testprogramm " Print "SRF 10 Firmware Version:" ; Srf10_firmware(&He0) Srf10_reichweite &HE0 , 5000 'Reichweite in Zentimetern festlegen Srf10_verstaerkung &HE0 , 12 'Verstärkungsfaktor Do Servo(1) = 035 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Servo(1) = 080 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Servo(1) = 135 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Loop End Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Local Lob As Byte Local Hib As Byte Local Firmware As Byte Local Temp As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 'Messvorgang in starten I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 I2cwbyte 81 'in Zentimetern messen I2cstop Warteaufmessung: Waitms 1 Firmware = Srf10_firmware(&He0) If Firmware = 255 Then Goto Warteaufmessung I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Hib , Ack I2crbyte Lob , Nack I2cstop Srf10_entfernung = Makeint(lob , Hib) End Function 'Messreichweite in cm festlegen Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Local Wert As Word Local Temp As Byte Wert = Reichweite / 4 'Ungefähre Registerberechnung Temp = Low(wert) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Register I2cwbyte Temp I2cstop End Sub 'Verstärung festlegen Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 1 'Register I2cwbyte Srf10_verstaerkung I2cstop End Sub Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte Local Firmware As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Firmware , Nack I2cstop Srf10_firmware = Firmware End Function
Nun möchte ich aber einen seriellen Befehl vom PC in meinem Fall ein "t" schicken, um die Messung auszulösen. (der Code kommt unten) Jetzt fährt der Servo in die erste Position und die Portlämpchen für den SCL/SDA-Port in meinem fall c.2 und c.3 flackern. Schaut so aus als hätt sich der M32 aufgehangen. Wenn ich nun ein paar Knöpfe auf der Tastatur drück, hört das Leuchten auf und ich bekomm eine 0 vom SRF zurück. Der Servo fährt in die zweite Position und das Spiel beginnt von vorne, bis er alle drei Messungen hat. Hab die SDA-Leitung auch schon mit nem 10k-Pullupwiederstand versehen, allerdings bessert sich da leider nix. Sitz schon seit heute Mittag dran und find den Fehler einfach nicht.
Könntet ihr euch bitte meinen Code anschauen wo da der Wurm drinsteckt...
Hier der Code:
Hoff mir kann jemand helfenCode:Declare Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Declare Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Declare Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) Declare Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte $regfile = "m32def.dat" $crystal = 9216000 'Quarzfrequenz $baud = 19200 Config Scl = Portc.2 'Ports fuer IIC-Bus Config Sda = Portc.3 Config Pinc.0 = Output Config Pinc.1 = Output Config Servos = 2 , Servo1 = Portc.0 , Servo2 = Portc.1 , Reload = 10 Dim Entfernung As Integer Dim I As String * 1 Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Pwm1a = 0 Pwm1b = 0 Tccr1b = Tccr1b Or &H02 On Urxc Onrxd Enable Urxc Enable Interrupts Servo(1) = 080 I2cinit Wait 1 Print "SRF10 Testprogramm " Print "SRF 10 Firmware Version:" ; Srf10_firmware(&He0) Srf10_reichweite &HE0 , 5000 'Reichweite in Zentimetern festlegen Srf10_verstaerkung &HE0 , 12 'Verstärkungsfaktor Do Gosub Rs232abfrage 'Hauptschleife Wait 3 Loop End Function Srf10_entfernung(byval Srf10_slaveid As Byte) As Integer Local Lob As Byte Local Hib As Byte Local Firmware As Byte Local Temp As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 'Messvorgang in starten I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 I2cwbyte 81 'in Zentimetern messen I2cstop Warteaufmessung: Waitms 1 Firmware = Srf10_firmware(&He0) If Firmware = 255 Then Goto Warteaufmessung I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Hib , Ack I2crbyte Lob , Nack I2cstop Srf10_entfernung = Makeint(lob , Hib) End Function 'Messreichweite in cm festlegen Sub Srf10_reichweite(byval Srf10_slaveid As Byte , Byval Reichweite As Word) Local Wert As Word Local Temp As Byte Wert = Reichweite / 4 'Ungefähre Registerberechnung Temp = Low(wert) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 2 'Register I2cwbyte Temp I2cstop End Sub 'Verstärung festlegen Sub Srf10_verstaerkung(byval Srf10_slaveid As Byte , Byval Srf10_verstaerkung As Byte) I2cstart I2cwbyte Srf10_slaveid I2cwbyte 1 'Register I2cwbyte Srf10_verstaerkung I2cstop End Sub Function Srf10_firmware(byval Srf10_slaveid As Byte) As Byte Local Firmware As Byte Local Srf10_slaveid_read As Byte Srf10_slaveid_read = Srf10_slaveid + 1 I2cstart I2cwbyte Srf10_slaveid I2cwbyte 0 'Leseregister festlegen I2cstop I2cstart I2cwbyte Srf10_slaveid_read I2crbyte Firmware , Nack I2cstop Srf10_firmware = Firmware End Function Onrxd: I = I + Chr(udr) Return 'Testroutine Test: Servo(1) = 035 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Servo(1) = 080 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Servo(1) = 135 Wait 1 Entfernung = Srf10_entfernung(&He0) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Return Rs232abfrage: If Len(i) = 1 Then Select Case I Case "t" Gosub Test Case Else I = "" End Select Print "OK" I = "" End If Return![]()
Gruß







Zitieren

Lesezeichen