EEPROM module woes

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Tom Estes
Registered User
Registered User
Posts: 37
Joined: Thu Dec 14, 2006 4:19 pm
Location: Monkey Island, Oklahoma USA

EEPROM module woes

Post by Tom Estes » Tue Feb 06, 2007 9:23 pm

I give up, am going to need some help. I'm having trouble with the following code

Code: Select all

Device = 18F252
Clock = 20

Include "USART.bas"
Include "EEPROM.bas"
Include "Convert.bas"

Dim TstValue As Word

USART.SetBaudrate(br9600) 
TstValue = 17932
EE.Write(0,TstValue)
While true
USART.Write(DecToStr(EE.ReadWord(0)),"W ")
USART.Write(DecToStr(EE.ReadByte(0)),"B ")
EE.Read(0,TstValue)
USART.Write(DecToStr(TstValue),"C ")
DelayMS(1000) 
Wend
TstValue is written to the EEPROM, I can read it from my programmer. For the life of me I cannot get a realtime read. As the code shows, I've tried reading as a byte, word, and compound. Everything returns 0. I must be doing something wrong?

By the way, I ran the example code, got the same results. Writes but no reads. The example has its own problems. It is named the same as the EEPROM module so it seems to include itself and the compiler can't find needed references. I solved that by renaming the expample code.

Something I don't have set up right on the 18F252 perhaps? I'm at a loss.....


TomE

Bruce
Posts: 16
Joined: Sun Oct 29, 2006 5:54 pm
Contact:

Post by Bruce » Wed Feb 07, 2007 4:57 pm

I ran your code as-is on an 18F252 & 18F452, and it works as expected.

However, when I try the same code on an 18F242, I get all 0's returned.

I'm using SF default config fuse settings.
Regards,

Bruce
http://www.rentron.com

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Wed Feb 07, 2007 6:01 pm

> ...It is named the same as the EEPROM module so it
> seems to include itself and the compiler can't find needed
> references. I solved that by renaming the expample code.

Sorry about that - the search path ordering was changed in the last update (documented) from

LIB->USERLIB->SOURCEFOLDER

to

SOURCEFOLDER->USERLIB->LIB

Hopefully you can see that this new search ordering has a number of benefits. I'll rename the sample file in question in the next release build.

> I give up, am going to need some help

Like Bruce, I tried this on a 18F252 and 18F452 without problems. The code is known to work on many other 18 series also.

However, what hardware silicon version is the MCU (you should be able to get this information from your hardware programmer). Revisions B2, B3, B4 and B5 had a problem which required EEDATA to be saved immediately after a read. If using older silicon, you might want to try the following

(a) Open ..\Swordfish\Library\EEPROM.bas
(b) Unlock the file for editing (double click on the padlock above the code windows)

Comment out the 'ReadByte' function and replace with this one

Code: Select all

public function ReadByte(pAddress as TAddress) as byte
   dim RD as EECON1.Booleans(0)
   EECON1 = $00
   RD = true
   result = EEDATA
   BackToFLASH
   inc(Address)
   ClrWDT
end function
There was also an error with C0 and C1 silicon, where RD could not be set immediately after writing to ADR, but this should not be a problem with the current library code or the code shown above.

Tom Estes
Registered User
Registered User
Posts: 37
Joined: Thu Dec 14, 2006 4:19 pm
Location: Monkey Island, Oklahoma USA

Post by Tom Estes » Wed Feb 07, 2007 6:35 pm

Thanks Bruce for taking the time to try the code.

Your results make me think it may be a silicon version issue. The errata sheets talk about special EEPROM read considerations. I tried several 252 and 452 chips but each had the same date code and they are old 2002-03 dates. All return 0.

TomE

Bruce
Posts: 16
Joined: Sun Oct 29, 2006 5:54 pm
Contact:

Post by Bruce » Wed Feb 07, 2007 6:38 pm

Spot-on Dave... :D

Works as expected with the modification - on the older silicon rev 18F242.
Regards,

Bruce
http://www.rentron.com

Tom Estes
Registered User
Registered User
Posts: 37
Joined: Thu Dec 14, 2006 4:19 pm
Location: Monkey Island, Oklahoma USA

Post by Tom Estes » Wed Feb 07, 2007 7:03 pm

Yup, that fixed it! Old silicon it was.....

Thanks David and Bruce for your support.

I love the compiler David, am really enjoying using it.

TomE

Post Reply