MSP430F5438A的串口
設(shè)置串口,最關(guān)鍵的是波特率的設(shè)置,推薦一個(gè)網(wǎng)站,很方便地計(jì)算波特率,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; } }
關(guān)鍵就是UCA0IV 寄存器,通過看文檔得知,這是 USCI_Ax Interrupt Vector Register,具體功能如下:
00h = No interrupt pending,0是無中斷
02h = Interrupt Source: Data received; Interrupt Flag: UCRXIFG; Interrupt
Priority: Highest,2是數(shù)據(jù)接收觸發(fā)中斷
04h = Interrupt Source: Transmit buffer empty; Interrupt Flag: UCTXIFG;
Interrupt Priority: Lowest,4是數(shù)據(jù)發(fā)送中斷
經(jīng)常使用的是接收中斷,沒用過發(fā)送中斷