Hallo Andreas,
so läufts bei mir....
der AT24c512 hat ein festes Byte für Hardware Adresse
(nur das R/W-Bit ist variabel),
dann folgen 2Byte mit der eigentlichen Speicheradresse
die Speicheradresse musst du als word-Variable hochzählen (hier +16)
abhänig wieviele Bytes hintereinander geschrieben bzw. gelesen werden
Code:'## Datenspeicher AT24c512 A1 und A0 auf +5V !! Hardware Adresse Const Chip_w = &B10100110 'schreiben Const Chip_r = &B10100111 'lesen Dim Ebuffer(16) As Byte Dim I As Word 'Pointer counter Dim X As Word Dim Adr As Word Dim Eepromadr As Word '......... Declare Sub Schreibe_block(byval St_adr As Word) Declare Sub Lese_block(byval St_adr As Word) '........ '********************************************************************** '** Define Subroutines ** '********************************************************************** 'Schreib 16 Byte aus dem ebuffer in EEPROM Sub Schreibe_block(st_adr As Word ) ' Local Adr_low As Byte Local Adr_high As Byte Adr_low = Low(st_adr) ' Extract low byte of address to be written. Adr_high = High(st_adr) ' Extract high byte of addesss to be written. I2cstart ' Send I2C Start. I2cwbyte Chip_w ' EEPROM device type, address and write bit. I2cwbyte Adr_high ' Send high address to write to. I2cwbyte Adr_low ' Send low address to write to. I2cwbyte Ebuffer(1) ': Print Ebuffer(1) --> nur zum debuggen I2cwbyte Ebuffer(2) ': Print Ebuffer(2) I2cwbyte Ebuffer(3) ': Print Ebuffer(3) I2cwbyte Ebuffer(4) ': Print Ebuffer(4) I2cwbyte Ebuffer(5) ': Print Ebuffer(5) I2cwbyte Ebuffer(6) ': Print Ebuffer(6) I2cwbyte Ebuffer(7) ': Print Ebuffer(7) I2cwbyte Ebuffer(8) ': Print Ebuffer(8) I2cwbyte Ebuffer(9) ': Print Ebuffer(9) I2cwbyte Ebuffer(10) ': Print Ebuffer(10) I2cwbyte Ebuffer(11) ': Print Ebuffer(11) I2cwbyte Ebuffer(12) ': Print Ebuffer(12) I2cwbyte Ebuffer(13) ': Print Ebuffer(13) I2cwbyte Ebuffer(14) ': Print Ebuffer(14) I2cwbyte Ebuffer(15) ': Print Ebuffer(15) I2cwbyte Ebuffer(16) ': Print Ebuffer(16) I2cstop 'Waitms 10 End Sub 'lese 16 Byte in den ebuffer Sub Lese_block(st_adr As Word) Local Adr_low As Byte Local Adr_high As Byte Adr_low = Low(st_adr) ' Extract low byte of address to be written. Adr_high = High(st_adr) ' Extract high byte of addesss to be written. I2cstart ' Send I2C Start. I2cwbyte Chip_w ' EEPROM device type, address and write bit. I2cwbyte Adr_high ' Send high address to write to. I2cwbyte Adr_low I2cstart ' Issue another start sequence. I2cwbyte Chip_r ' Select MicroChip EEPROM device type, address and read bit I2crbyte Ebuffer(1) , Ack ' Read data from desired location in chip. I2crbyte Ebuffer(2) , Ack I2crbyte Ebuffer(3) , Ack I2crbyte Ebuffer(4) , Ack I2crbyte Ebuffer(5) , Ack I2crbyte Ebuffer(6) , Ack I2crbyte Ebuffer(7) , Ack I2crbyte Ebuffer(8) , Ack I2crbyte Ebuffer(9) , Ack I2crbyte Ebuffer(10) , Ack I2crbyte Ebuffer(11) , Ack I2crbyte Ebuffer(12) , Ack I2crbyte Ebuffer(13) , Ack I2crbyte Ebuffer(14) , Ack I2crbyte Ebuffer(15) , Ack I2crbyte Ebuffer(16) , Nack I2cstop End Sub
Grüße
Kurzschluss







					
					
					
						
Zitieren

Lesezeichen