打印
[MCU]

写入flash的数据和读出的不一致,为什么啊?

[复制链接]
238|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
laocuo1142|  楼主 | 2020-11-13 11:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
flash, se, TE, dc, TI
今天尝试 读写flash,改自TI官方代码,我准备了一个变量,可写入进去的和读出的不一致,请大家帮我看看。
void write_SegC (unsigned int *array)
{
  unsigned char *Flash_ptr;                          // Flash pointer
  Flash_ptr = (unsigned char *) 0x1040;              // Initialize Flash pointer
  FCTL1 = FWKEY + ERASE;                    // Set Erase bit
  FCTL3 = FWKEY;                            // Clear Lock bit
  *Flash_ptr = 0;                           // Dummy write to erase Flash segment
  FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

    *Flash_ptr++ = *array;                   // Write value to flash  }
  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}
void read (void)
{
  unsigned char *Flash_ptrC;                         // Segment C pointer
  unsigned char *Flash_ptrD;                         // Segment D pointer
  Flash_ptrC = (unsigned char *) 0x1040;             // Initialize Flash segment C pointer
  Flash_ptrD = (unsigned char *) 0x1000;             // Initialize Flash segment D pointer
  FCTL1 = FWKEY + ERASE;                    // Set Erase bit
  FCTL3 = FWKEY;                            // Clear Lock bit
  *Flash_ptrD = 0;                          // Dummy write to erase Flash segment D
  FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

    *value = *Flash_ptrC++;          // copy value segment C to segment D
  Nor_Val = value[0];
  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}

//时钟初始化
void  Clk_Init(void)
{
  if (CALBC1_8MHZ==0xFF)     // If calibration constant erased
  {           
    while(1);                               // do not load, trap CPU!!
  }
  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
  BCSCTL1 = CALBC1_8MHZ;                    // Set range
  DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */
  BCSCTL2 |=  SELM_1  + DIVM_3;
  FCTL2 = FWKEY + FSSEL0 + FN1;             // MCLK/3 for Flash Timing Generator
  //BCSCTL3 |= XT2S0 + LFXT1S0 + XCAP_3;      //配置ACLK匹配电容
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

980

主题

4028

帖子

10

粉丝