Hi Leute,

Ich habe ein kleines Problem, wo ich nicht wirklich weiter komme. Ich
möchte gerne Daten aus zwei externen EEproms lesen. Die Daten
werden vorher mittels Ponyprog auf die EEproms geschrieben und
danach nicht mehr verändert. Ich muß zwei EEproms nehmen, da die
größten, die ich kenne, nur 512KBit haben und da reicht leider einer
nicht ;o))

Mit einem EEprom bekomme ich es problemlos hin. Nur wie mache
ich es (ohne den ganzen Code einfach nur zu duplizieren!) mit zwei
EEproms?? Hier mal der Code, soweit ich ihn fertig habe:

Code:
$regfile = "m128def.DAT"
$crystal = 16000000
$baud = 19200
$hwstack = 50
$swstack = 50
$framesize = 40

$lib "I2C_TWI.LBX"                                                              'Setting up I2C hardware bus
Config Twi = 400000                                                             'Hardware I2C bus speed
Config Scl = Portd.0                                                            'TWI (i2c) ports on the Mega128
Config Sda = Portd.1
'EEproms are adressed as: &B 1010 A2(0) A1 A0 R/W
Const Eeprom1w = &B10100000                                                     'slave write address eeprom
Const EEprom1r = &B10100001                                                     'slave read address eeprom

Const Eeprom2w = &B10100100                                                     'slave write address Eeprom #2
Const Eeprom2r = &B10100101                                                     'slave read address Eeprom  #2



'==== Declaration
Declare Sub Read_eeprom_word(byval Adress As Word , Valueword As Word)
Declare Sub Read_eeprom_index

Dim Samples As Word , Start_byte(10) As Word , Lenght(10) As Word             
Dim Bytetodo As Word , Outbyte As Byte
Dim Temp As Byte , Tempw As Word , Lus As Byte
Dim Bitcount As Byte , Tempadress2 As Byte

'=== Main ===
Read_eeprom_index                                                               'Read eeprom index
Print Samples ; " Samples present in the eeprom"
For Lus = 1 To Samples
Print Lus ; "sample start at eeprom adress: &H" ; Hex(start_byte(lus)) ; " is &H" ; Hex(lenght(lus)) ; " bytes long."
Next For
Wait 3
End



'=== Sub routines ===
Sub Read_eeprom_index                                                           'Find the start adresse 
      Read_eeprom_word 0 , Samples                                              '1e Byte in the eeprom contains the number of samples 
      Temp = Low(samples) : Temp = Temp -1                  '
      For Lus = 0 To Temp                                                       'Loop the number of Samples found
          Tempw = Lus * 2                                                       'Reading words, so steps 2
          Read_eeprom_word Tempw , Start_byte(lus + 1)                          'Read the start adres of the samples
          Tempw = Start_byte(lus + 1)
          Tempw = Tempw * 2                                                     'Reading words, so steps 2
          Read_eeprom_word Tempw , Lenght(lus + 1)                              'Read the lenght of the sample from the eeprom
          Rotate Lenght(lus + 1) , Left , 8                                     'Msb and Lsb are inverted so swap them
      Next Lus
End Sub

Sub Read_eeprom_word(byval Adress As Word , Valueword As Word)
   Local Tempadress As Byte , Valueh As Byte , Valuel As Byte,
   I2cstart                                                                     'generate start
   I2cwbyte EEprom1w                                                            'slave adsress
   Tempadress = High(adress)
   I2cwbyte Tempadress                                                          'highbyte adress of EEPROM
   Tempadress = Low(adress)
   I2cwbyte Tempadress                                                          'lowbyte adress of EEPROM
   I2cstart                                                                     'repeated start
   I2cwbyte EEprom1r                                                            'slave address (read)
   I2crbyte Valuel , Ack                                                        'read byte
   I2crbyte Valueh , Nack
   I2cstop                                                                      'generate stop
   Valueword = Makeint(valuel , Valueh)
End Sub
Problem: Ich weiß nicht unbedingt, ob die Daten EEProm übergreifend
geschrieben wurden (Problem könnte man erledigen in dem man es
beim schreiben der EEProm Daten verhindert) und ich weiß nicht, wieviele
Samples insgesamt vorhanden sind.

Wäre nett, wenn mir jemand zeigen könnte, wie ich die Daten aus EEprom
#2 ( Also Eeprom2w & Eeprom2r) ebenfalls im gleichen Zuge auslesen
könnte. Den Code aus den Subs Read_eeprom_index &
Read_eeprom_word einfach nur zu duplizieren (mit den Adressen des
Eeproms #2) kann ich wahrscheinlich nicht, da ich u.a. nicht genug Platz
auf dem endgültigen Atmel (Mega habe.

viele internette Grüße,
Reinhard