PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : AT24C08 Schreiben und Lesen



Ripper121
13.12.2010, 22:09
Habe ein AT24C08 EEPROM
das beispiel von Bascom funz auch

Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte)

Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte)



Const Addressw = 174 'slave write address

Const Addressr = 175 'slave read address



Dim B1 As Byte , Adres As Byte , Value As Byte , I As Byte 'dim byte


For I = 0 To 255
Cls
Locate 1 , 1
Call Write_eeprom(i , I) : Lcd "Write:" ; I 'write value of three to address 1 of EEPROM
Locate 2 , 1
Call Read_eeprom(i , Value) : Lcd "Read:" ; Value
Waitms 50
Next



'-------- now write to a PCF8474 I/O expander -------

I2csend &H40 , 255 'all outputs high

I2creceive &H40 , B1 'retrieve input

Print "Received data " ; B1 'print it

End



Rem Note That The Slaveaddress Is Adjusted Automaticly With I2csend & I2creceive

Rem This Means You Can Specify The Baseaddress Of The Chip.









'sample of writing a byte to EEPROM AT2404

Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte)

I2cstart 'start condition

I2cwbyte Addressw 'slave address

I2cwbyte Adres 'asdress 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 Adres As Byte , Value As Byte)

I2cstart 'generate start

I2cwbyte Addressw 'slave adsress

I2cwbyte Adres 'address of EEPROM

I2cstart 'repeated start

I2cwbyte Addressr 'slave address (read)

I2crbyte Value , Nack 'read byte

I2cstop 'generate stop

End Sub

Aber hier kann ich ja nur ein Byte schreiben also 0-255.
Wie kann ich den ganzen EEPROM von 8KByte nutzen?

Jaecko
14.12.2010, 18:58
Zuerst mal: Der 24C08 ist kein 8kByte-Speicher!
Es sind 8kBit => 1024 Byte = 1kByte.

Bei mehr als 256 Byte braucht man dann zur Adressierung im EEPROM ein 2. Adressbyte.
Also etwa so:


I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte AdresH 'adress of EEPROM (High)
I2cwbyte AdresL 'adress of EEPROM (Low)
I2cwbyte Value 'value to write
I2cstop 'stop condition

Ripper121
14.12.2010, 21:13
und wie geht das jetzt wie bekomme ich die adressen raus?

bluelight_electronic
14.12.2010, 21:36
heyho,

ich nutz zwar kein basecom aber das ist überall gleich.

Du musst wissen was du speichern willst und dann sagst du auch wo du es haben magst.
Heißt du musst dir selbst eine "Verwaltung" aufbauen, es sei denn du willst linear daten einfach speichern und wieder lesen.


willst du aber nur ein paar werte abspeichern bzw immer wieder das selbe (z.b. 100byte) joar dann weißt du ja auch wieder wo was liegt..

hoffe ich konnte dir helfen
gruß,
Manuel