简体   繁体   English

MSP430 LED 完全不闪烁

[英]MSP430 LED Not Blinking At All

I've been trying to turn on the LEDs on my MSP430G2553 and it just doesn't work.我一直在尝试打开 MSP430G2553 上的 LED,但它不起作用。 I've tried the code examples from TI, the pre-generated code composer studio LED blinking project, and even previous code that worked on an MSP430 from the past.我已经尝试过来自 TI 的代码示例、预生成的代码编写器工作室 LED 闪烁项目,甚至是以前在 MSP430 上工作的代码。 None of them seem to work.它们似乎都不起作用。 What could be the problem?可能是什么问题呢? Could it be faulty hardware?会不会是硬件故障? Here's my code:这是我的代码:

#include  <msp430.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= 0x01;                            // Set P1.0 to output direction

  for (;;)
  {
    volatile unsigned int i;
    volatile unsigned int j;

    P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR

    i = 25000;                              // Delay
    while(i--) {
       j = 2;
       while(j--);
    }
  }
}

Can you try this version (still a polling loop, but let's keep it very basic)? 您可以尝试使用此版本(仍然是轮询循环,但让它保持非常基础)吗?

#include <msp430.h>

int main(void) {
  volatile int i;
  WDTCTL = WDTPW | WDTHOLD;
  P1DIR |= 0x01;
  P1OUT = 0x00;

  for (;;) {
    P1OUT ^= 0x01;
    for (i = 0x6000; i > 0; i--) { };
  }
  return 0;
}

I took this from one of my old examples when I used the MSP430 in 2010... 我在2010年使用MSP430时是从一个旧示例中得出的...

Try replacing your while loop with __delay_cycles(1000000); 尝试用__delay_cycles(1000000);替换while循环__delay_cycles(1000000); .

Compilers can optimize-out empty loops even if the loop variable is marked as volatile . 即使循环变量被标记为volatile编译器也可以优化空循环。

#include  <msp430.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= 0x01;                            // Set P1.0 to output direction

  for (;;)
  {
    P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR

    __delay_cycles(1000000);
  }
}

I encountered a problem with the MSP430FR5994 dev board where the LEDs wouldn't turn on for the blinky example but they would turn on for the "Out Of Box Experience" project. 我遇到了MSP430FR5994开发板的问题,在闪烁的示例中LED不会打开,但在“开箱即用体验”项目中它们会打开。 Comparing the code, I determined that the difference is this line from pmm.c: 比较代码,我确定与pmm.c的区别在于:

//For FRAM devices, at start up, the GPO power-on default
//high-impedance mode needs to be disabled to activate previously
//configured port settings. This can be done by clearing the LOCKLPM5
//bit in PM5CTL0 register
PM5CTL0 &= ~LOCKLPM5;

Putting that at the top of main() seems to fix whatever the issue is and the LEDs behave as expected. 将其放在main()的顶部似乎可以解决所有问题,并且LED的行为符合预期。

After a reset, all port pins are high-impedance with Schmitt triggers and their module functions disabled to prevent any cross currents.复位后,所有端口引脚都处于高阻抗状态,施密特触发器和它们的模块功能被禁用以防止任何交叉电流。 Even if you have made all the necessary GPIO settings, you need to clear LOCKLPM5 bit in the PM5CTL register (described in the I/O Configuration After Reset chapter TI User Guide)即使您已经进行了所有必要的 GPIO 设置,您也需要清除 PM5CTL 寄存器中的 LOCKLPM5 位(在 I/O Configuration After Reset 章节 TI 用户指南中进行了描述)

PM5CTL0 &= ~LOCKLPM5;

until then, the I/Os remain in their high-impedance state with Schmitt trigger inputs disabled.在此之前,I/O 将保持在其高阻抗 state 中,并且禁用施密特触发器输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM