http://www.picbasic.co.uk/forum/showthread.php?t=587
You WILL need pull-up's on the Clock and Data lines (weak pull-up's just don't work reliably here)... 4K7 is recommended.
http://www.picbasic.co.uk/forum/showthread.php?t=587
You WILL need pull-up's on the Clock and Data lines (weak pull-up's just don't work reliably here)... 4K7 is recommended.
Deeper question - sorry - let me explain..
The external EEPROM is working.. I am storing and retrieving data. So yes, I know the lines are working, etc. I have pull-ups, etc.
However, I am trying to KEEP data alive even after power down, and this does not seem to be working 100%. Some survives, some does not!!
24LC512s - I am using two of them. The software can tell them apart, and know them as 'Chip1', and 'Chip2'. When I write data to the Chips, then retrieve it, I get valid data, even if I fill up both chips. It works fine at a gross level.
The issue is deeper than if the EEPROM is recording or not - it has to do with saving specific BYTES in EEPROM between power cycles..
My program writes logging data to the EEPROM in Page Mode. My data is 36 bytes long, so I actually read 3 times into an array of a size of 108 (which works on the 18F2525). That way each page has 108 of the 128 bytes used.
1. I ALSO want to store some variables that I need BETWEEN power cycles in EEPROM.
A. the last used memory location, so when I start up again I know where I ws.
B. the user selected 'baud rate' for download
C. the 'passthru flag' - tells the code if it should just record to memory only, or also send that data to the serial port.
SO - I write my LOGGING data in memory positions
128-64000 - in chip 1 -> saving address 0-127
0-64000 in chip 2
I WANT to use the first 'page' on chip one as a place to keep persistent variables. SO I write to the address range 0-127 for these variables.
The memory locations are defined as:
Symbol ADR_loc = 10 ' next usable address
Symbol CHP_loc = 12 ' the chip we are on
Symbol D_baud_loc = 14 ' the download baud value
Symbol pass_loc = 20 ' the flag for passthru
Symbol wpt_loc = 30 ' the flag for waypoints
Symbol W_baud_loc = 40 ' waypoint baud rate
Then, I collect data from the user or from the program, and I2CWRITE the data into the memory locations as per above. The PROBLEM seems to be that when I write for example a '1' into "pass_loc", when I I2CREAD that same memory location later DURING the same power cycle, it is fine - it reads back what I'd expect. The PROBLEM is that if I power cycle, the data gets smashed...
HOWEVER, the data I write in PAGE MODE appears to survive a power cycle....
Any ideas why?? Can you not save persistent data to EEPROM?
of course you can, this is why we use EEPROMs!. . .Can you not save persistent data to EEPROM?
I see several reasons for EEPROM data not being what you expect it to be:
It has not been written to EEPROM (is your timing ok?)
or
it is being overwritten during the power up.
In both cases there must be something wrong in your code.
I assume you have already tried a different chip to ensure the EEPROM itself is ok.
regards
Ralph
_______________________________________________
There are only 10 types of people:
Those who understand binary, and those who don't ...
_______________________________________________
Have not checked memory - I will. Funny tho how perfectly well it works AS LONG AS I DON'T POWER DOWN.. So the culprit MUST be something in the intitialzation somehow?? hmm.
Maybe the fact I am declaring the memory locations as SYMBOLS is a problem? When I start up, for example, I declare the memory location to store baud rate as
wptbd Symbol = 10
Does this need to be a VARIABLE? I will never write the value for Waypoint Baud to anywhere EXCEPT position 10.. that is so I know where to get it when I need it.
I saw mention of not using SYMBOLS in I2C..
??
O.k this is why,
with your EEPROM, your address must be a word sized variable, so useAnd with wptbd Symbol = 10 written as is you didn't get any compilation error??
wptbd VAR WORD
wptbd = 10
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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
Tom,
on my DataLoggers I have 16F876 or 18F252 and 2x 24LC512.
The following code is tested.
could you give it a try and let us know what the result was?
Code:SCL var PortC.5 ' I2C Clock SDA var PortC.4 ' I2C Data ROM0 CON $A0 ' EEPROM 0 Address ADDR VAR word ' ROM Location MonPort var PortB.7 ' Monitor Port Mode con 16572 ' 4800 Baud 8N1 for Monitor Port Test var byte[21] ' Test Array I2Cdelay con 10 ' Delay after I2Cwrite Temp var byte CLEAR SEROUT2 MonPort,Mode,[13,10,"** MCU started",13,10,13,10] ADDR=100 I2CREAD SDA,SCL,ROM0,ADDR,[Temp] IF Temp="*" THEN GOTO SkipWrite I2CWRITE SDA,SCL,ROM0,ADDR,_ [$2A,$20,$54,$65,$73,$74,$20,$45,$45,$50,$52,$4F,_ $4D,$20,$2D,$2D,$3E,$20,$4F,$4B,$21] PAUSE I2Cdelay SEROUT2 MonPort,Mode,["** EEPROM written",13,10,13,10] GOTO Loop SkipWrite: SEROUT2 MonPort,Mode,["** EEPROM write skipped",13,10,13,10] I2CREAD SDA,SCL,ROM0,addr,[str test\21] Loop: SEROUT2 MonPort,Mode,[STR Test\21,13,10] PAUSE 1000 GOTO Loop END
regards
Ralph
_______________________________________________
There are only 10 types of people:
Those who understand binary, and those who don't ...
_______________________________________________
Bookmarks