我有一块M453开发板,买了一本《ARM Cortex-M4微控制器原理与实践》。
书上有读写Data Flash的例程,如下:
#include "stdio.h"
#include "M451Series.h"
#include "Common.h"
#include "Typedef.h"
#include "SmartM_M4.H"
#define DATAFLASH_START_ADDRESS 0x3f800
int32_t main(void)
{
UINT32 i=1;
UINT32 buf[10]={'0','1','2','3','4','5','6','7','8','9'};
SYS_UnlockReg();
SYS_Init(PLL_CLOCK);
UART0_Init(115200);
printf("\n\n");
printf("+-----------------------------------------------------+\n");
printf("| SmartM-M451 FMC Data Flash \r\n");
printf("+-----------------------------------------------------+\n");
printf("\r\nData Flash Write:0~9\r\n");
FMC_Open();
FMC_Erase(DATAFLASH_START_ADDRESS);
for(i=0;i<10;i++)
{
FMC_Write(DATAFLASH_START_ADDRESS+i*4,buf[i]);
}
memset(buf,0,sizeof buf);
printf("\r\nData Flash Read:");
for(i=0;i<10;i++)
{
buf[i]=FMC_Read(DATAFLASH_START_ADDRESS+i*4);
printf("%c ",buf[i]);
}
FMC_Close();
while(1)
{
}
}
写入的是0到910个数,可是读出来都是ff。请高手指教,哪里错了?谢谢!
|