Skip to main content
prashant pawar
Visitor II
January 6, 2017
Question

how to read and write eeprom for stm8s003k3

  • January 6, 2017
  • 1 reply
  • 1539 views
Posted on January 06, 2017 at 14:57

void main()

{

GPIOB-> DDR |= (1<<2); //output

GPIOB-> CR1 |= (1<<2); //push-pull type output

// GPIOB-> DDR &= ~(1<<7); //input

// GPIOB-> CR1 |= (1<<7); //pull-up without interrupt

GPIOC-> DDR &= ~(1<<2)|(1<<3); //input

GPIOC-> CR1 |= (1<<2)|(1<<3); //pull-up without interrupt

//

/* Define FLASH programming time */

FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

/* Unlock Data memory */

FLASH_Unlock(FLASH_MEMTYPE_DATA);

/* Read a byte at a specified address */

add = 0x4000;

val = FLASH_ReadByte(add);

/* Program complement value (of previous read byte) at previous address + 1 */

val_comp = (uint8_t)(~val);

FLASH_ProgramByte((add + 1), val_comp);

/* Check program action */

val = FLASH_ReadByte((add + 1));

if (val != val_comp)

{

/* Error */

// OperationStatus = 0;

/* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */

/* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */

while (1)

{

}

}

}
    This topic has been closed for replies.

    1 reply

    Simon V.
    ST Employee
    March 6, 2017
    Posted on March 06, 2017 at 11:26

    Thank you for your code !

    It is helpful for the community.

    Regards,

    Simon

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.