PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Kompassmodul am I2C Bus



alecs
12.07.2005, 13:15
Hallo ich habe ein Kompassmodul CMPS03 an mein RN-Control angeschlossen und ein kleines Testprogramm geschrieben, jedoch bekomm ich beim compilieren Fehler, welche ich mir nicht erklären kann:

Error1 - LINE 38 Unknown Statement [.EQU not found for: PORTC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: PORTC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: DDRC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: DDRC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: DDRC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: DDRC] in File
Error1 - LINE 38 Unknown Statement [.EQU not found for: PINC] in File
... usw...

Zeile 38 ist die letzte Zeile im Code... also das "END SUB"

kann mir jemand helfen ????

danke!




Declare Sub Kompass()

$crystal = 16000000 'Quarzfrequenz
$baud = 9600 'Baudrate für RS232

Dim Richtungint As Word 'Zwischenvariable für Kompassmessung cmps03
Dim Richtung As Single 'Richtung für Kompassmessung cmp03
Dim Lsb As Byte
Dim Msb As Byte


Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1

I2cinit 'I2C Initialisieren

'On Timer2 Interrupthandler 'Alle Interrups werden in dieser Routine behandelt

Do 'Endlosschleife
Call Kompass()
Waitms 200
Loop
End

Sub Kompass ()
I2cstart
I2cwbyte 192 'I2C Adresse C0
I2cwbyte 2 'Register 2 + 3
I2cstart
I2cwbyte 193 'Leseadresse (C1)
I2crbyte Msb , Ack
I2crbyte Lsb , Nack
I2cstop
Richtungint = Makeint(lsb , Msb) 'Word aus 2 Byte machen
' Richtung = Richtungint 'In Single zum Rechnen umwandeln
' Richtung = Richtung / 10 'Wert ist inkl. einer Nachkommastelle
Print "Richtung: " ; Richtungint
End Sub

pebisoft
12.07.2005, 13:57
probier den code einmal aus.
evtl musst du den avr noch ändern.
mfg pebisoft



Declare Sub Kom_werte(byval Ee_adresse As Byte)

$regfile = "m16def.dat"
$crystal = 16000000
$baud = 9600

Config Scl = Portc.0
Config Sda = Portc.1

Dim Kom_daten As Byte , Kom_temp As Byte
Dim Kom_ausgabe As Word
Dim Kom_adresse As Byte
Kom_adresse = 2

Do

Call Kom_werte(kom_adresse)
Print Kom_ausgabe
Waitms 200

Loop

End

Function Kom_werte(byval Ee_adresse As Byte)
Disable Interrupts
I2cstart
I2cwbyte &B11000000 , Ack
I2cwbyte Ee_adresse
Waitms 10
I2cstart
I2cwbyte &B11000001 , Ack
I2crbyte Kom_daten , Ack
I2crbyte Kom_temp , Nack
Kom_ausgabe = Kom_daten * 256
Kom_ausgabe = Kom_ausgabe + Kom_temp
I2cstop
Enable Interrupts
End Function

PicNick
12.07.2005, 14:38
@alecs: du mußt schauen, ob du den richtigen Prozessor für den Kompiler eingestellt hast.
Irgendeine Include (.Dat) file ?
er findet keine Definition für PORTC, DDRC und PINC
( er merkt, daß die Suche erfolglos ist, wenn er ganz hinten ist, daher die seltsame Zeilennummer)

michaelb
12.07.2005, 15:00
Hallo,
fehlt da nicht die Einbindung des dat Files? Und muss man Portc nicht als Output deklarieren? Oder reicht das wenn man I2C Ports deklariert?
Gruß Michi

alecs
12.07.2005, 16:59
Hey, danke für den Tip.

Genau eine Zeile fehlte mit : $regfile = "m32def.dat"

Hab ich total übersehen !!!

Mal sehen ob alles jetzt funktioniert wie ich es wollte ....


gruß Alecs

alecs
12.07.2005, 17:06
Also das Programm geht erst mal so weit, aber ich bekomme immer 65535 als Wert, egal wie ich den Kompass dreh :(

Weiß jemand warum bzw kann mir einen Tip geben `?

Danke

PicNick
12.07.2005, 17:33
Sub Kompass ()
I2cstart
I2cwbyte 192 'I2C Adresse C0
I2cwbyte 2 'Register 2 + 3
----------------------------- I2cstop --------------------
I2cstart
I2cwbyte 193 'Leseadresse (C1)
I2crbyte Msb , Ack
I2crbyte Lsb , Nack
I2cstop


Ich denk, da fehlt ein stop dazwischen

alecs
12.07.2005, 18:00
Hallo Robert,

leider brachte das stop keinen Erfolg der Wert 65535 bleibt einfacht stehen ...
nicht einmal eine geringe Abweichung ...

Was kann das sein ? Hab noch keine Erfahrung mit dem Sensor !!!

Gruß
Alecs