cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am using stm8l001j3m3. In my project i can't write to eeprom. How can i do it?

mniza.1
Associate

My code as a below;

void EEPROM_WriteByte(unsigned int address, unsigned char value)

{

FLASH->DUKR = 0xAE;

FLASH->DUKR = 0x56;

(*(uint8_t *)(0x9FC0 + address)) = value;

FLASH->IAPSR &= FLASH_MemType_Data;

}

unsigned char EEPROM_ReadByte(unsigned int address)

{

unsigned char *ptr = (uint8_t *)(0x9FC0 + address);

return (*ptr);

}

1 REPLY 1
WilkoL
Senior

While I don't know the STM8L001, this is how I do it with a STM8S103

void save_byte_eeprom(uint8_t *location, uint8_t data)
{
	FLASH_Unlock(FLASH_MEMTYPE_DATA);
	
	FLASH_EraseByte((uint32_t) location);
	DELAY_ms(20);
	FLASH_ProgramByte((uint32_t) location, data);
	DELAY_ms(20);
	FLASH_Lock(FLASH_MEMTYPE_DATA);
}