writing a string to EEPROM

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

I have posted this in the EEPROM tutorial topic. It was later when i realized that if a person reads the tutorial topic, it is likely they are new at using EEPROM like myself. I apologize for the double post :oops:

I have a problem writing to EEPROM of atmega8515. I get a string send to parceInput but when i read the EEPROM all I get is ( ¼ ) that. If I put something in the EEPROM using EEMEM, reading it works just fine. Someone please explain how to write a string to EEPROM in one function and read it in another.
Here is the code I tried

uint8_t  EEMEM EEPROMString[10]; // this is before main()
void parceInput(char s[])
{
   if ((s[0] == 'r') && (s[1] == 'e') && (s[2] == 'a') && (s[3] == 'd'))
   {
      sendString("Reading EEPROM \r\n");
      readEEPROM(); // read whats in eeprom

   }
   else
   {
      sendString("Saving to EEPROM : ");
      sendString(s);
      sendChar('\r');
      sendChar('\n');
      eeprom_is_ready(); // dont know what this is, says in EEPROM.h to use it.
      eeprom_write_block((const void*)&s, (void*)&EEPROMString, 10);// write a string to the EEPROM
   }

}

// readEEPROM
void readEEPROM()
{

eeprom_is_ready();
uint8_t  SRAMstring[10];
eeprom_read_block((void*)&SRAMstring, (const void*)&EEPROMString, 10); // read whats in EEPROM
sendString((char *)SRAMstring);

}

Thanks in advance.

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

Watchdog timing out?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Just lose the '&' on '&s' in the call to eeprom_write_block(). s is already a pointer, you don't want to pass a pointer to a pointer

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

Thank you 8) It works now.