Newsgroups: comp.robotics
Path: brunix!sgiblab!spool.mu.edu!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!uhog.mit.edu!news.media.mit.edu!fredm
From: fredm@media.mit.edu (Fred G Martin)
Subject: Re: Miniboard: Logging Data to EEPROM
Message-ID: <1994Feb9.144926.9735@news.media.mit.edu>
Sender: news@news.media.mit.edu (USENET News System)
Organization: MIT Media Laboratory
References: <2j9bro$8l7@Times.Stanford.EDU>
Date: Wed, 9 Feb 1994 14:49:26 GMT
Lines: 97

In article <2j9bro$8l7@Times.Stanford.EDU> cdb@CS.Stanford.EDU (Craig
Becker) writes: 

>I am writing a data-taking program for the miniboard and
>would like it to save data to the EEPROM since there is
>such a limited amount of RAM.
>
>I have tried doing this, but with no success. My understanding
>is that the program that logs the data must be in RAM... is
>this true?

Yes, this is true because while you're burning the byte into EEPROM,
the memory effectively "disappears" from the address space of the CPU,
so you have to be executing the program from somewhere else.  If
you've got a single chip 6811, then that's the internal RAM.

Your program should have a driver located in EEPROM gets copies down
into RAM upon boot-up; then, when your program needs to burn a byte,
it can JSR to this routine in RAM (put the driver at the bottom of RAM
since the machine stack builds down from the top).

>If anyone has code to do this sort of thing, I'd appreciate
>it. Thanks

Here is code taken from the EEBOOT20.ASM loader used by DLM (the code
downloader).  One trick is that you must "unprotect" the EEPROM within
the first ~64 cycles of execution after reset in order for the whole
process to be enabled.

This code checks if the byte already has the value you want to program
it with; if so, it returns without programming.  Also, the programming
process consists of two steps:  erasing (changing all the bits to
ones) and then programming (changing some of the bits to zeros).  The
code checks if the byte you want to program can be accomplished
without erasing first; if so, then it skips the erase step (e.g.,
changing a $35 into a $30).

The full file from which this code is taken is
cherupakha.media.mit.edu: pub/miniboard/ms-dos/eeboot20.asm.

	-Fred


	CLRA
	STAA	BPROT	; unprotect the EEPROM
...

BYTE_PGM	EQU	$02
BYTE_ERA	EQU	$16
BULK_ERA	EQU	$06

* call eewr_cmd with B= byte to be written;
*                    Y= address of the byte

eewr_cmd EQU *
	XGDY		; B has byte value to be written
eewr_2	CMPB	0,X	; check if byte already has desired value
	BEQ	read_cmd ; return if so

	LDAA	0,X	; get current value
	COMA		; complement
	STAB	temp
	ANDA	temp	; AND with desired value
	BEQ	noerase	; if zero, don't need to erase

	LDAA	#BYTE_ERA
	BSR	eepr_cmd

noerase	LDAA	#BYTE_PGM
	BSR	eepr_cmd
	BRA	read_cmd	; get value back from byte and return


* put command in A register, byte to be written in B
* ptr to address in X
eepr_cmd EQU *
	STAA	PPROG
	STAB	0,X
	ORAA	#1
	STAA	PPROG
	BSR	delay10
	CLR	PPROG
	RTS

delay100 LDY	#28570
	BRA	delaylp
delay10	LDY	#2857
delaylp	DEY
	BNE	delaylp
	RTS

* temporary storage
mode	RMB	1	; 0 = eeprom burn, 1 = ram download
temp	RMB	1

Fred Martin | fredm@media.mit.edu | (617) 253-5108 | 20 Ames St. Rm. E15-320
Epistemology and Learning Group, MIT Media Lab     | Cambridge, MA 02139 USA
