I need help with changing baud rate, reseting uart

Hi. I want to change reset uart and change baud rate with an interface (combobox) on windows. At the beginning default baud rate is 2400.

ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD

UCTL1 |= CHAR; // 8-bit character

UTCTL1 |= SSEL0; // UCLK = ACLK

UBR01 = 0x0D; // 32k/2400 - 13.65

UBR11 = 0x00;

UMCTL1 = 0x6B; // Modulation

UCTL1 &= ~SWRST; // Initialize USART state machine

IE2 |= URXIE1; // Enable USART1 RX interrupt

how can i reset this later? I tried something like this but it doesn’t work

case 3: // set baud rate 9600

UCTL1 |= CHAR; // 8-bit character

UTCTL1 |= SSEL0; // UCLK = ACLK

UBR01=0x03;

UBR11=0x00;

UMCTL1=0x29;

UCTL1 &= ~SWRST;

IE2 |= URXIE1;

default;

How can I do it?

TI recommends that you set SWRST = 1 before you start changing registers. Here is the procedure outlined in the User Guide:

Note: Initializing or Re-Configuring the USART Module

The required USART initialization/re-configuration process is:

  1. Set SWRST (BIS.B #SWRST,&UxCTL)

  2. Initialize all USART registers with SWRST = 1 (including UxCTL)

  3. Enable USART module via the MEx SFRs (URXEx and/or UTXEx)

  4. Clear SWRST via software (BIC.B #SWRST,&UxCTL)

  5. Enable interrupts (optional) via the IEx SFRs (URXIEx and/or UTXIEx)

Failure to follow this process may result in unpredictable USART behavior.

Hope this helps,

Greg