Tool/software:
Im using the code given below: its not working: I want to configure the uart baud rate 19200 and 8MHz
I followed the datasheet and tried lots of time tunning different value but its not working, but it works on 19200 16 MHz
If anybody can help me in this case it will be greateful.
Thanks
#include <msp430.h>
/**
* main.c
* BAUD RATE 19200 8MHz
*
*/
// Function to initialize UART
void initUART(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//-- Setup UART
UCA1CTLW0 |= UCSWRST; // Put UART A1 into SW reset (required before configuring)
// Select SMCLK (8MHz) as the clock source
UCA1CTLW0 |= UCSSEL__SMCLK;
// Set baud rate to 19200 with 8MHz clock
UCA1BRW = 26; // 8MHz / (16 * 19200) = 26
// Configure modulation based on 0.4286 fractional part
UCA1MCTLW = (0x54 << 8) | (0 << 4) | UCOS16; // UCBRSx = 0x54, UCBRFx = 0, enable UCOS16 (oversampling)
//-- Setup Ports
P3SEL1 &= ~BIT4; // Clear P3SEL1 bit 4 to select UART function
P3SEL0 |= BIT4; // Set P3SEL0 bit 4 to select UART function
// Unlock and enable I/O pins (disable high-impedance mode)
PM5CTL0 &= ~LOCKLPM5;
// Take UART out of reset to begin operation
UCA1CTLW0 &= ~UCSWRST;
}
// Function to send a string via UART
void uartSendString(char *str)
{
while (*str != '\0')
{
while (!(UCA1IFG & UCTXIFG)); // Wait for TX buffer to be ready
UCA1TXBUF = *str; // Transmit the character
str++; // Move to the next character
}
}
void main(void)
{
initUART(); // Initialize UART
//-- Main loop
while (1)
{
uartSendString("Hello, Worked 8MHz Baud rate 19200!\r\n"); // Send the string
__delay_cycles(800000); // Delay to avoid overwhelming the UART (adjust as necessary)
}
}