Skip to main content
Visitor II
January 13, 2021
Question

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

  • January 13, 2021
  • 1 reply
  • 1064 views

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);

}

    This topic has been closed for replies.

    1 reply

    Visitor II
    January 19, 2021

    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);
    }