R
R
RiffKazan2012-08-18 22:14:58
Do it yourself
RiffKazan, 2012-08-18 22:14:58

Confused with launchpad?

Started mastering launchpad-a. I tried to make a PWM program for a button-driven LED. I ran into a problem that somehow the board reacts incorrectly to the s2 button connected to the p1.3 leg, the
simplest code

#include "io430.h"

void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT6; //P1.6 назначаем выходом, т.к. там светодиод
P1DIR &= ~BIT3; //P1.3 назначаем входом, т.к. там кнопка
P1REN |= BIT3; //подключаем внутр. резистор к P1.3 и к +
//Теперь на P1.3 высокий уровень всегда, пока кнопка НЕ нажата
while(1)
{
//Если кнопка нажата на P1.3 будет логич. 0
if((P1IN & BIT3) == 0)
P1OUT |= BIT6; //Включаем светодиод
else
P1OUT &= ~BIT6; //Отпустили кнопку - выкл. светодиод
}
}

This code doesn't work correctly. After the reset, the LED just lights up and does not respond to the button.
Instead of io430.h, I tried both io430g2553.h and msp430g2553.h
during debugging, the P1IN value remains unchanged, regardless of whether the s2 button is pressed or not.
Z.s. In an absolutely incomprehensible way, the board, which was simply disconnected from USB, and then reconnected, began to work as it should. Another program was flashed (with PWM) - it does not work again. The above is flashed again - and again it does not work, after 5-6 disconnections-connections from USB - it starts working. That beats me))

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
constv, 2012-08-23
@constv

in the examples for MSP430 for connecting internal resistors such a sequence

// Configure Switch on P1.2
P1REN |= BIT2; // P1.2 Enable Pullup/Pulldown
P1OUT = BIT2; // P1.2 pullup

R
RiffKazan, 2012-08-18
@RiffKazan

Hmmm... I don't know how to explain it, but the problem was solved by adding P1OUT |= BIT3; before P1REN |= BIT3;

V
Vladimir Chirkin, 2012-08-20
@shtirlitsus

some bits do not take fixed values ​​when power is applied. they need to be forced to initialize. On pic controllers, for example, there is a separate table showing which bits take on which values ​​when reset or power is applied. some are forced not to change. I think the msp430 should have a similar table. you have to look there.

B
Barcooler, 2014-10-23
@Barcooler

Depending on the version of Launchpad, the layout of the buttons is different, in the first versions (up to 1.4, it seems) pull-up resistors were used, in the latter they were excluded from the circuit and the pull-up had to be done programmatically.
By the way, this can be seen from the examples for different versions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question