MSP430 serial port initialization, and serial port operation

Source: Internet
Author: User

#include <msp430x14x.h>/* For UART0 serial port configuration, and Operation function Description *//* First, UART0 initialization */ voidUart0_idev_init (void) {P3sel |= BIT4 + BIT5;//1. Select P3.4 and P3.5 to do UART0 communication portME1 |= UTXE0 + URXE0;//2. Enable USART0 to be sent and acceptedUCTL0 |= CHAR;//3. Select 8-bit charactersUTCTL0 |= SSEL0;//4. Select Clock Source, Aclk:ssel0                                    //Smclk:ssel1UBR00 =0x03;//5. Baud Rate 32767hz:9600UBR10 =0x00;//UMCTL0 =0x4A;//ModulationUCTL0 &= ~swrst;//6. Initialize the UART state machineIE1 |= URXIE0;//7. Enable USART0 to receive interrupts}/* Two, uart0 send a byte*/voidUart0_send_byte (byte dat) { while(! (IFG1 & UTXIFG0));//USART0 TX buffer ready?TXBUF0 = dat;}/* Three, read a byte*/from the uart0 RXBUF0Int8u Uart0_rec (void){returnRXBUF0;}/* Four, UART1 serial interrupt processing function */#pragma vector=uart0rx_vector__interruptvoidUSART0_RX (void){}/* For UART2 serial port configuration, and Operation function Description *// * one. UART1 initialization * /voidUart1_idev_init (void) {P3sel |= BIT6 + BIT7;//1. p3.6,p3.7 Selected as UART1 communication portME2 |= UTXE1 + URXE1;//2. Enable USART0 to be sent and acceptedUCTL1 |= CHAR;//3. Select 8-bit charactersUTCTL1 |= SSEL0;//4. Select Clock Source, Aclk:ssel0                              //Smclk:ssel1UBR01 =0x03;//5. Baud Rate 32767hz:9600UBR11 =0x00;//UMCTL1 =0x4A;//ModulationUCTL1 &= ~swrst;//6. Initialize the UART state machineIE2 |= URXIE1;//7. Enable USART1 to receive interrupts}/* Two, Uart1 send a byte*/voidUart1_send_byte (byte dat) { while(! (IFG2 & UTXIFG1));//USART0 TX buffer ready?TXBUF1 = dat;}/* Three, read a byte*/from the Uart1 RXBUF1Int8u Uart1_rec (void){returnRXBUF1;}/* Four, UART1 serial interrupt processing function */#pragma vector=uart1rx_vector__interruptvoidUSART1_RX (void){}

MSP430 serial port initialization, and serial port operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.