Other Parts Discussed in Thread: MSP430FR2311, MSP-EXP430FR5739
I have configured the MSP430FR5739 UART when running with a clock frequency of 8MHz, using the Registry entries as per the MSP430FR57xx Family Users Guide, using Table 18-5. Recommended Settings for Typical Crystals and Baudrates. This works for a Clock at 8MHz. However, when I try another frequency using the values in the table, UART spits out rubbish. Could someone please advise if there is some other setting that is required? See code below:
// UART Test
#include <msp430.h>
// Define Constant values
//#define MCU_CLK_8MHZ // Comment this out to use 16MHz Clock
#define UART_TXD BIT0 //Pin 19: P2.0 UART TXD
#define UART_RXD BIT1 //Pin 20: P2.1 UART RXD
#ifdef MCU_CLK_8MHZ // Values from User Guide for 8MHz
#define UART_BR 52
#define UART_BRF 1
#define UART_BRS 0x49
#define UART_OS16 1
#else // Values from User Guide for 16MHz
#define UART_BR 104
#define UART_BRF 2
#define UART_BRS 0xD6
#define UART_OS16 1
#endif
// Function declaration and Variables
void UART_TX(char *TXData);
char* TXString; // Transmit string for UART
// Main
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure Clocks
CSCTL0_H = 0xA5; // Unlock register
#ifdef MCU_CLK_8MHZ
CSCTL1 |= DCOFSEL0 + DCOFSEL1; // 8MHz
#else
CSCTL1 |= DCOFSEL_0 + DCORSEL; // 16MHz
#endif
CSCTL2 = SELA_3 + SELS_3 + SELM_3; // set ACLK = vlo; SMCLK = DCO, MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; // set all dividers
CSCTL0_H = 0x01; // Lock Register
// Configure Ports
P2SEL1 |= UART_TXD + UART_RXD; // Configure UART pins P2.0 & P2.1
P2SEL0 &= ~(UART_TXD + UART_RXD);
// Configure UART
UCA0CTL1 |= UCSWRST + UCSSEL_2; // Configure UART 0
UCA0BR0=(UART_BR&0xff);
UCA0BR1=(UART_BR>>8);
UCA0MCTLW = UART_BRF|UART_BRS|UART_OS16;
while(1)
{
TXString = "Testing \r\n";
UART_TX(TXString);
__delay_cycles(20000);
}
}
void UART_TX(char *TXData) // Define a function which accepts a character pointer to an array
{
// Function to Transmit characters
unsigned int i=0;
UCA0CTL1 &= ~UCSWRST; // release from reset
while(TXData[i]) // Increment through array, look for null pointer (0) at end of string
{
while (!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = TXData[i]; // Send out element i of tx_data array on UART bus
i++; // Increment variable for array address
}
}