MSP430 serial port receiving program (using interruption)
[Copy link]
Use the receive interrupt to resend the received characters. After each character is received, the low power mode will be exited, and the received characters will be resent in the main function.
/**********************************************
*Program description: P3.4 and P3.5 of the microcontroller are used as serial ports to receive characters and then send out the received characters
**************************************************/
#include <msp430x14x.h>
void usartInit(void); //Serial port initialization
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
usartInit();
while(1){
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
while((UTCTL0&TXEPT)==0);//Wait for data to be sent
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
}
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
LPM3_EXIT;
}
/****************************************************************************
*Function name: uartInit() /
*Purpose: Initialization configuration of USART0, use P3.4 and P3.5, use receive interrupt /
*Return value: None /
*Parameter: None /
**************************************************************************/
void usartInit(){
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00; //
UMCTL0 = 0x4A; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
}
|