Programming AVR EEPROM

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to write a string to AVR8535 EEPROM memory:


#include 

char *string = " Welcome!ABCD";
int start_addr ; 

void main(void)
{
for (start_addr = 0x0010; *string != '\0'; start_addr++, string++)
{
    EEAR = start_addr;
    EECR.2 = 1;
    EECR.1 = 1;
    EEDR = *string;
    while (EECR.1 != 0);
}
}

But when I see the EEPROM memory I see it as below:

0010: 00 20 57 65 6C 63 6F 6D 65 21 41 42 43 FF FF FF | . Welcome!ABC...

Why is the 0x0010 address set to 00 and last character is not written at all?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have

     EEAR = start_addr; 
     EECR.2 = 1; 
     EECR.1 = 1; 
     EEDR = *string;
     while (EECR.1 != 0);
     while(EECR & (1<<EEWE)); //wait for write finished
     EEAR = start_addr;
     EEDR = *string;   //do this first! 
     EECR.2 = 1; 
     EECR.1 = 1; 
     

The write sequence & timing is critical. It always pays to follow the data sheet.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

Last Edited: Mon. Jan 13, 2014 - 08:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are setting the data register after you set the bits in the control register.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cross post, Happy New Year Johan!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks writing to data register first and then to control register works out perfectly. Thanks for your help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would a C programmer be worrying about EECR/EEDR/etc? I think all the AVR C compilers provide either implicit or explicit EEPROM support routines.

Which C compiler is this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I note the

EECR.2

way of referencing individual bits and speculate CodeVision.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it looks like CodeVision.

Yes, CV handles EEPROM natively.

No, the OP has obviously not worked out how to click on Help.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
No, the OP has obviously not worked out how to click on Help.

david, you are sure that in the latest version of codevision teh help button does not re-direct to this forum?
8)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tend to use the CodeVision IDE in preference to the AS6 IDE. Principally because the Search in Files, Terminal, Analysis etc is superior.

AS6 works pretty slowly on this laptop. "Visual Assist" cripples it terminally.

To find the CodeVision help:

CV IDE: Help Menu: Click Help (F1)
AS6 IDE: Help Menu: Click CodeVision Help

Pavel has put a lot of effort into providing Help, Examples etc. It is well worth using these facilities before coming to this Forum. Of course, you can always ask for explanation here.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Why would a C programmer be worrying about EECR/EEDR/etc? I think all the AVR C compilers provide either implicit or explicit EEPROM support routines.

Which C compiler is this?


Reading between the lines & using 8535 etc. , I assume that the OP is a university student and they may well be taught & be required to write their own functions rather than using libraries.
Some universities still require asm to be extensively taught.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Judging by the , it is probably a school assignment that only uses Proteus Simulation.

Mind you, the AVR data sheet has both ASM and C examples for low-level EEPROM programming.

A bright student only has to copy-paste it straight from the data sheet. Then change a bit of spelling so that teacher thinks it is all her own work.

You still need to add the relevant provisos about interrupts and brain-dead C compilers.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
A bright student only has to copy-paste it straight from the data sheet.

It is certainly no more difficult than Googling/Freaking, but it does requires some research & reading. After the X & Y & Z generation we are now going around the circle and have the G generation.
I notice that even doctors are Googling things!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?