Forums

help with msp 430 interface and dip-switches

Started by bcincin November 28, 2007
1- I got a board with dip-switches. How do they work? What do they use for?


2- I'm tring to do a c# interface to change baud rate of msp430 but it
does not work properly. I got a blinking led to see if it works fine. The
problem is, when i change baud rate, led stops blinkind. When I set change
it back to initial baud rate, led starts blinking again 

Code: 
#include <msp430x16x.h> 
void checkMes (char ); 
void delay(); // delay 
void blinker(); // blink led 
char message; // check received data 
volatile unsigned int delm=1; // # of delays 
volatile int t=0; // led's not blinking when it is 0 
volatile int m=0; 
volatile int baud; // msp430 baud speed 



void main(void) 
{ 
WDTCTL = WDTPW + WDTHOLD; // Stop WDT 
P3SEL |= 0xC0; // P3.6,7 = USART1 option select 
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD 
  

UCTL1 |= CHAR; // 8-bit character 
UTCTL1 |= SSEL0; // UCLK = ACLK 
UBR01 = 0x0D; // 32k/2400 - 13.65 
UBR11 = 0x00; 
UMCTL1 = 0x6B; // Modulation 
UCTL1 &= ~SWRST; // Initialize USART state machine 
IE2 |= URXIE1; // Enable USART1 RX interrupt 

            
P1DIR |=BIT0; 


P1OUT =~BIT0; 
// Mainloop 

for(;;){ 
_BIS_SR(LPM3_bits + GIE); 

#if 1 
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? 

TXBUF1 = message; 
#endif 

while (t==0){ 
 // Enter LPM3 w/interrupt 

checkMes (message); //check command message coming from interface 

while (t==1) 
blinker();  //start blinking the light 


} 

} 
} 
  

#if 1 
// UART1 RX ISR will for exit from LPM3 in Mainloop 
#pragma vector= USART1RX_VECTOR 
__interrupt void usart1_rx (void) 
{ 
 _BIC_SR_IRQ( LPM3_bits) ;// Clear LPM3 bits from 0(SR) 
 t=0; 
 message=RXBUF1; 
  
} 

#endif 

void delay() //changes the blinking speed of led 
{ 
  unsigned int i; 
  i=10000; 
  while(i>0) 
    i--; 
} 


void blinker ()     // blinks led 
{ 
  while (t==1){ 
    int i=delm; 
    P1OUT ^=BIT0; 
    while (i>0)    // waits for delay 
    { 
      i--; 
      delay(); 
    }  
  } 
} 


void checkMes (char m) 
{ 
  char c2; 
  int com;  
  
  
  
  if ((m & 0x80) == 0x80)  //Check if it is blink command 
  { 
    if ((m & 0x10) == 0x10){    //check if it is blink button 
      t=1; 
      blinker(); 
     } 
    else      // # of delays 
    { 
      c2=(m & 0x07); 
      delm=c2;          
     t=1; 
    } 
  } 
  else     // it is configuration 
  { 
   t=2; 
    com = (m & 0x03);   //check baud rate 
        switch(com){ 
       case '1': // set baud rate 2400 
                IE2=0x00; 
                ME2=0x00; 
                UCTL1=0x01; // Software reset 
                UCTL1 |= CHAR; // 8-bit character 
                UTCTL1 |= SSEL0; // UCLK = ACLK 
          UBR01=0x0D; 
          UBR11=0x00; 
          UMCTL1=0x6B; 
                ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD 
                UCTL1 &= ~SWRST; // Initialize USART state machine 
                IE2 |= URXIE1; // Enable USART1 RX interrupt 
          baud=6; 
                break; 
       case '2': // set baud rate 4800 
                IE2=0x00; 
                ME2=0x00; 
                UCTL1=0x01; // Software reset 
                UCTL1 |= CHAR; // 8-bit character 
                UTCTL1 |= SSEL0; // UCLK = ACLK 
          UBR01=0x06; 
          UBR11=0x00; 
          UMCTL1=0x77; 
                ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD 
                UCTL1 &= ~SWRST; // Initialize USART state machine 
                IE2 |= URXIE1; // Enable USART1 RX interrupt 
                baud=7; 
                break; 
       case '3': // set baud rate 9600 
                IE2=0x00; 
                ME2=0x00; 
                UCTL1=0x01; // Software reset 
                UCTL1 |= CHAR; // 8-bit character 
                UTCTL1 |= SSEL0; // UCLK = ACLK 
          UBR01=0x03; 
          UBR11=0x00; 
          UMCTL1=0x29; 
                ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD 
                UCTL1 &= ~SWRST; // Initialize USART state machine 
                IE2 |= URXIE1; // Enable USART1 RX interrupt 
                baud=8; 
           break; 
       default: 
            break; 
    } 
  } 
} 

"bcincin" <berkecincin@gmail.com> wrote in message 
news:QsSdnYq1dOXJodDanZ2dnUVZ_o-mnZ2d@giganews.com...


> 1- I got a board with dip-switches. How do they work?
Voodoo?
> What do they use for?
They are used primarily to put oil into the ash tray. -- Regards, Richard. + http://www.FreeRTOS.org 14 official architecture ports, 1000 downloads per week. + http://www.SafeRTOS.com Certified by T&#2013265948;V as meeting the requirements for safety related systems.
bcincin wrote:
> 2- I'm tring to do a c# interface to change baud rate of msp430 but it > does not work properly. I got a blinking led to see if it works fine. The > problem is, when i change baud rate, led stops blinkind. When I set change > it back to initial baud rate, led starts blinking again
Just a wild guess, but I would imagine your code never advances beyond this line:
> while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
The reason *may* be that you did not follow the initialization sequence for the USART correctly with regard to the SWRST bit. Check the docs. There is a required sequence that will otherwise result in "unpredictable" behavior. -- Michael N. Moran (h) 770 516 7918 5009 Old Field Ct. (c) 678 521 5460 Kennesaw, GA, USA 30144 http://mnmoran.org "So often times it happens, that we live our lives in chains and we never even know we have the key." "Already Gone" by Jack Tempchin (recorded by The Eagles) The Beatles were wrong: 1 & 1 & 1 is 1
On 2007-11-28, bcincin <berkecincin@gmail.com> wrote:

> 1- I got a board with dip-switches. How do they work?
When closed, they allow current to flow through them. When open, they don't.
> What do they use for?
To turn current on/off.
> 2- I'm tring to do a c# interface to change baud rate of msp430 but it > does not work properly. I got a blinking led to see if it works fine. The > problem is, when i change baud rate, led stops blinkind. When I set change > it back to initial baud rate, led starts blinking again > > Code:
Your code is 1) Too long. People are willing to look at a short program to help you with a specific problem. If you just post a 100+ lines of code and ask "what's wrong with my program?" you're not going to get very good results. 2) A mess. The random indentation and brace placement make it impossible to read. Most of us won't try to help until you put in a little effort to make it easy for us. If you want help, post a smaller, well-formatted program that doesn't work. The program needs to be as small as possible but still demonstrate the problem. You might want to read this: http://www.catb.org/~esr/faqs/smart-questions.html -- Grant Edwards grante Yow! I wonder if I should at put myself in ESCROW!! visi.com