欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MSP430F5438A的串口

程序员文章站 2022-06-24 14:16:30
关键就是UCA0IV 寄存器,通过看文档得知,这是 USCI_Ax Interrupt Vector Register,具体功能如下: 00h = No interrupt pending,0是无中断02h = Interrupt Source: Data received; Interrupt F ......
设置串口,最关键的是波特率的设置,推荐一个网站,很方便地计算波特率,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是数据发送中断

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