MSP430F5438A的串口

设置串口,最关键的是波特率的设置,推荐一个网站,很方便地计算波特率,http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
1 P3SEL |= (BIT4 + BIT5);                      // P3.4,5 = USCI_A0 TXD/RXD
2   UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
3   UCA0CTL1 |= UCSSEL_2;                     // CLK = SMCLK
4   UCA0BR0 = 26;                           // 24MHz/57600=26,1,0,1
5   UCA0BR1 = 0;                           //
6   UCA0MCTL = UCBRF_1+UCBRS_0+UCOS16;        // Modulation UCBRSx=0, UCBRFx=0,UCOS16 = 1
7   UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
8   UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

 

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;
  case 2:break;
  case 4:break;
  default:break;
  }
}

关键就是UCA0IV 寄存器,通过看文档得知,这是 USCI_Ax Interrupt Vector Register,具体功能如下:

00h = No interrupt pending,0是无中断
02h = Interrupt Source: Data received; Interrupt Flag: UCRXIFG; Interrupt
Priority: Highest,2是数据接收触发中断
04h = Interrupt Source: Transmit buffer empty; Interrupt Flag: UCTXIFG;
Interrupt Priority: Lowest,4是数据发送中断

经常使用的是接收中断,没用过发送中断

 

posted @ 2019-04-24 13:58  尧舜语  阅读(898)  评论(0编辑  收藏  举报