TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430F6638主存储器储存数据的问题?

我往信息存储器中写数据可以按我设定的地址中写,比如我设定的地址是0X1800的D区,确实是写进D区了,但是我往主存储器中写数据时,我设置的起始地址时bank3的首地址038000H,为啥调试的时候显示的写在了08000H为首地址的区中呢?

Susan Yang:

请问您是如何写的?您现在是写在了Bank0吧?

您可以看一下下面的wiki页面,是使用

#pragma LOCATION( x , address );
int x;

或者 DATA_SECTION 来实现的

processors.wiki.ti.com/…/Placing_Variables_in_Specific_Memory_Location_-_MSP430

落笔:

回复 Susan Yang:

uchar *ADR =(uchar *)0x38000;//宏定义写入Flash的起始地址,位于bank3
//定义一个结构体
typedef struct
{uint year;uint monte;uint day;uint hour;uint minute;uint tube_num;uint lock_force;
}Flash_seg;

/*************************** 擦除FLASH ***************************/

void FlashErase(uchar *address)
{FCTL3 = FWKEY;while(FCTL3 & BUSY);FCTL1 = FWKEY + ERASE;*((uchar *)address) = 0;//将对应地址上的双字节数据擦除FCTL1 = FWKEY;FCTL3 = FWKEY + LOCK;while(FCTL3 & BUSY);
}

/*************************** 按字节写FLASH ***************************/
void FlashWrite(uchar *address,Flash_seg *word,uint count)
{FCTL3 = FWKEY;while(FCTL3 & BUSY);FCTL1 = FWKEY + WRT;uint temp = 0;for (uint i = 0;i < count;i++){memcpy(&temp,((uchar *)(word))+i,1);address[i] = temp;}FCTL1 = FWKEY;FCTL3 = FWKEY + LOCK;while(FCTL3 & BUSY);
}

int main( void )
{// Stop watchdog timer to prevent time out resetWDTCTL = WDTPW + WDTHOLD;lcd_init();Flash_seg p;p.year = 2019;p.monte = 06;p.day = 24;p.hour = 10;p.minute = 25;p.tube_num = 01;p.lock_force = 13;uint count = sizeof( Flash_seg);
Flash_seg *q = &p;show_int((*q).year);LCD_CLEAR();FlashErase(ADR);for(uint i = 0;i < 128;i+= 14) //存128个字节的数据{FlashWrite(ADR+ i,q,count);}
}

程序是这样的,定义的首地址是bank3结果写在了bank0,希望您能指点迷津。您给的链接我看明白

Susan Yang:

回复 落笔:

很抱歉,目前没有MSP430F6638的板子,所以我用MSP430F5529来测试了一下。

调试结果和程序如下

该程序首先擦除flash seg D,然后使用长字写入模式将32位值写入内存位置0x1800。

 

/* --COPYRIGHT--,BSD_EX* Copyright (c) 2012, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**********************************************************************************MSP430 CODE EXAMPLE DISCLAIMER** MSP430 code examples are self-contained low-level programs that typically* demonstrate a single peripheral function or device feature in a highly* concise manner. For this the code may rely on the device's power-on default* register values and settings such as the clock configuration and care must* be taken when combining code from several examples to avoid potential side* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware* for an API functional library-approach to peripheral configuration.** --/COPYRIGHT--*/
//******************************************************************************
//MSP430F552x Demo - Flash In-System Programming w/ Long-Word write at 0x1800
//
//Description: This program first erases flash seg D, then it writes a 32-bit
//value to memory location 0x1800 using long-word write mode. Long-word write
//provides faster write than byte/word mode.
//ACLK = REFO = 32kHz, MCLK = SMCLK = default DCO 1048576Hz
//
//MSP430x552x
//-----------------
///|\|XIN|-
//| ||
//--|RSTXOUT|-
//||
//
//
//Bhargavi Nisarga
//Texas Instruments Inc.
//April 2009
//Built with CCSv4 and IAR Embedded Workbench Version: 4.21
//******************************************************************************#include <msp430.h>int main(void)
{unsigned long * Flash_ptrD;// Initialize Flash pointer Seg Dunsigned long value;WDTCTL = WDTPW+WDTHOLD;// Stop WDTFlash_ptrD = (unsigned long *) 0x1800;// Initialize Flash pointervalue = 0x12345678;// Initialize ValueFCTL3 = FWKEY;// Clear Lock bitFCTL1 = FWKEY+ERASE;// Set Erase bit*Flash_ptrD = 0;// Dummy write to erase Flash segFCTL1 = FWKEY+BLKWRT;// Enable long-word write*Flash_ptrD = value;// Write to FlashFCTL1 = FWKEY;// Clear WRT bitFCTL3 = FWKEY+LOCK;// Set LOCK bitwhile(1);// Loop forever, SET BREAKPOINT HERE
}

 

落笔:

回复 Susan Yang:

您能实现往程序存储区出数据吗?

Susan Yang:

回复 落笔:

我试了一下,将value(0x12345678)写入MSP430F5529的Main: code memory Bank D

落笔:

回复 Susan Yang:

非常感谢您的耐心解答。我看到您写的了 ,我按照您的也重试了一遍,结果我往信息存储区写数据,写进去的区域是我设置的地址,可是我往主存储器中写数据时地址改变了?不是我想要写进去的地址?我用的平台是IAR,会不会是软件平台设置的影响呢?

1.这是往信息存储区写的数据,是正确的

2.这是往主存储区写数据,地址被修改了

3.存储器地址结构

落笔:

回复 灰小子:

的确是您说的这个问题,非常感谢

落笔:

回复 Susan Yang:

问题解决了,是IAR设置不正确导致,感谢您的帮助

赞(0)
未经允许不得转载:TI中文支持网 » MSP430F6638主存储器储存数据的问题?
分享到: 更多 (0)