EEPROM Problems

Or maybe its I don’t know what to expect. Will EEPROM remain throughout program downloads? I’m hoping it does through controller resets… but it doesnt seem to be.

I’ve got this code, that I got from somewhere on these forums

	char readEE(unsigned short address) {
		EEADRH = ((address>>8)&0x03);
		EEADR = (address&0xFF);

		EECON1bits.EEPGD = 0;
		EECON1bits.CFGS = 0;
		EECON1bits.RD = 1;
	
		return EEDATA;
	}
	char writeEE(unsigned short address, char data) {
		EEADRH = ((address>>8)&0x03);
		EEADR = (address&0xFF);
		EEDATA = data;

		EECON1bits.EEPGD = 0;
		EECON1bits.CFGS = 0;
		EECON1bits.WREN = 1;
		INTCONbits.GIE = 0;
		EECON2 = 0x55;
		EECON2 = 0xAA;
		EECON1bits.WR = 1;
		INTCONbits.GIE = 1;
		EECON1bits.WREN = 0;
	}

I have funtions that should be reading and writing to functions… but the data doesn’t seem to be staying though controller resets and program downloads. Any help?

Brian,

Please read carefully through this thead: http://www.chiefdelphi.com/forums/showthread.php?t=22655 and pay particular attention to the details of timing, et cetera.

In answer to your question, yes, EEPROM data will be available to you for many years to come (if you store it correctly).

Please post again if there is still a question…

Doesn’t EEPROM data get wiped out when you download a new program? (This was part of his question too.)

Greg,

Actually, I’m not sure. I have not thought about it or researched it but flash and eeprom should have different bootstrap requirements and, therefore, separate erase routines… Flash is erased as a block and, as I remember, eeprom is erased byte by byte.

Maybe someone out there has actually done this?

I’ll look in the documentation this weekend (I’m a bit busy right now). However, it is an interesting question…

OK, I couldn’t help myself,

From **PIC18F6520/8520/6620/8620/6720/8720 Data Sheet, **section 4.0, page 41:

[left]There are three memory blocks in PIC18FXX20 devices. They are:
[/left]

[left]• Program Memory
[/left]

[left]• Data RAM
[/left]

[left]• Data EEPROM
[/left]

[left]Data and program memory use separate busses, which allows for concurrent access of these blocks.
[/left]
Since the data and program busses are independent, I would guess that reprogram with the IFI loader will not affect data EEPROM.

JMHO.

We did this last year for calibration values of the pots on our arms & crab wheels. We had a calibration mode that would read pot values at certain positions (in the case of crab it was center, full left, and full right) and store them off in EEPROM. Whenever the controller started up we would read those values from EEPROM and store them in a local calibration values structure so they were available to the crab/arm control routines as limit points.

This library of code was a huge time saver for the SW team because the procedure for calibrating a pot changed from: download debug code to read pot values, move crab/arm to endpoints & read values, change endpoint constants in header file, download code with new constants; to: put robot in calibrate mode and tap a button when crab/arm is at each endpoint, reset. It meant the pit crew could swap out a broken pot and calibrate it without a SW team member there. Best piece of SW we wrote in my opinion.

I also recommend adding a joystick calibration mode that prints the raw joystick values on the OI display. It saved our team when we needed to swap out a broken joystick while in line for our match. The drivers were able to center the stick without special debug software.

If there’s interest & I get some time I’ll write up a more detailed post explaining how we did all this.

Mike,

Thank you… To answer Greg’s question, is EEPROM erased when you download a new program via the IFI Loader?

Regards,

Oops, I guess I never answered that. I spent too much time babbling and forgot the original question.

EEPROM is not erased when you download a new program, I’ll verify this tonight.

I’m using it for something very similar to the joystick stuff. It detects the joystick center and its maximum possible range, and calculates deadbands off that. When I get it working correctly I can post it. I found an improved version of the eeprom code later in that thread, and I’ll try that out tonight. Thanks for the help.