Internal EEPROM Read/write Addressing Errors with 18F PIC's


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358

    Default Internal EEPROM Read/Write Addressing Errors with 18F PIC's

    How do I get the internal EEPROM to store CORRECTLY into ALL loactions when using 18F series PICs?


    A lot of debate on does it work, or doesn't it work? on this topic.

    Yes, it DOES work. You need...

    1. PBP Version 2.45 or later.
    2. MPASM version v03.70 or later (part of MPLAB v6.50).

    Typical Command Line to execute your compilation...

    PBPW -p18F252 Myfile -ampasmwin

    Nothing special in your program... use DATA, READ and WRITE commands just as you do for all your other 12 and 16 series PICs. If you don't believe me, here's a test program for you to run...

    Code:
    	'	Program ETEST.BAS
    	'	=================
    	'	Writes incrementing values to internal EEPROM
    	'	until Doomsday (or until EEPROM wears out!)
    
    	'
    	'	Hardware Defines
    	'	================
    		'
    		' 	LCD Display
    		'	-----------
    	Define LCD_DREG PORTC	' Port for LCD Data
    	Define LCD_DBIT 4	' Use upper 4 bits of Port
    	Define LCD_RSREG PORTC	' Port for RegisterSelect (RS) bit
    	Define LCD_RSBIT 3	' Port Pin for RS bit
    	Define LCD_EREG PORTC	' Port for Enable (E) bit
    	Define LCD_EBIT 0	' Port Pin for E bit
    	Define LCB_BITS 4	' Using 4-bit bus
    	Define LCD_LINES 2	' Using 2 line Display
    	Define LCD_COMMANDUS 2000
    				' Command Delay (uS)
    	Define LCD_DATAUS 50	' Data Delay (uS)
    
    	'
    	'	EEPROM Presets
    	'	==============
    	Data @0,0,1,2,3,4,5,6,7,8,9
    	Data 10,11,12,13,14,15,16,17,18,19
    	Data 20,21,22,23,24,25,26,27,28,29
    	Data 30,31,32,33,34,35,36,37,38,39
    	Data 40,41,42,43,44,45,46,47,48,49
    	Data 50,51,52,53,54,55,56,57,58,59
    	Data 60,61,62,63,64,65,66,67,68,69
    	Data 70,71,72,73,74,75,76,77,78,79
    	Data 80,81,82,83,84,85,86,87,88,89
    	Data 90,91,92,93,94,95,96,97,98,99
    	'
    	Data 100,101,102,103,104,105,106,107,108,109
    	Data 110,111,112,113,114,115,116,117,118,119
    	Data 120,121,122,123,124,125,126,127,128,129
    	Data 130,131,132,133,134,135,136,137,138,139
    	Data 140,141,142,143,144,145,146,147,148,149
    	Data 150,151,152,153,154,155,156,157,158,159
    	Data 160,161,162,163,164,165,166,167,168,169
    	Data 170,171,172,173,174,175,176,177,178,179
    	Data 180,181,182,183,184,185,186,187,188,189
    	Data 190,191,192,193,194,195,196,197,198,199
    	'
    	Data 200,201,202,203,204,205,206,207,208,209
    	Data 210,211,212,213,214,215,216,217,218,219
    	Data 220,221,222,223,224,225,226,227,228,229
    	Data 230,231,232,233,234,235,236,237,238,239
    	Data 240,241,242,243,244,245,246,247,248,249
    	Data 250,251,252,253,254,255
    
    
    	'
    	'	Software Variables
    	'	------------------
    	CounterA var BYTE	' Address Pointer
    	CounterL var WORD	' Loop Counter
    	DataA var BYTE		' Read Data from/to EEPROM
    	DataB var BYTE		' Expected Data from EEPROM
    	DataOffset var BYTE
    
    	'
    	'	Program Constants
    	'	-----------------
    	MaxEEPROM con 255	' Top address limit of EEPROM
    
    	'
    	'	Initialise Program 
    	'	------------------
    	TRISC=%00000000
    	CounterL=0
    	Pause 1000
    	'
    	'	Load Offset
    	'	-----------
    Loop:
    	Read 0,DataOffset
    	'
    	'	Read and Verify EEPROM Bank (256 Bytes)
    	'	---------------------------------------
    	LCDOut $FE,1,"Reading=",#CounterL
    	Pause 500		' Need this to see above message
    	For CounterA=0 to MaxEEPROM
    		Read CounterA,DataA
    		DataB=CounterA+DataOffset
    		If DataA<>DataB then 
    			LCDOut $FE,1,"Error Loop=",#CounterL,$FE,$C0
    				'
    				' Displays EEPROM Address, Expected Data, Read Data
    				'
    			LCDOut "$",HEX2 CounterA," E=$",HEX2 DataB," R=$",HEX2 DataA
    			Pause 1000
    			endif
    		Next CounterA
    	'
    	'	Increment DataOffset and write-Out EEPROM
    	'	-----------------------------------------
    	CounterL=CounterL+1
    	LCDOut $FE,1,"Writing=",#CounterL
    	DataOffset=DataOffset+1
    	For CounterA=0 to MaxEEPROM
    		DataA=CounterA+DataOffset
    		Write CounterA,DataA
    		Next CounterA
    	Goto Loop		' Do it forever
    
    	End
    If it doesn't work for you, check the versions of PBP and MPASM you're running... MPASM is FREE (a component part of MPLAB), so download and install the latest version regularly from the Microchip website.

    Just a brief note on the operation of the above test program. If you Power-OFF your PIC whilst running this program during the WRITE cycle where it's filling the EEPROM with new values, the EEPROM contents will of course be corrupted. When you next Power-On, some values will be correct, and some will not be correct (the errors which will display accordingly on the LCD). Allow the program to complete it's READ cycle, it will then write-out a fresh EEPROM page which should then be read without error.

    Melanie

  2. #2
    Join Date
    Jun 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default On Board EEPROM - Read {address} above 255

    Hi Melanie,
    I was wondering if you could recommend a way to read an EE with an address above 255. It appears that the Read function is limited to 1 byte addressing. Even though I declare it a word. Have you found this to be true? F.Y.I. I am using 18f2620, And loving it.

    Thanks ash
    Sorry to bring up an old post.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it will work if you declare the Address variable as a word sized.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jun 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Hi Mr. E,
    I tried that but it did not work. It still loops back after address 255.

    I preload My eeprom with the EEPROM *reserved word

    eeprom 192,["11"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 208,["12"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 224,["13"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 240,["14"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 256,["15"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 272,["16"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 288,["17"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    eeprom 304,["18"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]

    Im sending each line to an lcd and it works fine but i cannot reach EEPROM 256. Even though my address is 256 or above. and again my address varible is a WORD, not a BYTE.



    Thanks Ash
    Last edited by atillotson; - 4th July 2005 at 16:09.

  5. #5
    Join Date
    Jun 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default That fixes it.

    Oh, Well guess what?

    ReadMenuData:
    x = 2
    for Z = Index4 to Index4 + 15
    read Z,sendlcd[x]
    x = x + 1
    next Z
    return

    Index4 is a word like i said but Z was a byte.
    I changed it to a word and wha-la

    Thanks for your help.
    That was a really stupid mistake on my part sorry for your troubles.

    ashman

  6. #6
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Cool Preloading the EEprom with the DATA Command is a problem

    Hi Melanie,

    Just thought I'd throw in my 2 cents on this topic. If someone wants to preload the EEprom during the programming phase using PBP's DATA command, there is a PIC18F series problem. Dummy bytes (0) need to be inserted, and the address needs to be doubled (see below).
    Code:
    DATA @0,$08,0,$FE,0,$0F     ' ATTR #00
    DATA @6,$03,0,$FE,0,$0F     ' ATTR #01
    DATA @12,$02,0,$80,0,$0F    ' ATTR #02
    DATA @18,$04,0,$0E,0,$0C    ' ATTR #03
    Although this looks kinda weird, it will compile properly into the EEprom. This is only a problem with the preload function, and only with the PIC18F series (as far as I know).

    This is a known bug by MEL, and they have acknowledged its existance.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. Read/write variable into PIC internal eeprom
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th August 2008, 07:06
  4. Multiple Pics accessing single EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd February 2008, 17:22
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts