hmmm komisch........
eigentlich solte es jetzt funktionieren... er sollte direkt nacheinander in beide subs springen...
poste doch bitte mal deine jetzigen beiden programme...
bei mir funktiniert das so...
Druckbare Version
hmmm komisch........
eigentlich solte es jetzt funktionieren... er sollte direkt nacheinander in beide subs springen...
poste doch bitte mal deine jetzigen beiden programme...
bei mir funktiniert das so...
Komisch ist das schon weil egal was ich bei scl und sda eingebe er meldet immer master needs byte
Master:
Code:$regfile = "M32def.dat" ' the used chip
$crystal = 16000000 ' frequency used
$baud = 9600 ' baud rate
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name
I2cinit ' we need to set the pins in the proper state
Config Twi = 100000 ' wanted clock frequency
'will set TWBR and TWSR
'Twbr = 12 'bit rate register
'Twsr = 0 'pre scaler bits
Dim B As Byte , X As Byte
Print "TWI master"
B = 125
Do
' increase value
I2csend &H70 , B ' send the value
' show error
Waitms 500 'wait a bit
Loop
End
Slave:
Code:$regfile = "M32def.dat" ' the chip we use
$crystal = 16000000 ' crystal oscillator value
$baud = 9600 ' baud rate
Print "MCS Electronics TWI-slave demo"
Config Twislave = &H70 , Btr = 1 , Bitrate = 100000
' the code below #else is executed by the compiler when you use version 11175 or higher
'as you might need other interrupts as well, you need to enable them manual
Enable Interrupts
'this is just an empty loop but you could perform other tasks there
Do
nop
Loop
End
'A master can send or receive bytes.
'A master protocol can also send some bytes, then receive some bytes
'The master and slave must match.
'the following labels are called from the library
Twi_stop_rstart_received:
Print "Master sent stop or repeated start"
Return
Twi_addressed_goread:
Print "We were addressed and master will send data"
Return
Twi_addressed_gowrite:
Print "We were addressed and master will read data"
Return
'this label is called when the master sends data and the slave has received the byte
'the variable TWI holds the received value
Twi_gotdata:
Print "received : " ; Twi
Return
'this label is called when the master receives data and needs a byte
'the variable twi_btr is a byte variable that holds the index of the needed byte
'so when sending multiple bytes from an array, twi_btr can be used for the index
Twi_master_needs_byte:
Print "Master needs byte : " ; Twi_btr
Twi = 65 ' twi must be filled with a value
Return
'when the mast has all bytes received this label will be called
Twi_master_need_nomore_byte:
Print "Master does not need anymore bytes"
Return
ich habe gerade in meinen programmen geschaut und habe festgestellt das ich da die falschen pins für sda und scl definiert habe... anscheinend spielt es keine rolle was man da eingiebt... ;)
aber im moment sehe ich keine fehler mehr in deinen prog... sollte eigentlich funktionieren so... es hat ja bei mir auch funktioniert mit nem mega32 als master und nem mega8 als slave und auch umgekehrt...
vielleicht sieht hier noch jemand anderes einen fehler...
ist bei dir die verdrahtung in ordnung? hast 10k pullup's an den leitungen?
Ich hab den fehler.
ich habe die baudrate auf 19200 gestellt sont war sie immer auf 9600.
jetzt funktionierts.
warum weis ich aber auch nicht.
Danke für deine Hilfe und dass du so viel Gedult mit mir gehapt hast.
nur mit dem empfangen klapts noch nicht so ganz.
was?? aber das hat ja gar nichts mit dem i2c zu tun.... und die ausgabe auf den pc war ja ok?? komisch....
dank dir steige ich bald einen rang auf :)
Da sendet mir der master
TWI master
X113
X196
X136
X113
X113
X196
X136
X113
X113
X196
X136
X113
X113
X196
und der Slave
MCS Electronics TWI-slave demo
We were addressed and master will read data
Master needs byte : 1
We were addressed and master will read data
Master needs byte : 1
We were addressed and master will read data
Master needs byte : 1
und das steht im Masterprogramm:
Code:Do
' increase value
I2creceive &H71 , X ' send the value
Print "X" ; X
' show error
Waitms 500 'wait a bit
Loop
End
fehlt da nich noch eine sub mit sent oder so. weil received gibts ja auch
das sieht doch schonmal nicht schlecht aus... was übergibst du den der twi variabel im slave?
das senden vom master aus klapt? hast du den beitrag oben von mir gesehen wegen der pullup's?
Ja die Pullups hab ich. jeweils einen 10k an scl und sda.
die verkabelung muss ja passen da das senden vom master ja super funktioniert.
im slave steht
Twi_master_needs_byte:
Print "Master needs byte : " ; Twi_btr
Twi = 65
' twi must be filled with a value
Return
komisch sind die zahlen die du im master bekommst eigentlich sollte er ja 65 zurückbekommen...
ach mal weiter oben im code:
dim b as byte
b=65
und dann in der sub twi=b
dann soltest du beim master x65 erhalten... wenn nicht kann ich im moment auch nicht sagen wiso...