EEPROM command writing two bytes instead one [Solved]

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

Hello!

Well, I´m stuck for one whole day trying to figure out by myself what is going wrong with this EEPROM with no luck. Probably, as usual, some silly newbie mistake.

I´m writing a value (0x0b) at EEPROM address 4 and this work ok, but has a collateral effect of destroying the next EEPROM address (5) with 0x00.

if (get_dtmf [0]==7) 
{
  eeprom_update_word (( uint16_t *) 4 , get_dtmf [1]);
}

Using attiny2313A with Atmel GCC.

Any idea what can be causing this behavior?

Thank you in advance.

Good Soldering JRGandara

Last Edited: Thu. Aug 7, 2014 - 01:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

eeprom_update_word() will update a uint16_t.
Obviously this will take two uint8_t bytes in the eeprom.

If you want to only write one byte, use eeprom_update_byte().

 eeprom_update_word (( uint16_t *) 3 , 0x4567);
 // will write 0x67 at location 3 (low)
 // and 0x45 at location 4 (high)
 // e.g.
 eeprom_update_byte (( uint16_t *) 3 , 0x67);
 eeprom_update_byte (( uint16_t *) 4 , 0x45);

David.

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

eeprom_update_word function writes two bytes. I guess that get_dtmf is array of unsigned bytes. When you call eeprom_update_word, data you pass is promoted to unsigned int by adding 0 as more significant byte and this 0 is written at the address 5.
To resolve your problem use eeprom_update_byte.

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

Also why use absolute addressing in the EEPROM - you don't do it in RAM (you used named variable locations and just let the linker actually place those for you) so why don't you do the same for EEPROM by assigning some variables to be "EEMEM"?

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

How I suspected since the beginning, something I misread. Yesterday I tried to search in the forum but I was always getting errors.

The code worked with a minor correction:

 eeprom_update_byte (( uint16_t *) 4 , 0x45);

This line causes the following warning message:

Passing argument 1 of '__eeupd_byte_tn2313a' from incompatible pointer type [enabled by default]

Changed to uint8_t and worked like charm.

The search worked today and I found an EEPROM tutorial and have mention about EEMEM which I never heard. I will check this function.

Thank you all for the usual great help.

Good Soldering JRGandara