Xmega Internal EEPROM

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

Hi.

I would like to use xmega internal eeprom so I downloaded the AVR1315.

I used code below and if I read from eeprom immediately after write it works fine but there is no data when I reset the xmega and  just read byte from eeprom !!!

any one can help me :( ?

    EEPROM_DisableMapping();

    /* Write bytes. */
    EEPROM_WriteByte(0, 0, 'N');

    /* Read back and check bytes.*/
    Putchar(EEPROM_ReadByte(0, 0));
This topic has a solution.
Last Edited: Fri. Sep 4, 2015 - 12:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! 

 

I read and write to xmega eeprom this way. I only needed a two bytes, so I use byte 0 and byte 1 of a page. This code can help you. In the main, I get the match address, increment it and write again. So everytime the project resets, the mach number is +1. This is for a mini-golf match game, but you can use as an example.  This implements the NVM driver of ASF (non-volatile memory)

 

#define EXAMPLE_PAGE 2
#define EXAMPLE_ADDR EXAMPLE_PAGE * EEPROM_PAGE_SIZE

int fn_get_partida(void);
void fn_set_partida(int numero);

void main(void)
{
    
    ...
    
    partido = fn_get_partida(); 
	fn_set_partida(partido+1);
    
    ...
}

int fn_get_partida()
{
	uint16_t tmp;
	uint8_t read_page[EEPROM_PAGE_SIZE];
	nvm_eeprom_read_buffer(EXAMPLE_ADDR,read_page, EEPROM_PAGE_SIZE);
	tmp = read_page[1] * 0x100;
	tmp += read_page[0];
	return tmp;
}
void fn_set_partida(int numero)
{
	uint8_t write_page[EEPROM_PAGE_SIZE];
	uint16_t tmp;
	tmp = numero & 0xFF;
	write_page[0] = tmp;
	tmp = numero & 0xFF00;
	tmp = tmp >> 8;
	write_page[1] = tmp;
	
	nvm_eeprom_load_page_to_buffer(write_page);
	nvm_eeprom_atomic_write_page(EXAMPLE_PAGE);
	
}
	

bye ,

Jorge.

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

I just use 

eeprom_update_byte((uint8_t*)(pointer), number) ;

 

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

Torby wrote:

I just use 

eeprom_update_byte((uint8_t*)(pointer), number) ;

 

 

exactly :-) Just use functions declared in eeprom.h :-) xmega is more complex than mega or tiny, uses nvm controller but everything is handled in these functions. You have to watch out for nvm mode switching because not every function knows if its set properly (i.e reading data from flash with functions ended with _P messes up if you have read signature bytes without setting nvm back to standard operation) but generally with eeprom it should be ok anyway :-)

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

My read signature code sets the NVM for what it's about to do. I also set up so I can read the eeprom as memory at 0x1000.

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for your consideration.

but I found the solution :D

the avr1315 code working fine but in atmel studio when I reprogram my micro it clear my eeprom ! so i just propram the flash of xmega and it is working now :)

 

 

 

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

Oh, yes. I've had trouble with that too. In the project settings, you can tell it to preserve eeprom.

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut.