gpt4 book ai didi

c - 未从 LPM3 唤醒,ACLK 故障

转载 作者:太空宇宙 更新时间:2023-11-04 04:41:11 24 4
gpt4 key购买 nike

我正在阅读 SoftBaugh MSP430 状态机编程一书中的第 5 章,但在开始时遇到了问题。我现在已经尝试过两次,删除项目并从上一章的解决方案重新开始,然后进行指定的更改。

程序运行到 while 循环,通过 __low_power_mode_3 并且之后不会继续,表明它永远不会从 LPM3 唤醒。

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

我们已经尝试了不同的板(MSP430F2274 评估板),它们都带有 USBP,并且只是连接到交流适配器。

这是我的代码:

主.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;
}

系统.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();
}

系统.h

最佳答案

事实证明,这是一个错误的 IAR 安装。也许驱动程序安装错误或其他原因。我在另一台机器上尝试了相同的步骤,程序运行正常,正如原始问题中所写的那样。

关于c - 未从 LPM3 唤醒,ACLK 故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26364945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com