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
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 ...
_______________________________________________
Ralph:
Thanks for the demo code, here is what the result was - pasted from the Hyperterminal window. (I added "writing:" to the string so I could see that it was becuse it was not writing anything that showed up on the screen.)
---------------------------------------------------------------------
** MCU started
** EEPROM written
writing:
writing:
writing:
writing:
writing:
writing:
writing:
writing:
writing:
writing:
--------------------------------------------------------------------------
Here is the code I used:
'--------------------------------------------------------------------------------
'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?
' -----[ Fuses ]------------------------------------------------
@ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L
'
' -----[ Includes/Defines ]---------------------------------------------------------
include "modedefs.bas" 'include serout defines
OSCCON=%01111000
DEFINE OSC 8
While OSCCON.2=0:Wend
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 PortC.6 ' 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,["writing: ", STR Test\21,13,10]
PAUSE 1000
GOTO Loop
END
----------------------------------------------------------------
Is this what you expected?
Tom
I got to wondering why I was getting nothing in the last build. So I trapped for failures to read and write. I did see that it was just not getting there, so tweaked the port assignments, etc. Here is what I get now:
** MCU started
** EEPROM write skipped
Reading:* Test EEPROM --> OK!
Reading:* Test EEPROM --> OK!
Reading:* Test EEPROM --> OK!
Reading:* Test EEPROM --> OK!
Reading:* Test EEPROM --> OK!
(I added "reading" to it)
The program is as follows:
------------------------------------------------------------------
'--------------------------------------------------------------------------------
'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?
' -----[ Fuses ]------------------------------------------------
@ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L
'
' -----[ Includes/Defines ]---------------------------------------------------------
include "modedefs.bas" 'include serout defines
OSCCON=%01111000
DEFINE OSC 8
While OSCCON.2=0:Wend
SCL var PortC.3 ' I2C Clock
SDA var PortC.4 ' I2C Data
ROM0 con %10100000 ' address of chip1
ADDR VAR word ' ROM Location
MonPort var PortC.6 ' 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],failw
PAUSE I2Cdelay
SEROUT2 MonPort,Mode,["** EEPROM written",13,10,13,10]
GOTO Loop
SkipWrite:
SEROUT2 MonPort,Mode,["** EEPROM write skipped",13,10,13,10]
Loop:
I2CREAD SDA,SCL,ROM0,addr,[str test\21],failr
SEROUT2 MonPort,Mode,["Reading:", STR Test\21,13,10]
PAUSE 1000
GOTO Loop
failr:
serout2 monport, mode,["failure to read",10,13]
return
failw:
serout2 monport, mode,["failure to write",10,13]
return
END
So your Hardware is OK.
There must be something wrong with your code.
regards
Ralph
_______________________________________________
There are only 10 types of people:
Those who understand binary, and those who don't ...
_______________________________________________
Hmm.. I am keeping trying to unravel this -- I have a version of your program, but it won't compile.. Can you tell my why I have a 'bad expression'??? It says the I2Cwrite, I2Cread commands are wrong.. I cannot for the life of me make them compile - defining X as a word, byte, whatever..
TG
'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?
' -----[ Fuses ]------------------------------------------------
@ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L
'
' -----[ Includes/Defines ]---------------------------------------------------------
include "modedefs.bas" 'include serout defines
OSCCON=%01111000
DEFINE OSC 8
While OSCCON.2=0:Wend
SCL var PortC.3 ' I2C Clock
SDA var PortC.4 ' I2C Data
ROM0 con %10100000 ' address of chip1
ADDR VAR word ' ROM Location
portout var PortC.6
portin var PortC.7
Mode con 16572 ' 4800 Baud 8N1 for Monitor Port
Test var byte[21] ' Test Array
I2Cdelay con 10 ' Delay after I2Cwrite
Temp var byte
X var byte
dta var byte
CLEAR
loop:
SEROUT2 portout,Mode,[13,10,"** MCU started",13,10,13,10]
serout2 portout, mode, ["enter 1 to write data, 2 to read it"]
serin2 portin, mode, [DEC temp]
select case temp
case 1
for X = 0 to 256
I2Cwrite SDA, SCL,ROMO,X,[X],failw
pause 10
next x
case 2
for x = 0 to 256
I2Cread SDA,SCL,ROMO,X,[X],failr
Serout2 portout, mode, ["Address: ",#addr," Data:",#dta]
pause 100
next x
end select
goto loop:
failr:
serout2 portout, mode,["failure to read",10,13]
return
failw:
serout2 portout, mode,["failure to write",10,13]
return
END
Bookmarks