没有从LPM3唤醒,ACLK出现故障

时间:2014-10-14 15:49:27

标签: c microcontroller msp430

我正在阅读SoftBaugh MSP430状态机编程手册中的第5章,但我很难入门。我现在已经尝试了两次,删除项目并重新开始使用上一章的解决方案,然后进行指示的更改。

程序运行到while循环,超过__low_power_mode_3并且在此之后不会继续,表明它从未从LPM3中唤醒。

我的导师和我将示波器放在引脚2.0和2.1上,但是我们看不到来自ACLK的任何信号。当我停止执行并查看寄存器时,我看到BCSCTL3显示故障。

我们尝试过不同的主板(MSP430F2274评估板)和USBP,并且只是连接到AC适配器。

这是我的代码:

的main.c

#include "System.h"
#include "msp430x22x4.h"

#define TICK_DIVISOR 64

static __no_init int mMain_nCounter;

void InitializeHW (void);
void InitializeApps (void);

int main( void )
{   
    // Stop watchdog timer to prevent time out reset
    WDTCTL = (WDTPW | WDTHOLD);

    InitializeHW();
    InitializeApps();
    __enable_interrupt();

    while(1){
        __low_power_mode_3();
        mMain_nCounter--;            //   <-- this never executes
        if (mMain_nCounter > 0){
            // count not expired yet
            continue;
        }
        //restart the counter
        mMain_nCounter = TICK_DIVISOR;
        // twiddle the LED
        P1OUT ^= (BIT0);
    }
}

void InitializeHW( void )
{   
    System_InitializeHW();
}

void InitializeApps( void )
{   
    mMain_nCounter = TICK_DIVISOR;
}

system.c

#include "msp430x22x4.h"
#include "System.h"

#define TICK_DIVISOR        32

void System_InitializePorts( void );
void System_SetupACLK_VLO( void );
void System_SetupTimerA3( void );
void System_SetupWatchdogTimer( void );

void System_InitializeHW( void )
{
    // Set 12.5 pF internal capacitance
    BCSCTL3 = (XCAP_3);

    System_InitializePorts();
//  System_SetupACLK_VLO();
    System_SetupTimerA3();
    System_SetupWatchdogTimer();
}

void System_InitializePorts( void )
{
    // Port1 initialization
    // P1.0 - D1
    // P1.1 - n/c
    // P1.2 - n/c
    // P1.3 - n/c
    // P1.4 - n/c
    // P1.5 - n/c
    // P1.6 - n/c
    // P1.7 - n/c
    P1OUT = (0x00);
    P1DIR = (0xFF);
    P1SEL = (0x00);

    // Port2 initialization
    // P2.0 - ACLK or n/c
    // P2.1 - SMCLK or n/c
    // P2.2 - n/c
    // P2.3 - n/c
    // P2.4 - n/c
    // P2.5 - n/c
    // P2.6 - XIN or n/c
    // P2.7 - XOUT or n/c
    P2OUT = (0x00);
    P2DIR = (0xFF);
//  P2SEL = (BIT7|BIT6|BIT1|BIT0);      // Enable XT1 and ACLK/SMCLK
    //P2SEL = (BIT7|BIT6);              // Enable XT1 only
    P2SEL = (BIT1|BIT0);                // Enable ACLK/SMCLK only
//  P2SEL = (0x00);                     // Enable neither

    // Port3 initialization
    // P3.0 - n/c
    // P3.1 - n/c
    // P3.2 - n/c
    // P3.3 - n/c
    // P3.4 - n/c
    // P3.5 - n/c
    // P3.6 - n/c
    // P3.7 - n/c
    P3OUT = (0x00);
    P3DIR = (0xFF);
    P3SEL = (0x00);

    // Port4 initialization
    // P4.0 - n/c
    // P4.1 - n/c
    // P4.2 - n/c
    // P4.3 - n/c
    // P4.4 - n/c
    // P4.5 - n/c
    // P4.6 - n/c
    // P4.7 - n/c
    P4OUT = (0x00);
    P4DIR = (0xFF);
    P4SEL = (0x00);
}

void System_SetupACLK_VLO( void )
{   unsigned char byShadowBCSCTL3;

    // Make sure XTS is clear
    BCSCTL1 &= ~(XTS);

    // Read the existing BCSCTL3 settings to the shadow
    byShadowBCSCTL3 = BCSCTL3;
    // Mask out the ACLK option bits
    byShadowBCSCTL3 &= ~(LFXT1S1|LFXT1S0);
    // Set the correct option for VLO
    byShadowBCSCTL3 |= (LFXT1S_2);
    // Update the register
    BCSCTL3 = byShadowBCSCTL3;
}

void System_SetupTimerA3( void )
{
    // Prepare the divisor
    TACCR0 = (TICK_DIVISOR-1);

    // Up Mode from ACLK
    TACTL = (TASSEL_1|ID_0|MC_1|TACLR);

    // Interrupt on CCR0
    TACCTL0 = (CCIE);
}

void System_SetupWatchdogTimer( void )
{
    // Configure the watchdog timer for 4 Hz interrupts from ACLK
    WDTCTL = (WDT_ADLY_250);

    // Defensively clear the WDT interrupt flag
    IFG1 &= ~(WDTIFG);

    // Enable the WDT
//  IE1 |= (WDTIE);
}

#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA_CCR0_ISR( void )
{
    // Wake the processor
    __low_power_mode_off_on_exit();
}

#pragma vector=WDT_VECTOR
__interrupt void WatchdogTimer_ISR( void )
{
    // Wake the processor
    __low_power_mode_off_on_exit();
}

system.h中

1 个答案:

答案 0 :(得分:0)

原来,这是一个错误的IAR安装。也许是一个坏的驱动程序安装或东西我在另一台机器上尝试了相同的步骤,程序运行正常,如原始问题中所述。