MSP430一个内部信息存储器读写一直不成功,调试时总是停在读取数据的中间,不知道原因在哪?附上程序请教各位,不胜感激!
#define SegmentStart 0x01000 //Segment = 0x01000~0x010FF
#define SegmentSize 255 //SegmentA + SegmentB = 256
void WriteSegment_256 (char index,char *value,char size);
char ReadSegment_256(char index);
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
SD16CTL = SD16REFON+SD16SSEL0; // 1.2V ref, SMCLK
SD16CCTL0 |= SD16SNGL + SD16DF; // Single conv
//SD16CCTL0 |= SD16SNGL; // Single conv
SD16INCTL0 |= SD16INCH0+SD16INTDLY_0;
while (1)
{
value=ReadSegment_256(1);
for (i = 0; i < 0x900; i++); // Delay
char str1[3]={0xAA,0xBB,0xCC};
WriteSegment_256(0,str1,3);
for(char i=0;i<255;i++)
_NOP();
// char str2[3]={0xBB,0xAA,0xCC};
// WriteSegment_256(0,str2,3);
}
}
//*********************************************************
//读取片内存储的数据
//*********************************************************
char ReadSegment_256(char index)
{
char *flash_ptr = ((char *) SegmentStart) + index;
return *flash_ptr;
}
// *****************************************************
//把数组写入数据到片内FLASH,必须先全部擦除再写入
//参数index:保存数组的位置
//参数value:数组的指针
//参数size:数组的大小
// *****************************************************
void WriteSegment_256 (char index,char *value,char size)
{
char buffer[SegmentSize],i=0;
char *flash_ptr = (char *) SegmentStart;
//先读取原FLASH数组
for(i=0;i<SegmentSize;i++)
buffer[i]=ReadSegment_256(i);
//擦除FLASH,必须
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*flash_ptr = 0; // Dummy write to erase Flash segment
//把整个数组都写入FLASH
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for(i=0;i<size;i++)//修改原数组
buffer[index+i]=value[i];
for(i=0; i<SegmentSize; i++)//写入数据到FLASH
*(flash_ptr++) = buffer[i];
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
|