设置串口,最关键的是波特率的设置,推荐一个网站,很方便地计算波特率,https://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是数据发送中断
经常使用的是接收中断,没用过发送中断
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/603692.html