2- I'm tring to do a c# interface to change baud rate of msp430 but i does not work properly. I got a blinking led to see if it works fine. Th problem is, when i change baud rate, led stops blinkind. When I set chang it back to initial baud rate, led starts blinking again
Code: #include 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; } } }