EEPROM woes again

russbow

Senior Member
I have a I2C module consisting of a DS1307 rtc and an AT24C32 eeprom.

Using the usual hi2cout 0,(ABCDE) and reading back gives correct results

This code is an effort check address increments with event calls.

Code:
'working 30/11


#picaxe08M2

#No_Data

symbol LCD= c.0
symbol DEG= c.4
symbol incr=w13
symbol flag=b24
symbol address=w11
let w11=1
high c.0
serout LCD,N2400,(254,1,254,1) 'clear screen
pause 200

hi2csetup i2cmaster, %10100000, i2cslow, i2cword
hi2cout 0,(w11)		' Write initial address to location 0

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'The main loop

Main:

debug

gosub timeit 

gosub disp1

pause 5000

goto main

''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
'Get RTC data then ....

 timeit:
 
 hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte

	 hi2cin 0,(b0,b1,b2,b3,b4,b5,b6)

	
	pause 50

	b11=b2/16	 'hour MSD
	b12=b2 & $0F 'hour LSD
	b7=b1/16	 'min  MSD
	b8=b1 & $0F  'min  LSD
	b9=b4/16	 'day MSD
	b10=b4 & $0F 'day LSD
	b2=b5/16
	b3=b5 & $0F
	b0=b6/16:b4=b6 & $0F
	
'''''''''''''''''''''''''''''''''''''''''''''''''''''

' ..... check event parameters


	If b8 = 0 or b8 = 5 Then
  		If flag = 0 Then gosub count_it
    		flag = 1
  	'End If
Else
  flag = 0
End If

return

''''''''''''''''''''''''''''''''''''''''''''''''''''

'This displays HH:MM and DD/MM/YY on line 1

disp1:

serout LCD,N2400,(254,128,#b11,#b12,":",#b7,#b8,"   ") 'H/M

	serout LCD,N2400,(254,136,#b9,#b10,"/",#b2,#b3,"/",#b0,#b4)
	

return

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'This bit writes info to AT24C32 EEPROM

'Entry conditions are:- b8=0 or b8=5 and Flag set to zero
'address=w11
'incr=w13
'flag=b24

count_it:

	let flag=1	'stop further event

	hi2csetup i2cmaster, %10100000, i2cfast, i2cword	'set up eeprom

	hi2cin 0,(address)	'get next address from location zero

	let incr=incr+1		'increment event counter

	hi2cout address,(incr)	'store counter in next eeprom location

	address=address+1		'increment eeprom address

	hi2cout 0, (address)	'and write it to location zero
	
	gosub disp2			'show counter and current address

return

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This bit displays event count and next address on line 2

disp2:

serout LCD,N2400,(254,192,"Count ",#incr,"  Add ",#address)
pause 100
return
Time and date display ok, I never had an issue with this, but the count (incr) and the Add (address)
do not follow what I expected (wanted!)

The LCD shows the count incrementing on the *0 and *5 minutes, but the address doesn't follow, often sticking at 2.

Any ideas would be appreciated
 

hippy

Ex-Staff (retired)
You have not got any PAUSE after the HI2COUT's.

First step when then things appear not to have been written out correctly; read them back in and see if they are expected :)
 

Technical

Technical Support
Staff member
As well as the problem with the eeprom write delay (add a pause) it is not a good idea to run both 'fast' and 'slow' devices on the same i2c bus, as it is possible for the slow device to 'get confused' at the fast speed. Run everything at the speed of the slowest device on the bus, so in this case you should use 'slow' both times.
 

russbow

Senior Member
Thank you both. The pause command cures the problem and now i2cslow is used for both devices.
It has been running all night and the count and address figures have tracked perfectly for a little under 200 cycles.

Now to modify it to log the data I want. Hopefully wont be back :D
 

westaust55

Moderator
If you don't mind working with an SMD chip (and adapter board) you can replace the DS1307 with a DS1338 which is identical to the DS1307 and will operate "legally" (ie by the datasheet) with the i2cfast parameter.
 
Last edited:

nick12ab

Senior Member
It's only 8 pins so you can just solder LED leg cut-offs to the DS1338's legs and bend the new legs so that they form a DIP footprint. A small piece of stripboard helps with this.

Typo fixed = excellent

Why are there now lines separating the title from the body of the post?
 

westaust55

Moderator
I catch many of my own typos soon after, once I get onto a PC as opposed to typing on a phone. Only the privileged get a Nickpicking service.

Soldering SMD chips is not too difficult.
I use a conventional soldering iron and solder but use a magnifying glass to check positioning and recheck after the first leg is soldered. Have done up to 20 pin chips this way.
 

papaof2

Senior Member
Soldering SMD chips is not too difficult.
I use a conventional soldering iron and solder but use a magnifying glass to check positioning and recheck after the first leg is soldered. Have done up to 20 pin chips this way.
Your hand is steadier than mine ;-) I've done some 8 pin SOIC (FRAM chips) with aid of a magnifier, but don't know whether I could maintain that level of concentration for 20 pins. - perhaps doing 10 pins then taking a break before the other 10 would work.
 

russbow

Senior Member
From post #2

You have not got any PAUSE after the HI2COUT's.
Why do I need a pause after this

Code:
hi2cout 0,(w11)
writing only one variable, and only need one pause for this

Code:
hi2cout address,(HourH,HourL,MinH,MinL,mintemp,maxtemp)
writing six variables?
 

westaust55

Moderator
If you write one byte (Byte Write) then the EEPROM control sees the end of data after the one byte and immediately writes that byte to actual EEPROM.

If you write multiple bytes up to the page size, the chip control detects the different mode (Page Write) and saves the incoming data bytes into a temporary buffer and then when the end of data is detected, writes all the data to the actual EEPROM at one time which is still done within the same max time frame.

Note that if your multi-byte write crosses a page boundary then the data that you though was going to be written consecutively wraps/rolls at the end of the page and start at the beginning of the same page. As such you overwrite earlier EEPROM memory locations.
 
Last edited:

russbow

Senior Member
I am using a AT24C32 eeprom and the initial write, as I understand it is a word device, is

Code:
hi2csetup i2cmaster, %10100000, i2cslow, i2cword
hi2cout 0,(w11)		' Write initial address to location 0
Does this mean that w11 uses locations 0 and 1, and the next free location is #2.

also can I write bytes to the eeprom :-
Code:
hi2cout 1,(b0,b1,b2,b3,b4,b5,b6)
or must I use hi2cout 1,(w0,w1,w2,... etc...), which will mean a major re-vamp of the variables used. :confused:
 

Technical

Technical Support
Staff member
A word device is a device that needs two bytes (a word) to set the read/write address before the brackets. It does NOT 'write' words, it only writes bytes still.

So hi2cout with w0 will only result in the lower byte of w0 being written, the top byte will be lost.
Instead you should hi2cout on both bytes that make up w0, ie b0 and b1 on even addresses, this saves the entire word contents in two byte 'lumps'

Code:
w0 = $1234
w1 = $5678

hi2cout 0,(b1,b0) ; saves $12 $34 
pause 10
hi2cout 2,(b3,b2) ; saves $56 $78
pause 10
 

russbow

Senior Member
That's great thanks. I want to use bytes inside the brackets and wasn't sure if that would work properly.
 

russbow

Senior Member
I am using a 24c32 eeprom because it is an integral part of the module. The data sheet attached.

yes, I have read it. No, I do not fully undersand it.

Using this code .........
Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Note entry address for first write is 7

count_it:


	Read 0, MINTEMP:pause 100
	Read 1, MAXTEMP:pause 100

	hi2csetup i2cmaster, %10100000, i2cslow, i2cword	'set up eeprom

	hi2cin 0,(address)	'get next address from location zero
	pause 200

	hi2cout address,(b11,b12,b7,b8,mintemp,maxtemp)	' HH MM
	
	pause 200

	let address=address+8		'increment eeprom address
	
	hi2cout 0, (address)	'and write it to location zero
	
	pause 200	

	gosub wipe
	
	
return

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
........ how many readings can I expect before data is either lost or over written. each entry is eight variables long, 6 defined and 2 wasted.

Is there a page boundary? if so, as my address increments are 8, can I ignore any boundaries.
 

Attachments

Last edited:

jtcurneal

Senior Member
A 24C32 can store 4096 bytes of data.

you should be able to write up to 511 8 byte blocks of data. I use 1 block for the address for the next time that I write.

By adding 8 to the eeprom address that I am going to write. I have never had any problem overwriting or losing data.

Joel
 
Top