Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   read/write EEPROM on 18F8520 (http://www.chiefdelphi.com/forums/showthread.php?t=22655)

Random Dude 21-01-2004 22:21

Re: read/write EEPROM on 18F8520
 
Quote:

Originally Posted by Paul
It did help out, however there is one problem. When I write to the eeprom and try to play back from it using the readEE function it doesn't seem to work. I think my memory addresses are off. Would this be an acceptable way of using the writeEE function?
writeEE(0x00,somechar);
or would i have to write it like this?
write(&0x00,somechar);
Thanks for clearing some of the other stuff for me.


The former:

writeEE(0x00,somechar);

WizardOfAz 21-01-2004 23:29

Re: read/write EEPROM on 18F8520
 
Quote:

Originally Posted by Paul
It did help out, however there is one problem. When I write to the eeprom and try to play back from it using the readEE function it doesn't seem to work. I think my memory addresses are off. Would this be an acceptable way of using the writeEE function?
writeEE(0x00,somechar);
or would i have to write it like this?
write(&0x00,somechar);
Thanks for clearing some of the other stuff for me.

Like RandomDude says, it's writeEE(0x00, somechar);

But a couple more comments.

Make sure you've included eeprom.h, since without the function prototype, the 0x00 may push a byte on the stack for the address parameter.

Also, note that doing the write takes time, several milliseconds. If you do a writeEE immediately followed by readEE it won't work. If you'd like to send a bigger code sample I'll be happy to look at it.

Bill

Paul 22-01-2004 14:49

Re: read/write EEPROM on 18F8520
 
Quote:

Originally Posted by WizardOfAz
Like RandomDude says, it's writeEE(0x00, somechar);

But a couple more comments.

Make sure you've included eeprom.h, since without the function prototype, the 0x00 may push a byte on the stack for the address parameter.

Also, note that doing the write takes time, several milliseconds. If you do a writeEE immediately followed by readEE it won't work. If you'd like to send a bigger code sample I'll be happy to look at it.

Bill

Thanks, I'll continue working on the problem I'm having. If I still don't have any luck I'll be sure to post that part of the code.

zeep25 14-02-2004 15:38

Re: read/write EEPROM on 18F8520
 
I used the code that Wizard posted in the second page and im having a little problem ... i added the eeprom.c and eeprom.h ... and included them ... this is my code right now :

Code:

int i=0;
int g=999;
void Default_Routine(void)
{
  if (i==0)
    {
    writeEE(0x00, "23");
    i=1;
    printf("----- %d \n",i);
    }
    else
    {
    g=readEE(0x00);
    printf("----- %d \n",g);
    }

} /* END Default_Routine(); */

i even tried changing the code into :

Code:

int i=0;
void Default_Routine(void)
{
  if (i==0)
    {
    writeEE(0x00, "23");
    i=1;
    printf("----- %d \n",i);
    }
    else
    {
    printf("----- %d \n",readEE(0x00));
    }

} /* END Default_Routine(); */

in the console window i see the i = 1 meaning that it went over the writing code and hopefully wrote the value in 0x00 ... but when it tries to read ... it shows the output as 0 ... for some reason its not writing to 0x00 block ... thats what im thinking .. any suggestions ?? comments

gnormhurst 15-02-2004 20:44

Re: read/write EEPROM on 18F8520
 
Quote:

Originally Posted by zeep25
I used the code that Wizard posted in the second page and im having a little problem ... i added the eeprom.c and eeprom.h ... and included them ... this is my code right now :

Code:

...
    writeEE(0x00, "23");


writeEE expects an "unsigned char" type for the data item, but you are passing a string literal (due to the quotations). Try this:

Code:

    writeEE(0x00, 23 );
Note also that writing to flash is not instantaneous -- the value won't be ready to read for some period of time. You should also included a call to

Code:

  processEEqueue();
somewhere in the main 26.2 ms loop.

-Norm

gnormhurst 15-02-2004 20:50

Re: read/write EEPROM on 18F8520
 
A HUGE THANKS! to Random Dude and Wizard of AZ for this code. It works great, and it saved me HOURS, nay, DAYS of work. And I really needed it. I bet a lot of people do.

-Norm

Paul 15-02-2004 21:45

Re: read/write EEPROM on 18F8520
 
Wow... I just wanna say thank you for including that little part about the processEEqueue(); I know from experience what happens when you don't include that little bit of code lol.... my edubot went in circles randomly haha. Thanks for the nifty little bit of code. :D

WizardOfAz 16-02-2004 01:12

Re: read/write EEPROM on 18F8520
 
Glad the code is of use to some teams. And sorry I didn't respond sooner. I actually went 24+ hours w/o reading email.

The "23" as a parameter will have caused a problem. That causes a pointer (address) to the string to be passed, not even close to what you want. And the first byte of the address was probably a zero, resulting in writing zero to that EE address.

Make sure to use
#include "eeprom.h"
which would have caught that mistake, since the compiler would have know that an unsigned char should be passed and you passed a pointer to char.

If you're going to write just one byte per 26 ms loop, you actually don't need to call processEEQueue, since writeEE itself calls it. Only if you call writeEE multiple times in quick succession (in a single loop) should you have to call processEEQueue. In your example, since you called writeEE in one loop then readEE in subsequent loops, except for the issue with "23" it should have worked.

Bill

nov787 21-03-2004 16:40

Re: read/write EEPROM on 18F8520
 
Are you guys using EEPROM for CopyCat or other purposes?

WizardOfAz 22-03-2004 13:32

Re: read/write EEPROM on 18F8520
 
Quote:

Originally Posted by nov787
Are you guys using EEPROM for CopyCat or other purposes?

We use it this year for two things. First, the way our steering position sensors are set up, we have to know how the wheels were steered when the bot was turned off in order to avoid a recalibration sequence when we power on. So we store the steering position in EEPROM every 5 seconds when it is changing.

Second, we have an 8 bit code that indicates how we want to run autonomous mode in the upcoming game, and an OI interface for setting it. This mode byte gets stored in EEPROM so we can power down after setting it but still remember run the correct autonomous mode in the game.

Last year we had a program that would save driver inputs to EEPROM during a driver period and play it back autonomously, but didn't rewrite that one this year.

Bill


All times are GMT -5. The time now is 21:47.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi