Argg!! I just cannot get those values to stay in EEPROM through a power cycle!!
Here is what I've done:
18F2525
2 x 24LC512 connected as CHIP1, CHIP2
Chip1 con %10100000 ' address of chip1
Chip2 con %10100010 ' address of chip2
resistors in pace.
My program stores data to these chips, and this works. I can store data, then read it back and what I get is valid data (because it contains a checksum, if anything were wrong, the recieving software program would choke)
THEN, I decided I wanted to store the BAUD setting for download and waypoint transmssion, and a flag called PASSTHRU, and Waypoint on/off -- RIGHT IN THE EXTERNAL EEPROM so that I did not have to keep setting it every time I power up the system.
SO,
My program uses the chips memory as follows:
Chip1 address usage:
0-127 = special setting storage
128 - 63872 - logging data
Chip2 address usage:
0 - 63872 - logging data
In the initialization, I have set the following parameters:
' ------------ memory eeprom storage locations --------------------------------------
ADR_loc var word ' location to store the address
CHP_loc var byte ' will only be 1, 2, 3, 4
D_baud_loc var word ' download baud rate
pass_loc var byte ' the flag for passthru - 1 or 0
wpt_loc var byte ' the flag for waypoints - 1 or 0
W_baud_loc var word ' waypoint baud rate
ADR_loc = 100 ' next usable address
CHP_loc = 102 ' the chip we are on
D_baud_loc = 104 ' the download baud value
pass_loc = 108 ' the flag for passthru
wpt_loc = 110 ' the flag for waypoints
w_baud_loc = 112 ' waypoint baud rate
The values actually STORED in these locations are:
address var word ' current memory address
chipselect var byte ' current chip we are on 1 or 2
passthru var byte ' flag - allows data to pass thru to PC
Set_Wpt var byte ' flag allows waypoint data to be sent
wptBD var word ' baudrate of waypoint- ie 16572, etc.
D_baud var word ' baudrate of download speed for PC
SO, my program should ALWAYS know where to look for the various settings. In fact, I have proven that this works - when the program powers up, it confirms that each of these values is correct.
THEN,
I2Cread DPIN, CPIN, Chip1, wpt_loc, set_wpt ' waypoint flag storage
I2Cread DPIN, CPIN, Chip1, Pass_loc, passthru ' passthru flag storage
I2Cread DPIN, CPIN, Chip1, D_baud_loc, D_baud.byte0 ' baud2
I2Cread DPIN, CPIN, Chip1, D_baud_loc+1, D_baud.byte1 'baud2
I2Cread DPIN, CPIN, Chip1, W_baud_loc, wptbd.byte0 ' store waddress 1
I2Cread DPIN, CPIN, Chip1, W_baud_loc+1, wptbd.byte1 ' store waddress 2
I2Cread DPIN, CPIN, Chip1, ADR_loc, address.byte0' get the address 1
I2Cread DPIN, CPIN, Chip1, ADR_loc+1, address.byte1' get the address 2
I2Cread DPIN, CPIN, Chip1, CHP_loc, Chipselect ' get the chipselect
SO - at this point, you'd expect that my program now knows:
1. WHERE to look for the data, and
2. It has read the values from those locations into variables.
The PROBLEM is this.. This works great AS LONG AS I DON'T RESTART. Once I store data using "I2CWRITE" into these locations, I can reliably get them back whenver I want. If I restart, the values are all messed up.
As an example, I wrote a small program to allow me to query these values on a PC screen anytime to troubleshoot. Here is what I see:
Upon first startup:
PARAMETER MEMLOC
Download baud rate unknown: 0 104
Waypoint baud rate unknown: 5837 112
Unknown Streaming setting: 197 108
Unknown Waypoint Setting: 215 110
Last Memory Address: 0 100
Current Chip: 7 102
SO, it is properly looking in the right place, but seeinig garbage values. Once I tell it to store a set of 'Default' values that the program will recognize, I get this response:
PARAMETER MEMLOC
Download baud rate 9600 104
Waypoint baud rate 4800 112
Data WILL NOT stream to GPS-TEAM 108
Waypoint Output ON 110
Last Memory Address: 128 100
Current Chip: 1 102
This response is CORRECT. The program recognizes values and is reporting what the settings are.
If I power cycle, the old garbage values come back - the exact same ones!!
PARAMETER MEMLOC
Download baud rate unknown: 0 104
Waypoint baud rate unknown: 5837 112
Unknown Streaming setting: 197 108
Unknown Waypoint Setting: 215 110
Last Memory Address: 0 100
Current Chip: 7 102
-- so SOMETHING is writing garbage to my memory when I am not looking. Might it be my setup variables for the 18F2525
ADCON0 = %00110000' turn off - select port AN12 (nothing)
ADCON1 = %00001111' turn portA to digital I/O (same as dec 15)
CMCON = $07 ' turn off
HLVDCON = %00000000 ' turn off
CVRCON = $00000000 ' turn off
SSPCON1 = %11011100 ' supposed to be turning on I2C
SSPCON2 = %01111000 ' supposed to be turning on I2C
INTCON = %11110000 ' TG guess at 2525 interrups for all INT pins
INTCON2= %01110100 ' rising edge of INT0,1,2 RB0,1,2
RCON = %10000000 ' no priority interrups
T1CON = %11000000 'Timer1 1:1 prescale.
T0CON = 1
SOMETHING is writing to Chip1 memory locations when I am not looking, I just can't figure out WHAT.. ALL of my loops start at 128, even if I do NO OTHER MEMORY WRITES during a session, the variables STILL get messed up.
HELP!
Tom




Bookmarks