cancel
Showing results for 
Search instead for 
Did you mean: 

Write u16 to EEPROM in STM8S003F3

Posted on September 08, 2016 at 13:22

What is the right procedure to write to EEPROM?

I saw the following code:

oid CEEPROM::UNLOCK_EEPROM_IF_LOCKED() 
{ 
if ( EEPROM_IS_WRITE_PROTECTED() )
{ 
FLASH_DUKR = 0xAE; 
FLASH_DUKR = 0x56; 
while (EEPROM_IS_WRITE_PROTECTED());
} 
}
void CEEPROM::LOCK_EEPROM() 
{
FLASH_IAPSR_DUL = 0; 
while( !EEPROM_IS_WRITE_PROTECTED() ); 
}
void CEEPROM::Write(unsigned short address, unsigned char data)
{
UNLOCK_EEPROM_IF_LOCKED();
*(unsigned char*)(address) = data;
LOCK_EEPROM();
}

but I doubt it.

3 REPLIES 3
luca239955_stm1_st
Senior II
Posted on September 08, 2016 at 15:08

what toolchain?

For Cosmic just write

@eeprom myEEpromVar;

myEEpromVar = 10;

and let the compiler (and libraries) do the work.

Posted on September 08, 2016 at 15:58

I work with IAR for STM8

Posted on August 18, 2017 at 03:47

What  c and h file you include ?? And where to find them ?? I am using Cosmic compiler.