Static
26.05.2005, 22:26
Hallo, ich habe ein RN-Control Board mit einem Mega 32 drauf. Da der interne Ram nicht ausreicht habe ich noch einen 24LC64 eeprom an den I²C Bus angeschlossen. Ich habe direkt diesen Stecker auf dem Board benutzt, da kann ich mir doch die Pull-Up Widerstände sparen, oder? Die Adress Anschlüsse des e²proms hab ich direkt auf GND gelegt.
Mein Programm in Bascom, zum testen sieht so aus:
$regfile = "m32def.dat"
$crystal = 7372800 'Quarzfrequenz
$baud = 9600
Enable Interrupts
Config Portc = Output
Config Sda = Portc.1
Config Scl = Portc.0
Print "EE - Test"
Waitms 500
Declare Sub Write_eeprom(byval Adres As Word , Byval Value As Byte)
Declare Sub Read_eeprom(byval Adres As Word , Value As Byte)
Const Addressw = 160 'slave write address
Const Addressr = 161 'slave read address
Dim I As Word
Dim B1 As Byte , Adres As Word , Value As Byte
Dim Temp As Byte , Temp2 As Byte
Print "schreibe"
For I = 1 To 100
Value = I
Print I
Call Write_eeprom(i , Value)
Next I
End
Waitms 200
Print "lese"
I = 1
For I = 1 To 100
Value = 0
Call Read_eeprom(i , Value)
Print I ; "= " ; Value ; " ";
Waitms 20
Next I
End
Print "fertig"
Sub Write_eeprom(byval Adres Word , Byval Value As Byte)
Temp = High(adres)
Temp2 = Low(adres)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Temp 'asdress of EEPROM
I2cwbyte Temp2
I2cwbyte Value 'value to write
I2cstop 'stop condition
Waitms 10 'wait for 10 milliseconds
End Sub
Sub Read_eeprom(byval Adres Word , Value As Byte)
Temp = High(adres)
Temp2 = Low(adres)
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Temp
I2cwbyte Temp2 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Value , Nack 'read byte
I2cstop 'generate stop
Waitms 10
End Sub
Das funktioniert bloß leider nicht, nach dem schreibvorgang passiert nichts mehr. Die Ports für SDA und SCL sind doch richtig, oder? Woran kann es sonst liegen?
Mein Programm in Bascom, zum testen sieht so aus:
$regfile = "m32def.dat"
$crystal = 7372800 'Quarzfrequenz
$baud = 9600
Enable Interrupts
Config Portc = Output
Config Sda = Portc.1
Config Scl = Portc.0
Print "EE - Test"
Waitms 500
Declare Sub Write_eeprom(byval Adres As Word , Byval Value As Byte)
Declare Sub Read_eeprom(byval Adres As Word , Value As Byte)
Const Addressw = 160 'slave write address
Const Addressr = 161 'slave read address
Dim I As Word
Dim B1 As Byte , Adres As Word , Value As Byte
Dim Temp As Byte , Temp2 As Byte
Print "schreibe"
For I = 1 To 100
Value = I
Print I
Call Write_eeprom(i , Value)
Next I
End
Waitms 200
Print "lese"
I = 1
For I = 1 To 100
Value = 0
Call Read_eeprom(i , Value)
Print I ; "= " ; Value ; " ";
Waitms 20
Next I
End
Print "fertig"
Sub Write_eeprom(byval Adres Word , Byval Value As Byte)
Temp = High(adres)
Temp2 = Low(adres)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Temp 'asdress of EEPROM
I2cwbyte Temp2
I2cwbyte Value 'value to write
I2cstop 'stop condition
Waitms 10 'wait for 10 milliseconds
End Sub
Sub Read_eeprom(byval Adres Word , Value As Byte)
Temp = High(adres)
Temp2 = Low(adres)
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Temp
I2cwbyte Temp2 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Value , Nack 'read byte
I2cstop 'generate stop
Waitms 10
End Sub
Das funktioniert bloß leider nicht, nach dem schreibvorgang passiert nichts mehr. Die Ports für SDA und SCL sind doch richtig, oder? Woran kann es sonst liegen?