Code function: TI official routine: PC sends characters to MCU and then MCU sends them back to PC. It is such a simple code. I actually... The following explains the function of each statement one by one.
Attach the code:
//*************************************************************************
// MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM0.
// USCI_A0 RX interrupt triggers TX Echo.
// Baud rate divider with 1MHz = 1MHz/9600 = ~104.2
// ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
// MSP430G2xx3
// -----------------
// /|\| PLEASE|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2/UCA0TXD|------------>
// | | 9600 - 8N1
// | P1.1/UCA0RXD|<------------
//
// D. Dang
// Texas Instruments Inc.
// February 2011
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//************************************************************************
#include
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
//_UNITE();
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
1: First, let's talk about some things you need to pay attention to when using the G2553 serial port.
(1): Hardware connection. The jumper cap should be changed to HW instead of SW. Look carefully on the board and you can see the words SW and HW.
(2): When using an external crystal oscillator 32768, the baud rate cannot exceed 9600. When using the internal DCO, it can be higher, but be careful that the register for baud rate calculation should not be less than 3. Remember that when the baud rate exceeds 9600, the board's built-in download circuit no longer supports it and an external serial port circuit must be connected
2: Introduce a simple process of serial port code:
1: Select the clock source you need, external crystal oscillator 32768 or internal DCO. If you choose internal DCO, you need to verify whether the correction data is erased.
2: Configure TX RX pins
3: Now start configuring the registers related to the serial port
First:
USCI_Ax Control Register G2553 has two serial port control registers UCAxCAL0 and UCAxCTL1. Generally, as a novice, we don't need to worry about UCAxCTL0. The default is fine. We only need to configure the clock source selection and software reset enable in UCAxCTL1. Generally, ACLK or SMCLK can be selected. As for the software reset, UCSWRST
UCSWRST: 0 is disabled. USCI reset is released for operation.
1 is enabled. The USCI logic is held in reset.
This means that after the microcontroller is reset, if this bit is 0, the serial port can work normally. If it is 1, it remains in the reset state. After the reset state, this bit is 1, which means that if it is not cleared after reset, the serial port will not work.
Second:
After configuring the above control registers, the following is the baud rate configuration UCAxBR0 Baud Rate Control Register 0
UCAxBR0 = integer part of (clock frequency/baud rate) The times must be less than 0xff and the extra ones are placed in UCAxBR1
Next:
Configure the baud rate adjuster: UCAxMCTL = (clock frequency/baud rate) fractional part * 8
Next_1:
At this time, according to the needs, whether to use the serial port to send interrupts and receive interrupts, be sure not to forget to enable the general interrupt
Final: Clear the UCSWRST bit and the serial port starts working
Now let me explain the problem of correcting the clock, which is the following sentence of the watchdog
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
As novices, when we see CALBC1_1MHZ, we will naturally think that it is also a mask similar to BIT0. However, after searching the header file, we find that this is not the case.
We can receive a passage like this:
#define CALDCO_1MHZ_ (0x10FEu) /* DCOCTL Calibration Data for 1MHz */
READ_ONLY DEFC( CALDCO_1MHZ , CALDCO_1MHZ_)
I won't say too much about this, just one thing: this chip is calibrated before leaving the factory, and the calibrated data is placed in a certain section of the Flash. CAKBC1_1MHZ is defined as an address in the Flash. If you accidentally erase the data in the Flash, all the data in it will become 0XFF. So the meaning of this sentence is to take out CAKBC1_1MHZ. The data in this flash is more similar to 0xff. You can verify it by single-step simulation. I will post my simulation for reference below.
You can see that the operation of the assembly instruction is to take out the data in that address and compare it with 0XFF. Well, we will introduce it here. It is enough to know that the thing is an address. If you want to know more, you can read the following article which is very detailed http://blog.sina.com.cn/s/blog_a85e142101010myq.html
If you are interested, you can simulate and see if the values in your two clock registers can correspond to the corresponding DCO selection frequency. I saw the following figure 3 7. Just choose the 1MHZ clock as shown below:
Previous article:About the interrupt request flag
Next article:MSP430G2553 outputs ACLK and SMCLK
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- The price of chips has increased 20 times? Reportedly, there is panic stockpiling in China
- 【GD32L233C-START Review】2. Timer interrupt
- [Shanghai Hangxin ACM32F070 development board evaluation] 4. LCD_TK program analysis
- These pictures can explain the problems in the previous class. Popular science and practical application
- Automatic watering system based on esp32s2-work submission
- Principles and Design of Automatic Control (5th Edition)
- C2000Ware for C2000 MCUs
- MSP430F5529 ADC Reference
- Can I apply for a demo test in the Qorvo New Product Forum?
- 4418 development board Win8.1 PL2303USB to serial port driver installation