msp430f5438a Information Flash Seg Write -- Chapter

Today we are going to study how to write information flash by using msp430f5438a.

The size of the information is 512 bytes (1800-19FF).

when you start to write, you have to choose which segment you want to write into. That is to say, once you choose the segment, you can't write others until you select the other ones.

Here are some sample for how to write:

 1 //=================== 0x1800 - 0x187f =========================
 2 // Input = Remote & TireSensor. Holds values to write to seg D
 3 //=============================================================
 4 void write_segD(void)
 5 {
 6   int i;
 7   bool Re_Enable=false;
 8   u8 *pFlash = (u8 *)0x1800;
 9   
10   if(__get_interrupt_state()!=0)
11   {
12     __disable_interrupt();                  // 5xx Workaround: Disable global
13                                             // interrupt while erasing. Re-Enable
14                                             // GIE if needed
15     Re_Enable = true;
16   }
17   
18   TPMS_RCU_Group.tp.Marker[0]=99;
19   while(BUSY&FCTL3);                    //Test BUSY
20   FCTL3 = FWPW;                         //Clear LOCK
21   FCTL1 = FWPW+ERASE;                   //Enable segment erase
22   *(unsigned int *)pFlash = 0;          // Dummy write to erase Flash seg
23   while(BUSY&FCTL3);                    //Test BUSY
24   FCTL1 = FWPW+WRT;                     //Enable write
25   
26   pFlash = (u8 *)0x1800;
27   for(i=0;i< sizeof(PowerSupplyTypeDef)-1;i++)
28     *pFlash++ = BatCalValue.buf[i];
29   
30   for(i=0;i<16;i++)
31     *pFlash++ = TPMS_RCU_Group.table[i];
32   
33   FCTL1=FWKEY;                          // WRT = 0
34   FCTL3=FWKEY+LOCK;                     // LOCK = 1
35   if(Re_Enable==true)
36   {
37     __enable_interrupt();
38   }
39 }
 1 //=================== 0x1880 - 0x18ff ==========================
 2 //  Input = credential value. Holds values to write to seg C
 3 //==============================================================
 4 void write_segC(void)
 5 {
 6   int i;
 7   bool Re_Enable = false;
 8   char * Flash_ptr;                             // Initialize Flash pointer
 9   Flash_ptr = (char *) 0x1880;
10   
11   if(__get_interrupt_state()!=0)
12   {
13     __disable_interrupt();                  // 5xx Workaround: Disable global
14                                             // interrupt while erasing. Re-Enable
15                                             // GIE if needed
16     Re_Enable = true;
17   }
18   
19   FCTL3 = FWKEY;                                // Clear Lock bit
20   FCTL1 = FWKEY+ERASE;                          // Set Erase bit
21   *(unsigned int *)Flash_ptr = 0;               // Dummy write to erase Flash seg
22   FCTL1 = FWKEY+WRT;                            // Set WRT bit for write operation
23   
24   for (i = 0; i < CredentialsLenth; i++)
25   {
26     *Flash_ptr++ = XSocket.Credential.buf[i];   // Write value to flash
27   }
28   FCTL1 = FWKEY;                                // Clear WRT bit
29   FCTL3 = FWKEY+LOCK;                           // Set LOCK bit
30   
31   if(Re_Enable==true)
32   {
33     __enable_interrupt();
34   }
35 }

However, read is more easy. and simple.

 1 //=========================================
 2 //          Get segD value
 3 //=========================================
 4 void read_segD(void)
 5 {
 6   u8 *pFlash=(u8*)0x1800;
 7   
 8   for(int i=0;i< sizeof(PowerSupplyTypeDef)-1;i++)
 9     BatCalValue.buf[i] = *pFlash++;
10   
11   for(int i=0;i<16;i++)
12     TPMS_RCU_Group.table[i] = *pFlash++;
13 }
 1 //=========================================
 2 //          Get seg C value
 3 //=========================================
 4 void read_segC(void)
 5 {
 6   int i;
 7   char * pFlash;
 8   pFlash = (char *) 0x1880;
 9   for(i=0;i<CredentialsLenth;i++)
10   {
11     XSocket.Credential.buf[i]=*pFlash++;
12   }
13 }

 

 

OK, enjoy, thank you!

 

转载于:https://www.cnblogs.com/lumao1122-Milolu/p/7873889.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MSP430F5438A学习板是一种用于学习和设计MSP430F5438A单片机的开发板。它包括了MSP430F5438A单片机的相关资料和资源,可以帮助用户学习和了解该单片机的操作和功能。根据引用,学习板的一些资料包括MSP430F5438a.pdf、MSP430F5438学习板原理图.pdf、MSP430开发板原理图和MSP430 32kHZ晶振.pdf。这些资料可以提供技术细节、引脚布局、原理图和其他相关信息,有助于用户在学习和设计过程中进行参考和调试。根据引用,还有MSP430F5438单片机室内空气净化监测板的ALTIUM硬件原理图和PCB源文件,这些文件可供学习和设计参考。 为了使用MSP430F5438A学习板,以下是一些可能的方法和步骤: 1. 首先,学习并了解MSP430F5438A单片机的一般端口操作,以及端口寄存器的组成。这些资料可以在MSP430F5438a.pdf和MSP430F5438学习板原理图.pdf中找到。 2. 接下来,查看学习板相应端口管脚的原理图,了解各个管脚的功能和连接方式。这可以在MSP430F5438学习板原理图.pdf和MSP430开发板原理图中找到。 3. 使用JTAG口将程序烧写进入MSP430F5438A单片机中。通过JTAG接口,可以将编写好的代码烧写到单片机中进行程序调试。具体的烧写方法可以参考MSP430F5438a.pdf中的相关章节。 4. 进行程序调试。当按下按钮K1或K2时,观察LED1和LED2是否有变化。这可以帮助测试和调试你的程序,确保它们按预期工作。你可以根据MSP430F5438学习板原理图和MSP430F5438a.pdf中的资料,了解按钮和LED的连接和操作方式。 总之,MSP430F5438A学习板是一个帮助学习和设计MSP430F5438A单片机的开发板。通过学习和参考相关资料,你可以了解端口操作、端口管脚的原理图、烧写程序以及进行调试的方法和步骤。希望这些信息对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值