Author Topic: MSP430FR5969 Question(s)  (Read 3163 times)

0 Members and 1 Guest are viewing this topic.

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
MSP430FR5969 Question(s)
« on: March 25, 2017, 03:24:51 pm »
Hi,

I am dealing with a problem which is about msp430 launcher's button. I have written this code which is below. When I debug it, P1IN register changes stupidly. (with or without pressing button) I can not read exact value of P1IN.

Why does it behavior like that?

Code: [Select]
#include <msp430.h>

volatile unsigned int i;//to prevent optimization

void main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                            // to activate previously configured port settings
    P1DIR |= 0x01;                          // Set P1.0 to output direction
    P1REN  = 0x00;


    for(;;)
    {


       if(P1IN == 0)
           P1OUT = 0x01;//BIT 0 LED ON
       else
        P1OUT = 0X00;//LED OFF
    }
}
« Last Edit: March 25, 2017, 03:51:50 pm by Karamel »
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: MSP430FR5969 Question(s)
« Reply #1 on: March 25, 2017, 04:48:41 pm »
Remember that those registers are bytes, with 8 bits associated with 8 physical pins. When you set P1REN to 0, you turned off the internal resistors for all 8 of those pins. That means any of those 8 pins set for input are floating (likely producing random values) if they aren't connected to anything. That probably includes your button switch if it doesn't have an external pullup/down.

That also means "if (P1IN == 0)" is actually saying "if ANY of the input pins on P1 are non-zero, return false". I suspect that's not what you wanted.

Similarly setting P1OUT = 0 is turning off all outputs on P1. (And would affect resistor usage on inputs, if resisters were enabled.) Since you only have one pin set for output, you sorta get away with this one right now, but it'll get you in trouble later.
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: MSP430FR5969 Question(s)
« Reply #2 on: March 25, 2017, 06:42:29 pm »
Code: [Select]
#include <msp430.h>

volatile unsigned int i;//to prevent optimization

void main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                            // to activate previously configured port settings
    P1DIR |= 0x01;                          // Set P1.0 to output direction
    P1REN  = 0xFF;
    P1OUT = 0x00;


    while(1);
}

I changed my code like that, I am, now, debuging and still it changes stupidly when it is on while infinite loop. I try to get button press information from P1.1 and wanna show it on P1.0 pin.

Could you write this code to try on mine board? Maybe, my board has broken down. I don't know.

 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: MSP430FR5969 Question(s)
« Reply #3 on: March 25, 2017, 07:05:21 pm »
But does the single bit you care about change stupidly?

if ((P1IN & 0x02) == 0) // Test BIT 1
    P1OUT |= 0x01; // BIT 0 LED ON
else
    P1OUT &= 0xFE; // BIT 0 LED OFF
« Last Edit: March 25, 2017, 07:27:03 pm by Nusa »
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: MSP430FR5969 Question(s)
« Reply #4 on: March 25, 2017, 07:22:28 pm »
what does mean? P1OUT != 0x01; // BIT 0 LED ON
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: MSP430FR5969 Question(s)
« Reply #5 on: March 25, 2017, 07:28:13 pm »
Meant |=
Stupid typo....fixed it.
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: MSP430FR5969 Question(s)
« Reply #6 on: March 25, 2017, 07:47:51 pm »
Code: [Select]
void Delay()
{
    i = 1000;                               // SW Delay
    do i--;
    while(i != 0);
}

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                            // to activate previously configured port settings

   // P4DIR = 0x00;
   // P4REN = 0xFF;
   // P4OUT = 0xFF;

    P1DIR = 0x01;
    P1REN = 0xFF;
    P1OUT = 0xFF;

    while(1)
    {
        while((P1IN & 0x02) == 0) // Test BIT 1
        {
            Delay();
            if((P1IN & 0x02) == 1){
                P1OUT ^= 0x01; // BIT 0 LED ON
            }
        }
    }
}

I can, now, recognize its pressing down but why it doesn't toggle led?
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: MSP430FR5969 Question(s)
« Reply #7 on: March 25, 2017, 07:56:08 pm »
I solved it like that,
Code: [Select]
    while(1)
    {
        while((P1IN & 0x02) == 0) // Test BIT 1
        {
            Delay();
            while((P1IN & 0x02) == 0);
            Delay();
            P1OUT ^= 0x01; // BIT 0 LED ON
        }
    }
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf