This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430fr4133 UART at 57600, I'm missing something :)

Guru 18605 points
Other Parts Discussed in Thread: MSP430FR4133

Hi,

today I have just started with MSP430FR4133 launchpad :)

I was playing with the "_euscia0_uart_01.c" example and have modified a bit. This code simply returns back some string received through UART whenever the string is ended with "\n". I know, I have not performed any kind of buffer overflow protection and the code has lot of room for improvement :)

#include <msp430.h>
#include <string.h>

volatile int index_rx_buffer = 0;
char rx_buffer[10];

void Init_GPIO();

int main(void)
{
  WDTCTL = WDTPW | WDTHOLD;                // Stop watchdog timer

  // Configure GPIO
  Init_GPIO();
  PM5CTL0 &= ~LOCKLPM5;                    // Disable the GPIO power-on default high-impedance mode
                                           // to activate 1previously configured port settings

  __bis_SR_register(SCG0);                 // disable FLL
  CSCTL3 |= SELREF__REFOCLK;               // Set REFO as FLL reference source
  CSCTL0 = 0;                              // clear DCO and MOD registers
  CSCTL1 &= ~(DCORSEL_7);                  // Clear DCO frequency select bits first
  CSCTL1 |= DCORSEL_3;                     // Set DCO = 8MHz
  CSCTL2 = FLLD_0 + 243;                   // DCODIV = 8MHz
  __delay_cycles(3);
  __bic_SR_register(SCG0);                 // enable FLL
  while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked

  CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
                                           // default DCODIV as MCLK and SMCLK source

  // Configure UART pins
  P1SEL0 |= BIT0 | BIT1;                    // set 2-UART pin as second function

  // Configure UART
  UCA0CTLW0 |= UCSWRST;
  UCA0CTLW0 |= UCSSEL__SMCLK;
  
  // Baud Rate calculation
  // 8000000/(16*9600) = 52.083
  // Fractional portion = 0.083
  // User's Guide Table 14-4: UCBRSx = 0x49
  // UCBRFx = int ( (52.083-52)*16) = 1

  UCA0BR0 = 52;                             // 8000000/16/9600
  UCA0BR1 = 0x00;
  UCA0MCTLW = 0x4900 | UCOS16 | UCBRF_1;

  //UCA0BR0 = 8;                             // for 57600...
  //UCA0BR1 = 0x00;
  //UCA0MCTLW = 0xF700 | UCOS16 | UCBRF_10;

  UCA0CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  print_sentence("start");

  while(1) {
	  __bis_SR_register(LPM3_bits|GIE);         // Enter LPM3, interrupts enabled
	  print_sentence(rx_buffer);
	  __no_operation();                         // For debugger
  }
}

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
  {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
      	rx_buffer[index_rx_buffer++] = UCA0RXBUF;
      	if (UCA0RXBUF == '\n') {
      		__bic_SR_register_on_exit(LPM3_bits);
      		index_rx_buffer = 0;
      	}
      __no_operation();
      break;
    case USCI_UART_UCTXIFG: break;
    case USCI_UART_UCSTTIFG: break;
    case USCI_UART_UCTXCPTIFG: break;
    default: break;
  }
}

void Init_GPIO()
{
	// this provokes an initial 0x00 to be output on serial port
    P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF;
    P5DIR = 0xFF; P6DIR = 0xFF; P7DIR = 0xFF; P8DIR = 0xFF;
    P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF; P4REN = 0xFF;
    P5REN = 0xFF; P6REN = 0xFF; P7REN = 0xFF; P8REN = 0xFF;
    P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00;
    P5OUT = 0x00; P6OUT = 0x00; P7OUT = 0x00; P8OUT = 0x00;
}

int print_sentence(char* sentence) {
	int i;
	for (i = 0; i < strlen(sentence); i++) {
		while(!(UCA0IFG&UCTXIFG));
		UCA0TXBUF = sentence[i];
	}
	return i;
}

However, now I would like to switch from 9600 to 57600. I have tried that USCI UART Baud Rate Generator utility and also read the datasheet but I think I'm missing something. My attempt was in the source code line commented as "57600". When increasing the baud-rate like this, no strings come back as echo.

So, maybe some good samaritan can tell me what I am doing wrong in case it is a small error? What am I misunderstanding or not taking into account?

Have a really nice day! Tomorrow is friday! :)

**Attention** This is a public forum