请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LP-MSPM0G3507 工具与软件:
你好,我没有任何问题,而写入我的程序的假存储器。 但当我重置保存的数据时、无法读取它。 我在做什么错? 可以帮帮我吗?
#include "ti_msp_dl_config.h"
/* Address in main memory to write to */
#define MAIN_BASE_ADDRESS (0x00001000)
/* Counter variable to store the value in flash */
uint8_t counter = 0;
uint8_t counter_value;
uint8_t read_value=0x00;
uint8_t readed_value;
uint8_t error;
volatile DL_FLASHCTL_COMMAND_STATUS gCmdStatus;
/* Error codes */
#define NO_ERROR 0
#define ERROR_ERASE 1
#define ERROR_8BIT_W 2
volatile uint8_t gErrorType = NO_ERROR;
void writeValueToFlash(uint32_t address, uint8_t *value){
DL_FlashCTL_unprotectSector(
FLASHCTL, address, DL_FLASHCTL_REGION_SELECT_MAIN);
DL_FlashCTL_eraseMemory(
FLASHCTL, address, DL_FLASHCTL_COMMAND_SIZE_SECTOR);
DL_FlashCTL_waitForCmdDone(FLASHCTL);
DL_FlashCTL_unprotectSector(
FLASHCTL, address, DL_FLASHCTL_REGION_SELECT_MAIN);
DL_FlashCTL_programMemory8WithECCGenerated(
FLASHCTL, address, value);
counter_value=*value;
}
int main(void)
{
SYSCFG_DL_init();
DL_FlashCTL_unprotectSector(
FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
DL_FlashCTL_readVerifyFromRAM8WithECCGenerated(FLASHCTL, MAIN_BASE_ADDRESS, &read_value);
DL_FlashCTL_waitForCmdDone(FLASHCTL);
while (1) {
/* Increment the counter */
writeValueToFlash(MAIN_BASE_ADDRESS, &counter);
counter++;
delay_cycles(16000000);
}
}