read 24c02 send as hex to terminal Need someadvice

Hansen

Member
I have a task which I have divided in proportion stepper

since I do not know where the individual date elements are
day, month & year and maybe kind of off checksum

This chip uses as a time lock on a battery pack in a UPS system

I want a change it.. after I change battery so it does not get by and say "You is out off battery life"

I have a 24c02 from an old battery pack where I know what the date is in DD: MM: YY

I have created a setup which I believe can be used

switch must be used to activate read function


there are some who can help with some base code

based on picaxe 20x2


1 step

read content from 24c02 add 0 to add 255

send it to the terminal as HEX

00: xx.xx.xx.xx.xx.xx.xx.xx
08: xx.xx.xx.xx.xx.xx.xx.xx
.
.
FF: xx.xx.xx.xx.xx.xx.xx.xx

This will be used to find the right positions for the data that I need

2nd Step

after I know where my data is

should I change this and write data back incl new checksum (when I found out this algoritne now)
 

Attachments

srnet

Senior Member
The circuit diagram indicates that you have both pins of the I2C interface connected together ?
 

westaust55

Moderator
Since this seems to be a quick one-off requirement, we are not going to get too sophisticated with the code but the following untested code should for the starting point to read the EEPROM and display the data.
You can change all of the SEROUT lines to SERTXD and the use the PE's [F9] data logger terminal to receive the data and save as a .csv type file which can be read by many programs (eg MS Excel).

Code:
SYMBOL Address = b8
SYMBOL Counter = b9
SYMBOL Value   = b10
SYMBOL Nybble  = b11



Init: HI2CSETUP i2cmaster, %10100000, i2cslow, i2cbyte
	Address = 0

Main:
FOR Counter = 0 TO 31 ; 32 lots of 8 bytes = 256 bytes = 2048 bits = EEPROM size
	HI2CIN Address, (b0, b1, b2, b3, b4, b5, b6, b7)
	b0 = 0 : b1 = 1 : b2=2 : b3 = 3 : b4=4 : b5 = 5 : b6 = 6 : b7 = 7
	value = Address : GOSUB DECTOHEX
	SEROUT B.7, N4800, (": ")
	value = b0 : GOSUB DECTOHEX 
	SEROUT B.7, N4800, (".")
	value = b1 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b2 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b3 : GOSUB DECTOHEX 
	SEROUT B.7, N4800, (".")
	value = b4 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b5 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b6 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b7 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	Address = Address + 8
NEXT Counter
END

DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $38
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SEROUT B.7, N4800, (Nybble)
	RETURN
 

Hansen

Member
Since this seems to be a quick one-off requirement, we are not going to get too sophisticated with the code but the following untested code should for the starting point to read the EEPROM and display the data.
You can change all of the SEROUT lines to SERTXD and the use the PE's [F9] data logger terminal to receive the data and save as a .csv type file which can be read by many programs (eg MS Excel).

Code:
SYMBOL Address = b8
SYMBOL Counter = b9
SYMBOL Value   = b10
SYMBOL Nybble  = b11



Init: HI2CSETUP i2cmaster, %10100000, i2cslow, i2cbyte
	Address = 0

Main:
FOR Counter = 0 TO 31 ; 32 lots of 8 bytes = 256 bytes = 2048 bits = EEPROM size
	HI2CIN Address, (b0, b1, b2, b3, b4, b5, b6, b7)
	b0 = 0 : b1 = 1 : b2=2 : b3 = 3 : b4=4 : b5 = 5 : b6 = 6 : b7 = 7
	value = Address : GOSUB DECTOHEX
	SEROUT B.7, N4800, (": ")
	value = b0 : GOSUB DECTOHEX 
	SEROUT B.7, N4800, (".")
	value = b1 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b2 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b3 : GOSUB DECTOHEX 
	SEROUT B.7, N4800, (".")
	value = b4 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b5 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b6 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	value = b7 : GOSUB DECTOHEX
	SEROUT B.7, N4800, (".")
	Address = Address + 8
NEXT Counter
END

DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $37
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SEROUT B.7, N4800, (Nybble)
	RETURN


Will it be possible to change to picaxe 18x i run out off 20x2 ????
 
Last edited by a moderator:

john2051

New Member
Hi Hansen, If all you want is a hex dump of the eeprom, there is serial port bit banged software to do this on the net.
Some time ago I had some philips radios that had their frequencies programmed into a 24lc16 eeprom.
Is that the sort of thing you want? I2C to pc.

Regards to all john
 

Hansen

Member
Hi john
yes i have find some off this on the net, but this is only the first step to read the 24c02 2nd will be some change and recalculate new checksum
 

Hansen

Member
I make this test because the read from the 24c02 only get value zero back

picaxe 18x with 24lc256 on my axe091 test board

test was to a use add for 0 to 255 a value same as the add

when I read it back I get diff :( only zero

out put

"
00: 00.00.00.00.00.00.00.00.
08: 00.00.00.00.00.00.00.00.
10: 00.00.00.00.00.00.00.00.
18: 00.00.00.00.00.00.00.00.
20: 00.00.00.00.00.00.00.00.
28: 00.00.00.00.00.00.00.00.
30: 00.00.00.00.00.00.00.00.
38: 00.00.00.00.00.00.00.00.
40: 00.00.00.00.00.00.00.00.
48: 00.00.00.00.00.00.00.00.
.
.
D8: 00.00.00.00.00.00.00.00.
E0: 00.00.00.00.00.00.00.00.
E8: 00.00.00.00.00.00.00.00.
F0: 00.00.00.00.00.00.00.00.
F8: 00.00.00.00.00.00.00.00.


Code:
#PICAXE18X

SYMBOL Address = b8
SYMBOL Counter = b9
SYMBOL Value   = b10
SYMBOL Nybble  = b11


hi2csetup i2cmaster, %10100000, i2cfast, i2cword	;Setup 24LC256
Address = 0

main:
For Counter = 0 To 255
	hi2cout Counter,(Counter)
	pause 10
Next Counter

FOR Counter = 0 TO 31 ; 32 lots of 8 bytes = 256 bytes = 2048 bits = EEPROM size
	
	HI2CIN Address, (b0, b1, b2, b3, b4, b5, b6, b7)
'	b0 = 0 : b1 = "a" : b2=2 : b3 = 3 : b4=4 : b5 = 5 : b6 = 6 : b7 = 7
	value = Address : GOSUB DECTOHEX
	SERTXD (": ")
	value = b0 : GOSUB DECTOHEX 
	SERTXD (".")
	value = b1 : GOSUB DECTOHEX
	SERTXD (".")
	value = b2 : GOSUB DECTOHEX
	SERTXD (".")
	value = b3 : GOSUB DECTOHEX 
	SERTXD (".")
	value = b4 : GOSUB DECTOHEX
	SERTXD (".")
	value = b5 : GOSUB DECTOHEX
	SERTXD (".")
	value = b6 : GOSUB DECTOHEX
	SERTXD (".")
	value = b7 : GOSUB DECTOHEX
	SERTXD (".")
	SERTXD (b0, b1, b2, b3, b4, b5, b6, b7, 13, 10)
	Address = Address + 8
NEXT Counter
goto Main

DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $38
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SERTXD (Nybble)
	RETURN
 
Last edited:

g6ejd

Senior Member
Rather than be to adventurous, have you tried a simple 3 line or so programme that writes a single byte to address 0, then over-write your variable in the programme to be sure, then read the value back and display it? Doing that will prove whether your circuit is working as you expect it to. You circuit diagram has an error in it, have you wired up the board differently to the diagram?
 
Last edited:

westaust55

Moderator
Since the data "Received" is all zeros, this suggest a possible hardware problem.
$FF or 255 would normally indicate a poor comms connection but all zeros suggest the data line or clock is pulled low.
Have you corrected the error with the schematic as mentions at about post 2?
Maybe some clear photos of your circuit so folks can check the connections.
 

westaust55

Moderator
If you are temporarily trying to see the actual EEPROM values with the line:
SERTXD (b0, b1, b2, b3, b4, b5, b6, b7, 13, 10)

then I sugegst that you change it to:
SERTXD (#b0, #b1, #b2, #b3, #b4, #b5, #b6, #b7, cr, lf)
 

Hansen

Member
Since the data "Received" is all zeros, this suggest a possible hardware problem.
$FF or 255 would normally indicate a poor comms connection but all zeros suggest the data line or clock is pulled low.
Have you corrected the error with the schematic as mentions at about post 2?
Maybe some clear photos of your circuit so folks can check the connections.
If it the hardware it some thing wrong with my AXE 091 board

I have 2 wire from the 18x to the 2 pin close to the 24cxx socket SDA and SCL
 

hippy

Ex-Staff (retired)
If it the hardware it some thing wrong with my AXE 091 board

I have 2 wire from the 18x to the 2 pin close to the 24cxx socket SDA and SCL
Using an AXE091, 24LC256, 18X and 20X2 your code in post #8 works for me - save a minor bug in the decimal to hex conversion routine.

Check that you haven't got SDA and SCL crossed over and they go to the correct pins on the 18X socket; the lower pins of the SIL sockets surrounding the 18-pin position are 0V and 5V.
 

Armp

Senior Member
As has been mentioned above several times there is an error on your schematic - the SCL and SDA lines are shorted.
You have not yet indicated that you have fixed it.
 

Hansen

Member
:) Work with simple code


change

hi2csetup i2cmaster, %10100000, i2cfast, i2cword ;Setup 24LC256
to
i2cslave %10100000, i2cfast, i2cword ;Setup 24LC256

hi2cout 0,("lord off ",123,65,34,54)
to
writei2c 0,("lord off ",123,65,34,54)

HI2CIN 0, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12)

to
readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12)


it look like problem with hi2csetup, hi2cout,HI2CIN




output

lord off {A"6
108.111.114.100.32.111.102.102.32


Code:
#PICAXE18x


i2cslave %10100000, i2cfast, i2cword	;Setup 24LC256

main:
	writei2c 0,("lord off ",123,65,34,54)
	pause 10

	readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12)
	SERTXD ("   ", b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12, cr, lf)
	
	 SERTXD (#b0, ".", #b1, ".", #b2, ".", #b3, ".", #b4, ".", #b5, ".", #b6, ".", #b7, ".", #b8, cr, lf)
	pause 1000
goto main
 

Hansen

Member
As has been mentioned above several times there is an error on your schematic - the SCL and SDA lines are shorted.
You have not yet indicated that you have fixed it.
always fixed only mistake in the circuit program
 

westaust55

Moderator
As mentioned by hippy, there is/was a minor bug in the HEXTODEC subroutine. (comes from working from memory - mine not the chip's)

should be:
Code:
DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $3[COLOR="#FF0000"][B]7[/B][/COLOR]
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SEROUT B.7, N4800, (Nybble)
	RETURN


Which version of the Programming Editor are you using?
The PE does a hi2csetup to i2cslave translation for the 18X parts and hippy reports it is working for his 18X.
 

Hansen

Member
As mentioned by hippy, there is/was a minor bug in the HEXTODEC subroutine. (comes from working from memory - mine not the chip's)

should be:
Code:
DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $3[COLOR="#FF0000"][B]7[/B][/COLOR]
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SEROUT B.7, N4800, (Nybble)
	RETURN


Which version of the Programming Editor are you using?
The PE does a hi2csetup to i2cslave translation for the 18X parts and hippy reports it is working for his 18X.
firmware version 8.5
my picaxe 18x firmware ver 5

PE version 5.4.3 syntax DLL 262144

I got it work buy read all 256 byte now :)

00: 20.42.61.74.74.65.72.79. Battery

many thx, now i have to find the key off the date in the rest off the byte's


Code:
#PICAXE18X

SYMBOL Address = b8
SYMBOL Counter = b9
SYMBOL Value   = b10
SYMBOL Nybble  = b11


i2cslave %10100000, i2cfast, i2cbyte ;Setup 24LC02
Address = 0

main:

FOR Counter = 0 TO 32 ; 32 lots of 8 bytes = 256 bytes = 2048 bits = EEPROM size
	
	readi2c Address, (b0, b1, b2, b3, b4, b5, b6, b7)
'	b0 = 0 : b1 = "a" : b2=2 : b3 = 3 : b4=4 : b5 = 5 : b6 = 6 : b7 = 7
	value = Address : GOSUB DECTOHEX
	SERTXD (": ")
	value = b0 : GOSUB DECTOHEX 
	SERTXD (".")
	value = b1 : GOSUB DECTOHEX
	SERTXD (".")
	value = b2 : GOSUB DECTOHEX
	SERTXD (".")
	value = b3 : GOSUB DECTOHEX 
	SERTXD (".")
	value = b4 : GOSUB DECTOHEX
	SERTXD (".")
	value = b5 : GOSUB DECTOHEX
	SERTXD (".")
	value = b6 : GOSUB DECTOHEX
	SERTXD (".")
	value = b7 : GOSUB DECTOHEX
	SERTXD (". ")
	SERTXD (b0, b1, b2, b3, b4, b5, b6, b7, 13, 10)
	Address = Address + 8
NEXT Counter
sertxd(cr,lf,cr,lf)
pause 5000

goto Main

DECTOHEX:
	Nybble = Value / 16
	GOSUB Display
	Nybble = Value // 16
Display:	
	IF Nybble> 9 THEN
		Nybble = Nybble + $37
	ELSE
		Nybble = Nybble + $30
	ENDIF	
	SERTXD (Nybble)
	RETURN
 

westaust55

Moderator
18X firmware version 8.6 added some i2c comms improvements.

BASE FIRMWARE CODE:8
V1 FIRST PUBLIC RELEASE
V2 ADDED 256 GOSUB OPTION
V3 INTERNAL GANG PROGRAMMER CHANGE
V3 INTERNAL GANG PROGRAMMER CHANGE
V4 CORRECTED MINOR SERTXD ISSUE.
ADDED INFRAIN2 COMMAND.
V5 UPDATED READTEMP/READTEMP12/COUNT TIMING
V6 ADDED SINGLE BYTE READI2C/WRITEI2C SUPPORT.
V7 ROHS COMPLIANT
V8 INTERNAL GANG PROGRAMMER CHANGE
Unsure whether that impacted upon your FOR...NEXT loop sending one byte at a time when around post 9 ?? you tried writing to 24LC256.

The manual indicates the hi2csetup/hi2cin/hi2cout commands work with the 18X
Recall hippy stated previously that the PE "translated" these hi2c... commands to the i2cslave... series commands
 

hippy

Ex-Staff (retired)
18X firmware version 8.6 added some i2c comms improvements.

V6 ADDED SINGLE BYTE READI2C/WRITEI2C SUPPORT.
I believe that was the change to the command without specifying an address -

ReadI2c (b0)
WriteI2c (b0)

The manual indicates the hi2csetup/hi2cin/hi2cout commands work with the 18X
Recall hippy stated previously that the PE "translated" these hi2c... commands to the i2cslave... series commands
That's correct. The code I tested used the HI2CSETUP, HI2CIN and HI2COUT commands on both 18X and 20X2.
 

Hansen

Member
make my last recode on it and now it work as i want

this project give me some advice in use the i2c bus

thanks for all the help

finale code layout

Code:
#PICAXE18x

Symbol Checksum = W0
Symbol Address  = W1

Symbol Nybble   = b5
Symbol Value    = b4
Symbol Row2     = b7
Symbol Cel      = b8
Symbol Row      = b9
SYMBOL Counter1 = b11
SYMBOL Counter2 = b12



i2cslave %10100000, i2cfast, i2cbyte 

Checksum 	= 0		   ' 16 bit checksum
Row 		= 8		   ' Number off Number in the same line
Row2 		= Row -1
Cel 		= 256 / row -1 ' The Max address that want to be read

main:

Pause 5000
Address = 0

Checksum = 0

For Counter1 = 0 To Cel
	Gosub AddressDisplay	
	Sertxd(": ")
	For Counter2 = 0 TO Row2
		Address = Counter1 * Row + Counter2 + 1
		Value = Address
'		readi2c Address, (Value)		
		Checksum = Checksum + value
		Gosub Dectohex
		If Counter2 < Row2 Then
			Sertxd (".")
		Else
		      Sertxd (": ")
		Endif
	Next Counter2
	For Counter2 = 0 TO Row2
		Address = Counter1 * Row + Counter2
'		readi2c Address, (Value)		
		If Counter2 < Row2 Then
			Sertxd (Address)
		Else
		      Sertxd (Address, cr, lf)
		Endif
	Next Counter2
	Pause 1000
Next Counter1
Sertxd ( cr, lf," all byte total Sum = ")
Value = b1
Gosub Dectohex
Value = b0
Gosub Dectohex
Sertxd (" - ", #b1, " ", #b0, " - ")
Value = b1
Gosub Dectohex
Sertxd(".") 
Value = b0
Gosub Dectohex 
Sertxd ( cr, lf, cr, lf)
Goto main

AddressDisplay:
	Address = Address +1  
	If Address > 2047 Then
		Nybble = Address / 2048
	Else
		Nybble = 0
	Endif
	Gosub Display
	If Address > 255 Then
		Nybble = Address / 256 
		Nybble = Nybble // 16
	Else
		Nybble = 0
	Endif
	Gosub Display
	Address = Address -1
	Value = Address // 256
Dectohex:
	Nybble = Value / 16
	Gosub Display
	Nybble = Value // 16

Display:	
	If Nybble> 9 Then
		Nybble = Nybble + $37
	Else
		Nybble = Nybble + $30
	EndIf	
	Sertxd (Nybble)
	Return

The output from it

PS: output only for test off the setup off the output

The real output from the EEPROM will not be posted

Code:
0000: 01.02.03.04.05.06.07.08: 
0007: 09.0A.0B.0C.0D.0E.0F.10: 	


000F: 11.12.13.14.15.16.17.18: 
0017: 19.1A.1B.1C.1D.1E.1F.20: 
001F: 21.22.23.24.25.26.27.28:  !"#$%&'
0027: 29.2A.2B.2C.2D.2E.2F.30: ()*+,-./
002F: 31.32.33.34.35.36.37.38: 01234567
0037: 39.3A.3B.3C.3D.3E.3F.40: 89:;<=>?
003F: 41.42.43.44.45.46.47.48: @ABCDEFG
0047: 49.4A.4B.4C.4D.4E.4F.50: HIJKLMNO
004F: 51.52.53.54.55.56.57.58: PQRSTUVW
0057: 59.5A.5B.5C.5D.5E.5F.60: XYZ[\]^_
005F: 61.62.63.64.65.66.67.68: `abcdefg
0067: 69.6A.6B.6C.6D.6E.6F.70: hijklmno
006F: 71.72.73.74.75.76.77.78: pqrstuvw
0077: 79.7A.7B.7C.7D.7E.7F.80: xyz{|}~
007F: 81.82.83.84.85.86.87.88: &#8364;&#8218;&#402;&#8222;&#8230;&#8224;&#8225;
0087: 89.8A.8B.8C.8D.8E.8F.90: &#710;&#8240;&#352;&#8249;&#338;&#381;
008F: 91.92.93.94.95.96.97.98: &#8216;&#8217;&#8220;&#8221;&#8226;&#8211;&#8212;
0097: 99.9A.9B.9C.9D.9E.9F.A0: &#732;&#8482;&#353;&#8250;&#339;&#382;&#376;
009F: A1.A2.A3.A4.A5.A6.A7.A8: *¡¢£¤¥¦§
00A7: A9.AA.AB.AC.AD.AE.AF.B0: ¨©ª«¬*®¯
00AF: B1.B2.B3.B4.B5.B6.B7.B8: °±²³´µ¶·
00B7: B9.BA.BB.BC.BD.BE.BF.C0: ¸¹º»¼½¾¿
00BF: C1.C2.C3.C4.C5.C6.C7.C8: ÀÁÂÃÄÅÆÇ
00C7: C9.CA.CB.CC.CD.CE.CF.D0: ÈÉÊËÌÍÎÏ
00CF: D1.D2.D3.D4.D5.D6.D7.D8: ÐÑÒÓÔÕÖ×
00D7: D9.DA.DB.DC.DD.DE.DF.E0: ØÙÚÛÜÝÞß
00DF: E1.E2.E3.E4.E5.E6.E7.E8: àáâãäåæç
00E7: E9.EA.EB.EC.ED.EE.EF.F0: èéêëìíîï
00EF: F1.F2.F3.F4.F5.F6.F7.F8: ðñòóôõö÷
00F7: F9.FA.FB.FC.FD.FE.FF.00: øùúûüýþÿ

 all byte total Sum = 7F80 - 127 128 - 7F.80
 
Top