My Testprogram for a I2C transfer in to a ST 24C256 EEPROM would not work as expected but I c'ant find the failure in the program
Any help is very apreciated.
Walter
This is my samplecode:
'=====================================================================
' I2C EEProm Test 2
'
' 12.08.2014 / V 1
'=====================================================================
$regfile = "m644pdef.dat" ' specify the used micro
$crystal = 20000000
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
$baud = 9600
Config Lcdbus = 4
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Config Lcd = 20 * 4
Cursor Off 'LCD Cursor OFF
'-------I2C config ------------------------------------------------------
'Config Portd.2 = Input 'Interruptanschluss INT0
Config Scl = Portd.6 ' I2C Clock.
Config Sda = Portd.7 ' I2C Data.
$lib "I2C.LBX"
Config I2cdelay = 10 ' I2C Taktfrequenz 100kHz
'___________________________________________
' ==========================================
Dim X As Byte
Dim A As Word
Dim B As Word
Dim Schreiben As Byte
Dim Lesen As Byte
Dim Adresse As Word At $160 'Die Adresse als Word-Variable
Dim Low_adresse As Byte At $160 Overlay 'Zeiger auf das erste Byte
Dim High_adresse As Byte At $161 Overlay 'Zeiger auf das zweite Byte
'===================Hauptprogramm===============================================
Do
'----schreiben----
For Adresse = 250 To 260 'Adresse geht über die Byte-Grenze
Incr X '1 bis Überlauf
I2cstart 'Start
I2cwbyte &HA0 'Sende Slavadresse
I2cwbyte High_adresse 'Sende Speicheradresse High
I2cwbyte Low_adresse 'Sende Speicheradresse LOW
I2cwbyte X 'Sende Wert
I2cstop 'stop
Waitms 10
Locate 1 , 1
Lcd "->Adres.=" ; Adresse ; "Wert=" ; X ; " " 'Anzeige vom schreiben
Waitms 500
Next Adresse
'---lesen----
For Adresse = 250 To 260
I2cstart 'Start
I2cwbyte &HA0 'Sende Slavadresse +1 für Schreiben
I2cwbyte High_adresse 'Sende Speicheradresse High
I2cwbyte Low_adresse 'Sende Speicheradresse Low
I2cstart 'Start
I2cwbyte &HA1 'Sende Slavadresse +1 für Lesen
I2crbyte Lesen , Nack 'Lese Adresse vom EEprom
I2cstop 'Stop
Locate 2 , 1
Lcd "<-Adres.=" ; Adresse ; "Wert=" ; Lesen ; " " 'Anzeige vom lesen
Waitms 500
Next Adresse
Loop
End
[b:c24030814f][color=red:c24030814f](BASCOM-AVR version : 2.0.7.7 )[/b:c24030814f][/color:c24030814f]
↧