【转】MSP430 G2553 uart串口

2019-07-20 14:35发布

1)  USCIx分为USCI_Ax和USCI_Bx,其中只有USCI_Ax可配置为UART,MSP430单片机中有的型号有两个通信模块USCI0和USCI1。USCI_A:支持UART, IrDA, SPI
USCI_B:支持I2C, SPI

2)  其他比较简单,设置好几个控制寄存器,波特率,写几个收发函数就可以了。
用到的配置图表,系统时钟1MHZ

比较关键的一个寄存器,程序里面通过UCA0MCTL设置

[cpp] view plain copy


  • </pre><pre name="code" class="cpp"><pre name="code" class="cpp">void uart_Init() //初始化函数  
  • {  
  •     //UCA0CTL1 |= UCSRST;  
  •     UCA0CTL1 |= UCSSEL_2;  //clock is BRCLK  
  •     UCA0BR0 = 0x6D;              //Baud N=BCLK/rate,rate=9600,BCLK=SMCLK=1M  
  •     UCA0BR1 = 0;  
  •     UCA0MCTL = UCBRS0;               //UCBRSx=6         
  •   
  •     P1DIR |= BIT2;           //P1.2                                    ???UART_TX P1DIR|=0x01;  P1OUT&=~0x01;  
  •     P1DIR &= ~BIT1;           //P1.2  UART_RX  
  •     P1SEL = BIT1 + BIT2;      //select P1.1 and P1.2 as UART port  
  •     P1SEL2 = BIT1 + BIT2;  
  •     UCA0CTL1 &=~UCSWRST;     //**Initialize USCI state machine**  
  •   
  •     //IE2 |= UCA0RXIE + UCA0TXIE;                          // interrupt  
  •     IE2 |= UCA0RXIE;                          // interrupt  
  • }  

0条回答

一周热门 更多>