AnsweredAssumed Answered

how to read and write eeprom for stm8s003k3

Question asked by pawar.prashant.003 on Jan 6, 2017
Latest reply on Mar 6, 2017 by Simon V.

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

Outcomes