问一个关于5529 串口UART的问题~~~请大神们帮我看看

2019-03-24 09:35发布

我想用430F5529写个小程序,当上位机(串口助手)发一个字符a时,将IO口P1.4翻转~程序如下,不知道为什么UCA1RXBUF和aaa的值都没有~波特率设置为115200~~~~
程序无法实现功能,请大神们帮我看看~~~
  1. #include <msp430.h>
  2. char aaa;

  3. int main(void)
  4. {
  5.   P4SEL = BIT4+BIT5;                        
  6.   P1DIR |= BIT4;
  7.   
  8.   UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  9.   UCA1CTL1 |= UCSSEL__SMCLK;                  
  10.   UCA1BR0 = 0x09;                           //
  11.   UCA1BR1 = 0x00;                           //
  12.   UCA1MCTL |= UCBRS_1+UCBRF_0;              //
  13.   UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  14.   UCA1IE |= UCRXIE;                         // Enable USCI_A1 RX interrupt

  15.   __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, interrupts enabled
  16.   __no_operation();                         // For debugger
  17. }

  18. // Echo back RXed character, confirm TX buffer is ready first
  19. #pragma vector=USCI_A1_VECTOR
  20. __interrupt void USCI_A1_ISR(void)

  21. {
  22.   switch(__even_in_range(UCA1IV,4))
  23.   {
  24.   case 0:break;                             // Vector 0 - no interrupt
  25.   case 2:                                   // Vector 2 - RXIFG
  26.     while (!(UCA1IFG&UCTXIFG));             // USCI_A1 TX buffer ready?
  27.     UCA1TXBUF = UCA1RXBUF;                  // TX -> RXed character
  28.     aaa = UCA1RXBUF;
  29.     //uart_tx_string(aaa);
  30.     if(aaa == 'a')
  31.     {
  32.       P1OUT ^= BIT4;
  33.     }
  34.    
  35.     break;
  36.   case 4:break;                             // Vector 4 - TXIFG
  37.   default: break;
  38.   }  
  39. }
复制代码


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
1条回答
Ben讨厌苦咖啡
1楼-- · 2019-03-24 14:18
< 顶顶顶~~~~~

一周热门 更多>

相关问题

    相关文章