Forum: Mikrocontroller und Digitale Elektronik Bascom mit I2C Speicher


von Ralf K. (Gast)


Lesenswert?

Hi,
möchte ca. 30kB XRam an einem ATMega16 über I2C Bus mit Bascom
ansprechen.
Es sollen regelmässig Messwerte gespeichert werden, doch dafür reichen
die vorhandenen 1kB SRam hinten und vorne nicht :-(
Habe in meinem Bascom Buch gelesen, es können nur maximal 16kBit
angesprochen werden.
Möchte z.b. einen ST 24C256 verwenden.

Wer hat damit Erfahrung bzw. einen Tip wie es geht???

Im voraus schönen Dank

Wünsche allen ein frohes Fest

Ralf

von Marko (Gast)


Lesenswert?

Declare Sub Write_eeprom(byval Adresh As Byte , Byval Adresl As Byte ,
Byval Value As Byte)
Declare Sub Read_eeprom(byval Adresh As Byte , Byval Adresl As Byte ,
Value As Byte)

' Adresse erzeugen:
' Pin A0 und A1 sind intern mit Pulldowns versehen, sind also
' wenn extern nicht beschaltet 0
' Die Der Baustein halt serienmäßig die Adresse Binär:
' 1 0 1 0 0 A1 A0 R/W
' also, angenommen man möcht bei A0 = 0 und A1=0 schreiben:
' Adresse: 10100000 = 160
' Lesen Adresse: 10100001 = 161
'
' der 24c128 und 24c256 brauchen für die Adressierung 2 Byte
' Den High-Byte der Adresse und den Lowbyte der Adresse.
' Einfach, da die soviel Speicher habn :o)

Const Addressw = 160                                        'slave
write address
Const Addressr = 161                                        'slave
read address

Dim B1 As Byte
Dim Value As Byte                                           'dim byte
Dim Adresh As Byte                                          'Highbyte
der Adresse
Dim Adresl As Byte                                          'Lowbyte
der Adresse
Dim A As Byte
'allgemeine Variable für Berechnungen

For A = 1 To 5                                              ' die
ersten 5 Byte schreiben
   Value = A + 100                                          'Beginnend
mit Zahlenwert 105 um Verwechslungen zu vermeiden
   Call Write_eeprom(1 , A , Value)                         'Daten
schreiben
Next A

For A = 1 To 5                                              'die
geschriebenen 5 Byte auslesen
   Call Read_eeprom(1 , A , Value)                          'auslesen
   Print Value                                              'Ausgabe
an UART
Next A


'sample of writing a byte to EEPROM AT2404
Sub Write_eeprom(byval Adresh As Byte , Adresl As Byte , Value As
Byte)
    I2cstart                                                'start
condition
    I2cwbyte Addressw                                       'slave
address
    I2cwbyte Adresh                                         'asdress H
of EEPROM
    I2cwbyte Adresl                                         'asdress L
of EEPROM
    I2cwbyte Value                                          'value to
write
    I2cstop                                                 'stop
condition
    Waitms 10                                               'wait for
10 milliseconds
End Sub


'sample of reading a byte from EEPROM AT2404
Sub Read_eeprom(byval Adresh As Byte , Adresl As Byte , Value As Byte)
   I2cstart                                                 'generate
start
   I2cwbyte Addressw                                        'slave
adsress
   I2cwbyte Adresh                                          'asdress H
of EEPROM
   I2cwbyte Adresl                                          'asdress L
of EEPROM
   I2cstart                                                 'repeated
start
   I2cwbyte Addressr                                        'slave
address (read)
   I2crbyte Value , Nack                                    'read
byte
   I2cstop                                                  'generate
stop
End Sub


' when you want to control a chip with a larger memory like the 24c64
it requires an additional byte
' to be sent (consult the datasheet):
' Wires from the I2C address that are not connected will default to 0
in most cases!

'   I2cstart                                                'start
condition
'   I2cwbyte &B1010_0000                                    'slave
address
'   I2cwbyte H                                              'high
address
'   I2cwbyte L                                              'low
address
'   I2cwbyte Value                                          'value to
write
'   I2cstop                                                 'stop
condition
'   Waitms 10

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.