| Posted: 08:03am 10 Jun 2025 |
|
|
|
This writes and reads all pages on a 24C32. If you don't want write to them all reduce For n = 0 To 127 to 4 or more. If you already have data on the EEPROM just use :- Sub Read_24C32_All ' Read all data from 24C32 EEPROM at the bottom.
Edit. It uses System I2C.
24C32 EEPROM tester 2.bas ' Test program to fill a 24C32 EEPROM with 128 x 32 byte pages. Dim Integer n, dummy, I2C.addr, Mem.addr Dim D$, R$, txt$
For n = &H50 To &H58 'find the I2C address - if more than one the first or last can be used I2C CHECK n If Not MM.I2C Then ' test for slave response. 1 = no response I2C.addr = n Print "&H";Hex$(I2C.addr), EndIf Next Print
' Write to all pages on 24C32 EEPROM Print "Assembled I2C data, including the 2 pointer address bytes."
For n = 0 To 127 'make 32 byte pages Mem.addr = n * 32 'set the memory pointer D$ = "<-ptr A="+Str$(Mem.addr,4)+", Page "+Str$(n,3)+", A="+Str$(Mem.addr+31,4)+"->" 'make a page D$ = Chr$(Mem.addr>>8) + Chr$(Mem.addr And 255) + D$ 'Add 2 byte Mem. address to the start of the Data' I2C WRITE I2C.addr,0,Len(D$),D$ 'write 2 memory address bytes + data bytes For m=1 To 34 : If Asc(Mid$(D$,m,1))<32 Or Asc(Mid$(D$,m,1))>127 Then : MID$(D$,m,1)="." : EndIf : Next Print d$+" "; :If n Mod 4 = 3 Then :Print :EndIf 'show the pages written, non-ASCII characters shown as "." Pause 6 'allow time to write Next
Print :Print :Print "Data read from EEPROM" Read_24C32_All
Sub Read_24C32_All ' Read all data from 24C32 EEPROM Mem.addr = 0 : I2C WRITE I2C.addr, 0, 2, Mem.addr >> 8, Mem.addr And 255 'return the pointer to 0 For n = 0 To 31 I2C read I2C.addr, 0, 128, R$ 'print all data, 4 pages per line, showing non-ASCII characters as "." For m=1 To 32 : If Asc(Mid$(R$,m,1))<32 Or Asc(Mid$(R$,m,1))>127 Then : MID$(R$,m,1)="." : EndIf : Next Print R$ Next End Sub
End Edited 2025-06-10 18:07 by phil99 |