Es gelingt mir einfach nicht, das IC PCF8574 (8Bit I/O Fern-Expander für den I2C-Bus) mit Hilfe der I2C Special mode function des IOWarrior40 und AppleScript anzusteuern. Ich erhalte nur folgende Fehlermeldungen: {2,-128,0,0,0,0,0} und {3,-128,0,0,0,0,0}; -128 entspricht 128, d.h. 10000000 im Dualsystem und bit 7 liegt damit auf 1.
Hier das Apple-Script:
tell application "IOWarriorAppleScriptGateway"
-- I2C-Bus aktivieren
WriteInterface1 reportId 1 byte0 1
-- Start und Stopp und Anzahl der übermittelnden Bytes angeben 1*2^7 + 1*2^6 +0*2^2 + 0*2^1 + 1* 2^0 = 193
-- PCF8574P hat die Adresse 64
WriteInterface1 reportId 2 byte0 193 byte1 64
-- Daten senden, byte0 gibt die Anzahl der übertr. bytes an, byte1 gibt das Kommando an
-- 133 entspricht der Ziffer 5 auf der 7Seg-Anzeige, 255-(Bit3 + Bit6 + Bit4 + Bit1 + Bit5)=255-(8+64+16+2+32)=133
WriteInterface1 reportId 3 byte0 1 byte1 133
-- Daten lesen
ReadInterface1 reportId 3
end tell
Was mache ich falsch?
I2C (IIC,I^2C) - Bus, PCF8574 (8Bit I/O) und AppleScript
Moderator: Guido Körber
-
- Site Admin
- Posts: 2876
- Joined: Tue Nov 25, 2003 10:25 pm
- Location: Germany/Berlin
- Contact:
Also die Rückmeldung sagt, dass nicht mal das Adressbyte bei der Gegenstelle angekommen ist.
Kann es sein, dass die Adresse 64 als 7 Bit Darstellung spezifiziert ist? Das wird bei IIC manchmal gemacht und verwirrt dann schön, weil am unteren Ende das Read/Write Bit angehängt werden muss und damit die Adresse natürlich um ein Bit hochrutscht, in diesem Falle also 128 wäre.
Kann es sein, dass die Adresse 64 als 7 Bit Darstellung spezifiziert ist? Das wird bei IIC manchmal gemacht und verwirrt dann schön, weil am unteren Ende das Read/Write Bit angehängt werden muss und damit die Adresse natürlich um ein Bit hochrutscht, in diesem Falle also 128 wäre.
I2C (IIC,I^2C) - Bus, PCF8574 (8Bit I/O) und AppleScript
Vielen Dank für die sehr schnelle Rückmeldung! Sie haben völlig recht, dass das IC PCF8574 nicht angesprochen wird. Bei meinen vielen erfolglosen Versuchen hatte ich zum Schluss alle Adressbits auf 1 gesetzt, so dass die Adresse nun 78 lautet und nicht mehr 64, und dieses habe ich dann völlig vergessen. Blöder Fehler! Nun bekomme ich die Rückmeldung: {2,1,0,0,0,0,0} und {3,-128,0,0,0,0,0}. Das IC wird also erkannt. Muss ich den Fehler bei "WriteInterface1 reportId 3 byte0 1 byte1 133" suchen?
I2C (IIC,I^2C) - Bus, PCF8574 (8Bit I/O) und AppleScript
Nachtrag:
WriteInterface1 reportId 3 byte0 1 byte1 64 ergibt keine Fehlermeldung sondern {3,1,-1,0,0,0,0} als Antwort. -1 bedeutet 255 und damit 11111111 im Dualsystem. Alle Pins P0 bis P7 liegen beim IC auf 5V. Die 7Segmentanzeige ist dunkel. Dies ist korrekt.
WriteInterface1 reportId 3 byte0 1 byte1 65 ergibt ebenfalls keine Fehlermeldung sondern {3,1,64,0,0,0,0} als Antwort. 64 ergibt 01000000 im Dualsystem.
Pin P6 liegt auch wirklich auf 5V, alle anderen auf ca 0,4V. Die 7Segmentanzeige zeit ein "ei"
Alle anderen Werte - außer 64 und 65 - ergeben eine Fehlermeldung.
WriteInterface1 reportId 3 byte0 1 byte1 64 ergibt keine Fehlermeldung sondern {3,1,-1,0,0,0,0} als Antwort. -1 bedeutet 255 und damit 11111111 im Dualsystem. Alle Pins P0 bis P7 liegen beim IC auf 5V. Die 7Segmentanzeige ist dunkel. Dies ist korrekt.
WriteInterface1 reportId 3 byte0 1 byte1 65 ergibt ebenfalls keine Fehlermeldung sondern {3,1,64,0,0,0,0} als Antwort. 64 ergibt 01000000 im Dualsystem.
Pin P6 liegt auch wirklich auf 5V, alle anderen auf ca 0,4V. Die 7Segmentanzeige zeit ein "ei"
Alle anderen Werte - außer 64 und 65 - ergeben eine Fehlermeldung.
-
- Site Admin
- Posts: 2876
- Joined: Tue Nov 25, 2003 10:25 pm
- Location: Germany/Berlin
- Contact:
I2C (IIC,I^2C) - Bus, PCF8574 (8Bit I/O) und AppleScript
Fehler gefunden! Schreiben und Lesen klappen jetzt! Vielen Dank für die Anregung!
tell application "IOWarriorAppleScriptGateway"
set result to IsIOWarriorPresent
if result is equal to false then
display dialog "IOWarrior not present"
return
end if
-- I2C-Bus aktivieren
WriteInterface1 reportId 1 byte0 1
-- Start (1*2^7) und Stopp (1*2^6) und ByteAnzahl (2) ergeben: 1*2^7 + 1*2^6 +0*2^2 + 1*2^1 + 0* 2^0 = 194
-- PCF8574P hat die Basisschreibadresse 64, PCF8574AP 112 und PCF8591P 144
-- 133 entspricht der Ziffer 5 auf der 7Seg.Anzeige: 255-(Bit3 + Bit6 + Bit4 + Bit1 + Bit5)=255-(8+64+16+2+32)=133
-- WriteInterface1 reportId2 byte0 <Start+Stopp+ByteAnzahl> byte1 <Schreibadresse> byte2 <Ziffercode>
WriteInterface1 reportId 2 byte0 194 byte1 64 byte2 133
-- Auslesen
-- WriteInterface1 reportId 3 byte0 <ByteAnzahl> byte1 <Leseadresse>
WriteInterface1 reportId 3 byte0 1 byte1 65
-- Rückmeldung
ReadInterface1 reportId 3
-- ergibt {3,1,-123,0,0,0,0}, -123 bedeutet 256 - 123 = 133
end tell
tell application "IOWarriorAppleScriptGateway"
set result to IsIOWarriorPresent
if result is equal to false then
display dialog "IOWarrior not present"
return
end if
-- I2C-Bus aktivieren
WriteInterface1 reportId 1 byte0 1
-- Start (1*2^7) und Stopp (1*2^6) und ByteAnzahl (2) ergeben: 1*2^7 + 1*2^6 +0*2^2 + 1*2^1 + 0* 2^0 = 194
-- PCF8574P hat die Basisschreibadresse 64, PCF8574AP 112 und PCF8591P 144
-- 133 entspricht der Ziffer 5 auf der 7Seg.Anzeige: 255-(Bit3 + Bit6 + Bit4 + Bit1 + Bit5)=255-(8+64+16+2+32)=133
-- WriteInterface1 reportId2 byte0 <Start+Stopp+ByteAnzahl> byte1 <Schreibadresse> byte2 <Ziffercode>
WriteInterface1 reportId 2 byte0 194 byte1 64 byte2 133
-- Auslesen
-- WriteInterface1 reportId 3 byte0 <ByteAnzahl> byte1 <Leseadresse>
WriteInterface1 reportId 3 byte0 1 byte1 65
-- Rückmeldung
ReadInterface1 reportId 3
-- ergibt {3,1,-123,0,0,0,0}, -123 bedeutet 256 - 123 = 133
end tell
Re: I2C (IIC,I^2C) - Bus, PCF8574 (8Bit I/O) und AppleScrip
Hallo Forum,
bitte sagt mir, warum ich beim Lesen meines <USB to I2C Dongle> nur eine leere Rückmeldung bekomme.
Meine Hardware scheint korrekt aufgebaut, am I2C-Bus sind zwei Pull-Up Widerstände mit 50k und ein PCF8574AP angeschlossen. An drei Pins des PCF sind LEDs nach 5V, an weiteren drei Pins Taster nach GND angeschlossen. Die Ansteuerung der LEDs klappt, auch mehrmals hintereinander. Hier der AS-Code und sein Event-Protokoll:
(* 26. März 2010, 22 Uhr *)
(* Konstanten: *)
set Schreibadresse_PCF8574AP to 112 as number
set Leseadresse_PCF8574AP to Schreibadresse_PCF8574AP + 1
set roteLED to 2 ^ 7 as number
set gelbeLED to 2 ^ 6 as number
set grueneLED to 2 ^ 5 as number
(* Variablen: *)
set Dongle_fehlt to "<USB to I2C Dongle> nicht angeschlossen!"
set StartUndStoppUnd2Bytes to 194 as number
(* Code: *)
tell application "IOWarriorAppleScriptGateway"
activate
if not (IsIOWarriorPresent) then
display dialog Dongle_fehlt
quit application "IOWarriorAppleScriptGateway"
else
WriteInterface1 reportId 1 byte0 1 -- I2C-Bus aktivieren
WriteInterface1 reportId 2 byte0 StartUndStoppUnd2Bytes byte1 Schreibadresse_PCF8574AP byte2 (255 - grueneLED) --Tastaturpins auf HIGH, grüne LED an.
ReadInterface1 reportId 2
WriteInterface1 reportId 3 byte0 1 byte1 Leseadresse_PCF8574AP -- byte0 <ByteAnzahl> byte1 <Leseadresse>
ReadInterface1 reportId 3
end if
end tell
quit application "IOWarriorAppleScriptGateway"
-------Event-Protokoll: --------------------------
tell application "IOWarriorAppleScriptGateway"
activate
IsIOWarriorPresent current application
true
WriteInterface1 current application reportId 1 byte0 1
0
WriteInterface1 current application reportId 2 byte0 194 byte1 112 byte2 223.0
0
ReadInterface1 current application reportId 2
{}
WriteInterface1 current application reportId 3 byte0 1 byte1 113
0
ReadInterface1 current application reportId 3
{}
quit current application
end tell
Nachtrag: Datenein- und ausgabe mittels IOWarriorSimpleI2C klappt hervorragend. Es muss also ein Softwarefehler in meinem Code sein.
bitte sagt mir, warum ich beim Lesen meines <USB to I2C Dongle> nur eine leere Rückmeldung bekomme.
Meine Hardware scheint korrekt aufgebaut, am I2C-Bus sind zwei Pull-Up Widerstände mit 50k und ein PCF8574AP angeschlossen. An drei Pins des PCF sind LEDs nach 5V, an weiteren drei Pins Taster nach GND angeschlossen. Die Ansteuerung der LEDs klappt, auch mehrmals hintereinander. Hier der AS-Code und sein Event-Protokoll:
(* 26. März 2010, 22 Uhr *)
(* Konstanten: *)
set Schreibadresse_PCF8574AP to 112 as number
set Leseadresse_PCF8574AP to Schreibadresse_PCF8574AP + 1
set roteLED to 2 ^ 7 as number
set gelbeLED to 2 ^ 6 as number
set grueneLED to 2 ^ 5 as number
(* Variablen: *)
set Dongle_fehlt to "<USB to I2C Dongle> nicht angeschlossen!"
set StartUndStoppUnd2Bytes to 194 as number
(* Code: *)
tell application "IOWarriorAppleScriptGateway"
activate
if not (IsIOWarriorPresent) then
display dialog Dongle_fehlt
quit application "IOWarriorAppleScriptGateway"
else
WriteInterface1 reportId 1 byte0 1 -- I2C-Bus aktivieren
WriteInterface1 reportId 2 byte0 StartUndStoppUnd2Bytes byte1 Schreibadresse_PCF8574AP byte2 (255 - grueneLED) --Tastaturpins auf HIGH, grüne LED an.
ReadInterface1 reportId 2
WriteInterface1 reportId 3 byte0 1 byte1 Leseadresse_PCF8574AP -- byte0 <ByteAnzahl> byte1 <Leseadresse>
ReadInterface1 reportId 3
end if
end tell
quit application "IOWarriorAppleScriptGateway"
-------Event-Protokoll: --------------------------
tell application "IOWarriorAppleScriptGateway"
activate
IsIOWarriorPresent current application
true
WriteInterface1 current application reportId 1 byte0 1
0
WriteInterface1 current application reportId 2 byte0 194 byte1 112 byte2 223.0
0
ReadInterface1 current application reportId 2
{}
WriteInterface1 current application reportId 3 byte0 1 byte1 113
0
ReadInterface1 current application reportId 3
{}
quit current application
end tell
Nachtrag: Datenein- und ausgabe mittels IOWarriorSimpleI2C klappt hervorragend. Es muss also ein Softwarefehler in meinem Code sein.