国产精品久久久久影院,成人午夜福利视频,国产精品久久久久高潮,国产精品 欧美 亚洲 制服,国产精品白浆无码流出

歷史上的今天

今天是:2024年10月23日(星期三)

正在發(fā)生

2019年10月23日 | msp430的DCO校準(zhǔn)值被清除后該如何處理

發(fā)布者:760802csy 來源: eefocus關(guān)鍵字:msp430  DCO  校準(zhǔn)值 手機(jī)看文章 掃描二維碼
隨時(shí)隨地手機(jī)看文章

起因

在調(diào)試MSP430G系列的單片機(jī)的過程,發(fā)現(xiàn)不怎么的,時(shí)鐘頻率發(fā)生了變化,時(shí)間一下都對不上了。查收些資料說,DCO的值有可能被擦除了導(dǎo)致時(shí)鐘不對的。細(xì)想一下,好像是在調(diào)試的過程中,出現(xiàn)調(diào)試不了的現(xiàn)象就在IAR里點(diǎn)擊的“Erase memory”。把查找的資料記錄下來,所以就有這篇文章。


問題描述

因?yàn)镈CO校準(zhǔn)值在MCU出廠時(shí)保存于信息段A,一般是不允許清除信息段A的。


且示例代碼中,有如下語句:


if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)     

    while(1);// If calibration constants erased

    // do not load, trap CPU!!

}

BCSCTL1 = CALBC1_1MHZ; // Set range

DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation 


可以看出在啟動(dòng)時(shí)都先檢查DCO1MHZ的校準(zhǔn)值是否為0xFF,是則進(jìn)入while(1)死循環(huán)。 

正常情況下因?yàn)樾畔⒍蜛不清除沒問題的,但是我測試BSL下載時(shí),故意給錯(cuò)誤的BSL密碼,導(dǎo)致FLASH都被擦除,發(fā)現(xiàn)轉(zhuǎn)載DCO校準(zhǔn)值的信息段A也被清掉了,于是程序運(yùn)行到上面的代碼時(shí)即進(jìn)入死循環(huán)。


解決辦法

針對于這種DCO數(shù)據(jù)被擦除的情況,一般的解決辦法是,通過利用Timer捕捉外部的32.768K晶振或是時(shí)鐘源,然后得到1M,8M或是12Mhz之類的DCO的數(shù)值,然后在直接寫入segment flashA里面。 

有兩個(gè)解決方案供選擇:


1、外接晶體,用晶體配合timer校正DCO,TI的msp4300ware有源代碼。如下:

 /*******************************************************************************

 * 

 *                       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--

//******************************************************************************/

//  MSP430G2xx1 Demo - DCO Calibration Constants Programmer

//

//  NOTE: THIS CODE REPLACES THE TI FACTORY-PROGRAMMED DCO CALIBRATION

//  CONSTANTS LOCATED IN INFOA WITH NEW VALUES. USE ONLY IF THE ORIGINAL

//  CONSTANTS ACCIDENTALLY GOT CORRUPTED OR ERASED.

//

//  Description: This code re-programs the G2xx1 DCO calibration constants.

//  A software FLL mechanism is used to set the DCO based on an external

//  32kHz reference clock. After each calibration, the values from the

//  clock system are read out and stored in a temporary variable. The final

//  frequency the DCO is set to is 1MHz, and this frequency is also used

//  during Flash programming of the constants. The program end is indicated

//  by the blinking LED.

//  ACLK = LFXT1/8 = 32768/8, MCLK = SMCLK = target DCO

//  //* External watch crystal installed on XIN XOUT is required for ACLK *//

//

//           MSP430G2xx1

//         ---------------

//     /||            XIN|-

//      | |               | 32kHz

//      --|RST        XOUT|-

//        |               |

//        |           P1.0|--> LED

//        |           P1.4|--> SMLCK = target DCO

//

//  A. Dannenberg

//  Texas Instruments Inc.

//  May 2010

//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 3.42A

//******************************************************************************

#include


#define DELTA_1MHZ    244                   // 244 x 4096Hz = 999.4Hz

#define DELTA_8MHZ    1953                  // 1953 x 4096Hz = 7.99MHz

#define DELTA_12MHZ   2930                  // 2930 x 4096Hz = 12.00MHz

#define DELTA_16MHZ   3906                  // 3906 x 4096Hz = 15.99MHz


unsigned char CAL_DATA[8];                  // Temp. storage for constants

volatile unsigned int i;

int j;

char *Flash_ptrA;                           // Segment A pointer

void Set_DCO(unsigned int Delta);


int main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  for (i = 0; i < 0xfffe; i++);             // Delay for XTAL stabilization

  P1OUT = 0x00;                             // Clear P1 output latches

  P1SEL = 0x10;                             // P1.4 SMCLK output

  P1DIR = 0x11;                             // P1.0,4 output


  j = 0;                                    // Reset pointer


  Set_DCO(DELTA_16MHZ);                     // Set DCO and obtain constants

  CAL_DATA[j++] = DCOCTL;

  CAL_DATA[j++] = BCSCTL1;


  Set_DCO(DELTA_12MHZ);                     // Set DCO and obtain constants

  CAL_DATA[j++] = DCOCTL;

  CAL_DATA[j++] = BCSCTL1;


  Set_DCO(DELTA_8MHZ);                      // Set DCO and obtain constants

  CAL_DATA[j++] = DCOCTL;

  CAL_DATA[j++] = BCSCTL1;


  Set_DCO(DELTA_1MHZ);                      // Set DCO and obtain constants

  CAL_DATA[j++] = DCOCTL;

  CAL_DATA[j++] = BCSCTL1;


  Flash_ptrA = (char *)0x10C0;              // Point to beginning of seg A

  FCTL2 = FWKEY + FSSEL0 + FN1;             // MCLK/3 for Flash Timing Generator

  FCTL1 = FWKEY + ERASE;                    // Set Erase bit

  FCTL3 = FWKEY + LOCKA;                    // Clear LOCK & LOCKA bits

  *Flash_ptrA = 0x00;                       // Dummy write to erase Flash seg A

  FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

  Flash_ptrA = (char *)0x10F8;              // Point to beginning of cal consts

  for (j = 0; j < 8; j++)

    *Flash_ptrA++ = CAL_DATA[j];            // re-flash DCO calibration data

  FCTL1 = FWKEY;                            // Clear WRT bit

  FCTL3 = FWKEY + LOCKA + LOCK;             // Set LOCK & LOCKA bit


  while (1)

  {

    P1OUT ^= 0x01;                          // Toggle LED

    for (i = 0; i < 0x4000; i++);           // SW Delay

  }

}


void Set_DCO(unsigned int Delta)            // Set DCO to selected frequency

{

  unsigned int Compare, Oldcapture = 0;


  BCSCTL1 |= DIVA_3;                        // ACLK = LFXT1CLK/8

  TACCTL0 = CM_1 + CCIS_1 + CAP;            // CAP, ACLK

  TACTL = TASSEL_2 + MC_2 + TACLR;          // SMCLK, cont-mode, clear


  while (1)

  {

    while (!(CCIFG & TACCTL0));             // Wait until capture occured

    TACCTL0 &= ~CCIFG;                      // Capture occured, clear flag

    Compare = TACCR0;                       // Get current captured SMCLK

    Compare = Compare - Oldcapture;         // SMCLK difference

    Oldcapture = TACCR0;                    // Save current captured SMCLK


    if (Delta == Compare)

      break;                                // If equal, leave "while(1)"

    else if (Delta < Compare)

    {

      DCOCTL--;                             // DCO is too fast, slow it down

      if (DCOCTL == 0xFF)                   // Did DCO roll under?

        if (BCSCTL1 & 0x0f)

          BCSCTL1--;                        // Select lower RSEL

    }

    else

    {

      DCOCTL++;                             // DCO is too slow, speed it up

      if (DCOCTL == 0x00)                   // Did DCO roll over?

        if ((BCSCTL1 & 0x0f) != 0x0f)

          BCSCTL1++;                        // Sel higher RSEL

    }

  }

  TACCTL0 = 0;                              // Stop TACCR0

[1] [2]
關(guān)鍵字:msp430  DCO  校準(zhǔn)值 引用地址:msp430的DCO校準(zhǔn)值被清除后該如何處理

上一篇:使用Energia開發(fā)MSP430 LAUNCHPAD學(xué)習(xí)筆記2--串口通信
下一篇:MSP430如何使用energia

推薦閱讀

雖然德國機(jī)器人只在這顆距離地球3億公里的小行星上只生存了17個(gè)小時(shí),但是它卻給3億公里外的地球人類傳送多張難以置信的圖片,向地球人類展現(xiàn)了一個(gè)沒有青山綠水的外星球世界。 這幾張幾乎只有兩種顏色的照片看起來就像是單色相機(jī)拍攝出來一樣??吹竭@些相片我突然有一個(gè)很怪的想法,把中國大熊貓拿來跟外星球環(huán)境搭配再適合不過了,因?yàn)槎贾挥泻诎咨?..
//------------2_8數(shù)碼管鍵調(diào)時(shí)帶小數(shù)點(diǎn)功能#include<iom128v.h>#define uchar unsigned char#define uint unsigned int#define P0_1 PORTA |= (1<<0)#define P0_0 PORTA &=~ (1<<0)#define P1_1 PORTA |= (1<<1)#define P1_0 PORTA &=~ (1<<1)#define P2_1 PORTA |= (1<<2)#define P2_0 PORTA &=~ (1<<2)#define P3_1 P...
安全身份認(rèn)證、銀行卡和交易技術(shù)解決方案供應(yīng)商Entrust今天宣布推出Sigma 桌面型即時(shí)發(fā)卡解決方案,這是一個(gè)創(chuàng)新的直印技術(shù)發(fā)卡解決方案,適用于實(shí)體卡即時(shí)發(fā)卡和移動(dòng)端證卡發(fā)行。 Sigma解決方案專為遠(yuǎn)程打印和現(xiàn)場發(fā)卡而設(shè)計(jì),為企業(yè)、醫(yī)療保健、政府、高等教育和金融機(jī)構(gòu)實(shí)施簡單、安全、智能化的即時(shí)發(fā)卡解決方案樹立了標(biāo)準(zhǔn)。當(dāng)今企業(yè)面臨著無數(shù)的安全...
據(jù)外媒報(bào)道,奧迪一直在尋求創(chuàng)新,最近該公司開發(fā)帶自發(fā)光屏幕元件的顯示裝置。就像科幻電影中將圖像投影到玻璃表面,奧迪創(chuàng)造了一種將汽車擋風(fēng)玻璃變成電影院的方法。(圖片來源:carbazz)奧迪對該發(fā)明的解釋是:“自發(fā)光屏幕元件(screen element)的顯示表面,通過彎曲區(qū)分為第一和第二顯示區(qū)。選擇性屏蔽單元沿優(yōu)先方向傳輸來自屏幕元素的光,并沿阻...

史海拾趣

小廣播
設(shè)計(jì)資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機(jī)文章

 
EEWorld訂閱號

 
EEWorld服務(wù)號

 
汽車開發(fā)圈

 
機(jī)器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號 京ICP備10001474號-1 電信業(yè)務(wù)審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved