Convert small 64bit signed integer into a high and low byte ?


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3273
Posted: 01:18am 17 Apr 2026      

A better speed tester. This one doesn't waste time reading back a lot of bytes, 1 is all that is needed.
Print "Page write speed test for 24C32 EEPROM on I2C2"
Dim Wr$, Re$, tmp$, n%, t, I2C.addr = &H57

Print "Make future failure to write visible."
tmp$ = "Fail"
For n%= 0 To 95 Step 4
  Wr$ = Chr$(0)+Chr$(n%)+tmp$
  I2C2 write I2C.addr, 0, Len(Wr$), Wr$
  Pause 9
Next
  Print "Verify data was written"
  I2C2 write I2C.addr, 0, 2, 0, 0 : I2C2 read I2C.addr, 0, 96, Re$
  Print Re$ : Print
  Wr$ = "" : tmp$ = "" : Re$ = ""

For n% = 32 To 127 'make 3 pages of data
  Inc Wr$, Chr$(n%)
Next
Print "Test Data"
Print Wr$ : Print

For n% = 0 To 64 Step 32
  tmp$ = Mid$(Wr$,n%+1,32)
  Print tmp$
  tmp$ = Chr$(0) + Chr$(n%) + tmp$
  I2C2 write I2C.addr, 0, Len(tmp$), tmp$
  t=Timer:Do :I2C2 read I2C.addr,0,1,Re$:Loop Until MM.I2C<>1:t=Timer-t
  Print "Time to Write a Page = ";t;"mS" : Print
Next
Print

Re$ = ""
Print " Check saved data for errors."
I2C2 write I2C.addr, 0, 2, 0, 0 : I2C2 read I2C.addr, 0, 96, Re$
Print Re$
If Re$ = Wr$ then Print "  Data validated" else Print "  Validation failed!"
End

A:> RUN
Page write speed test for 24C32 EEPROM on I2C2
Make future failure to write visible.
Verify data was written
FailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFail

Test Data
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

!"#$%&'()*+,-./0123456789:;<=>?
Time to Write a Page =  1.806000002mS

@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
Time to Write a Page =  1.787999999mS

`abcdefghijklmnopqrstuvwxyz{|}~
Time to Write a Page =  1.789999999mS


Check saved data for errors.
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Data validated
A:>

So for this chip a 2mS pause is enough.
Edited 2026-04-17 13:56 by phil99