initialization
1 void Uart_Init(void)
2 {
3 BCSCTL1 = CALBC1_1MHZ; // Set DCO
4 DCOCTL = CALDCO_1MHZ;
5 P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
6 P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
7 UCA0CTL1 |= UCSSEL_2; // SMCLK
8 UCA0BR0 = 104; // 1MHz 9600
9 UCA0BR1 = 0; // 1MHz 9600
10 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
11 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
12 IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
13 }
1 // Echo back RXed character, confirm TX buffer is ready first
2 #pragma vector=USCIAB0RX_VECTOR
3 __interrupt void USCI0RX_ISR(void)
4 {
5 while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
6 UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
7 }
1 //Send data
2 //Send character
3 void uart_send_ch(unsigned char ch)
4 {
5
6 while(!(IFG2& UCA0TXIFG)); //Check whether the sending is finished
7 UCA0TXBUF = ch;
8 IFG2&=~UCA0TXIFG; //Clear the send flag
9 }
10
11 //Send string
12 void uart_send_str(char *str)
13 {
14 for( ; *str ; )
15 {
16 uart_send_ch((unsigned char)*str);
17 str++;
18 }
19 }
When sending a number combination using uart_send_str() and then sending a carriage return, garbled characters will appear, about nine characters will appear, and the problem can be solved by delaying in the middle
char a[4];
uart_send_str(a);
__delay_cycles(5);
uart_send_hook();
void uart_send_huiche(void)
{
uart_send_ch(0x0d);
uart_send_ch(0x0a);
}
Previous article:MSP430: Input Capture
Next article:MSP430: PWM Generation
Recommended ReadingLatest update time:2024-11-16 21:41
- Popular Resources
- Popular amplifiers
- MSP430 series single chip microcomputer system engineering design and practice
- oled multi-chip calling program
- Microcontroller Principles and Applications Tutorial (2nd Edition) (Zhang Yuanliang)
- Getting Started and Improving MSP430 Microcontrollers - National Undergraduate Electronic Design Competition Training Course
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Reliable communications for short-range wireless systems
- I can't read the TMP275 temperature sensor. I use the STM32 I/O to simulate IIC. Please help.
- Understanding GaN Device Thermal Analysis
- 5. Control objects in previous “Control” competitions
- Album of previous competition questions of the National Undergraduate Electronic Design Competition
- Explanation of the schematic diagram of the xenon lamp flash circuit
- 【GD32F307E-START】+Software I2C driver DS1307 calendar module
- TMS320C6678 Development Routine User Manual Study 2
- 【RPi PICO】Drawing in ms_paint
- Problems with the MAX7219