设为首页 加入收藏

TOP

MSP430F5438A的串口
2019-05-23 14:39:47 】 浏览:70
Tags: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是数据发送中断

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

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇linux 读写文件 open write lseek.. 下一篇FFmpeg 开发环境搭建及第一个程序..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目