打印

MSP430中断接收数据

[复制链接]
707|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
JAWN|  楼主 | 2016-4-24 21:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
dirtwillfly| | 2016-4-24 22:43 | 只看该作者
可以参考官网提供的串口接收的例程

使用特权

评论回复
板凳
dirtwillfly| | 2016-4-24 22:47 | 只看该作者
//******************************************************************************
//   MSP430F543xA Demo - USCI_A0, 115200 UART Echo ISR, DCO SMCLK
//
//   Description: Echo a received character, RX ISR used. Normal mode is LPM0.
//   USCI_A0 RX interrupt triggers TX Echo.
//   Baud rate divider with 1048576hz = 1048576/115200 = ~9.1 (009h|01h)
//   ACLK = REFO = ~32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
//   See User Guide for baud rate divider table
//
//                 MSP430F5438A
//             -----------------
//         /|\|                 |
//          | |                 |
//          --|RST              |
//            |                 |
//            |     P3.4/UCA0TXD|------------>
//            |                 | 115200 - 8N1
//            |     P3.5/UCA0RXD|<------------
//
//   M. Morales
//   Texas Instruments Inc.
//   June 2009
//   Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
//******************************************************************************

#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 9;                              // 1MHz 115200 (see User's Guide)
  UCA0BR1 = 0;                              // 1MHz 115200
  UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
  __no_operation();                         // For debugger
}

// Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF;                  // TX -> RXed character
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}

使用特权

评论回复
地板
dirtwillfly| | 2016-4-24 22:47 | 只看该作者
和你的要求只是没存储在数组里,而是又发出去了

使用特权

评论回复
5
JAWN|  楼主 | 2016-4-25 20:24 | 只看该作者
dirtwillfly 发表于 2016-4-24 22:47
//******************************************************************************
//   MSP430F543xA D ...

这样子的话当没有数据发来是会一直卡在 while (!(UCA0IFG&UCTXIFG)); 中,无法执行下面的语句

使用特权

评论回复
6
dirtwillfly| | 2016-4-25 23:02 | 只看该作者
JAWN 发表于 2016-4-25 20:24
这样子的话当没有数据发来是会一直卡在 while (!(UCA0IFG&UCTXIFG)); 中,无法执行下面的语句 ...

不会,没操作时会进入低功耗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

38

主题

110

帖子

1

粉丝