MSP430: Serial Output

Publisher:HeavenlyLoveLatest update time:2017-11-03 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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);

}


Keywords:MSP430 Reference address:MSP430: Serial Output

Previous article:MSP430: Input Capture
Next article:MSP430: PWM Generation

Recommended ReadingLatest update time:2024-11-16 21:41

Design of non-magnetic water meter based on MSP430FW427 single chip microcomputer
1 Introduction to MSP430FW42x MCU The MSP430FW42x series MCU is the latest dedicated MCU chip developed by TI for electronic flow and rotational motion detection. It perfectly combines ultra-low power MCU, rotation scanning interface (SCAN IF) and LCD driver module. The ultra-low power structure and flow detection mo
[Microcontroller]
Design of non-magnetic water meter based on MSP430FW427 single chip microcomputer
MSP430F5438 I2C Learning Notes——AT24C02
0. Introduction For most MCUs, I2C has become a long-standing problem. Since the 51 era, software simulation of I2C has become the mainstream. Even today when ARMCortex M3 is popular, software simulation of I2C is still the most widely used method. Although software simulation can solve all problems, it always feels t
[Microcontroller]
MSP430F5438 I2C Learning Notes——AT24C02
Detailed explanation of how to use the MSP430 watchdog
Take MSP430F2274 as an example. The assembly implementation uses IAR assembly, and the CCE assembly implementation can be slightly modified. 1. The watchdog has three working modes: stop mode, timer mode, and watchdog mode. 2. The clock sources that can be selected in the latter two modes are: SMCLK and AC
[Microcontroller]
Design of reversing radar based on MSP430
With the increasing requirements for the intelligence of automobile assisted driving systems and the networking development of automobile electronic systems, new reversing radars should be able to continuously measure and display the distance to obstacles, and have communication functions to send data to the vehicle
[Microcontroller]
Design of reversing radar based on MSP430
MSP430G2553 clock system configuration
In the MSP430 microcontroller, one clock cycle = the inverse of the MCLK crystal oscillator. If the MCLK is 8MHz, then one clock cycle is 1/8us. One machine cycle = one clock cycle, that is, each action of 430 can complete a basic operation. One instruction cycle = 1~6 machine cycles, depending on the specific instruc
[Microcontroller]
MSP430fr6989 serial port DMA sending experimental routine (written from scratch, personally tested and playable)
In this example, P2.0 and P2.1 of MSP430fr6989 are selected as serial ports UCA0TXD and UCA0RXD; (There is not much code, mainly for register operations, and it is written in the main.c file in a hurry. It is not recommended to do this for engineering) These two registers are mainly used: DMACTL0 is used to select D
[Microcontroller]
MSP430 MCU Timer
  The MSP430 series of microcontrollers have powerful timer resources, which play an important role in microcontroller application systems.   In F11X and F11X1, there is no timer B resource. The timing modules of 430 include watchdog timer, timer A and timer B. The main resource features of timer A are 16-bit timer co
[Microcontroller]
MSP430F5438 Research Experience
1. Multiple-source interrupt problem #pragma vector = PORT2_VECTOR __interrupt void port2(void) {      switch(P2IV)     {          case P2IV_P2IFG6:            P2IFG &=~BIT6;            P1OUT ^= BIT0;break;           //LED1 on and off          case P2IV_P2IFG7:            P2IFG &=~BIT7;            P1OUT ^= BIT1;break;
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号