Jump to content
Sign in to follow this  
zeke

MSP430F5438 clock frequency setting?

Recommended Posts

Hey Guys,

 

I've moved away from the Launchpad to the MSP-EXP430F5438 explorer board for my project development.

 

It pains me to admit it but I can't seem to set the DCO properly. I'm following the datasheet but the chip is acting like it's not calibrated.

 

Has anyone out there got experience calibrating the DCO on an F5438 processor?

If so, would you care to share your wisdom with me?

 

Thanks!

Share this post


Link to post
Share on other sites

F5xx and F6xx have hardware FLL. That is, the DCO can be dynamically adjusted by hardware according to a "reference". You normally do not need to calibrate the DCO. If you do want to, you need to disable the hardware DCO and do it your way. Read the User's Guide for F5xx/F6xx, not the one for F2xx/G2xx.

Share this post


Link to post
Share on other sites

I just wanted to give you a little warning since you might search "dco calibration" and come across a tool in the forums for calibrating the dco presets. That tool is for the value line and shouldn't be used on your chip or you could mess up your ADC12 calibrations. This warning is on that thread too, but just in case.

Share this post


Link to post
Share on other sites

Yup. I'm fully aware that the F5438 is a completely different animal. Thanks.

 

I managed to find sanity with the DCO by studying the UserExperience code that came with the board.

 

The code is kinda weird as far as coding style goes but it works so I stole the board configuration routines from it.

 

I now have the DCO running just fine at 16MHz. I also have the USB-UART running at 57600 baud. The TX routine is fishy because it works only when it wants to.

 

To recap, the solution for me was to properly setup the XT1 clock source before attempting to configure the DCO.

Share this post


Link to post
Share on other sites

Today has been a good day so I thought I should post a follow up about the clock frequency configuration on the F5438.

 

I based most of my work on the UserExperience demo code that came with the dev kit. You can find that here.

 

Here's a snippet of my main() routine:

void main( void )
{
 // Setup the MSP430F5438	
 WDTCTL 	 = WDTPW+WDTHOLD;      // Stop WDT

 halBoardInit();					// Initialize all GPIO configurations
 halBoardStartXT1();
 halBoardSetSystemClock( SYSCLK_16MHZ );
 halUsbInit();  					// activate the USB-UART
 halBoardOutputSystemClock();		// Send ACLK, MCLK, SMCLK out to pins P11.0,1,2 for debugging purposes

 

Refer to the UserExperience code to see what those functions do. There's a lot of lines there.

 

The key to my success was the order of the above routines. The halBoardStartXT1() was missing on my earlier attempts. :oops:

 

Next, I spent the day hammering out how to configure that sweet, sweet USB-UART to do different baud rates. I added this function to the hal_usb.c/.h files

 

void halUsbSetBaud( int Baudrate )
{
 volatile unsigned char i;

 // clear the receive buffer
 for ( i = 0; i < 255; i++ )
   halUsbReceiveBuffer[i] = '\0';

 bufferSize = 0;
 USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD;
 USB_PORT_DIR |= USB_PIN_TXD;
 USB_PORT_DIR &= ~USB_PIN_RXD;

 UCA1CTL1 |= UCSWRST;		//Reset State                      
 UCA1CTL0 = UCMODE_0;

 UCA1CTL0 &= ~UC7BIT;        // 8bit char
 UCA1CTL1 |= UCSSEL_2;				// Clock source = SMCLK (16MHz)

switch( Baudrate )
{
	case B9600:
	{
	 	// 9600 BAUD, CLK=16MHz 
	  UCA1BR0 = 104;
	  UCA1BR1 = 0;

	  // UCBRF = 3, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x31;
		break;
	}
	case B19200:
	{
	 	// 19200 BAUD, CLK=16MHz 
	  UCA1BR0 = 52;
	  UCA1BR1 = 0;

	  // UCBRF = 1, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x11;
		break;
	}
	case B38400:
	{
	 	// 38400 BAUD, CLK=16MHz 
	  UCA1BR0 = 26;
	  UCA1BR1 = 0;

	  // UCBRF = 1, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x11;
		break;
	}
	case B57600:
	{
	 	// 57600 BAUD, CLK=16MHz 
	  UCA1BR0 = 17;
	  UCA1BR1 = 0;

	  // UCBRF = 6, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x61;
		break;
	}
	case B115200:
	{
	 	// 115200 BAUD, CLK=16MHz 
	  UCA1BR0 = 8;
	  UCA1BR1 = 0;

	  // UCBRF = 11, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0xB1;
		break;
	}
	case B230400:
	{
	 	// 230400 BAUD, CLK=16MHz 
	  UCA1BR0 = 4;
	  UCA1BR1 = 0;

	  // UCBRF = 3, UCBRS = 5, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x3B;
		break;
	}
	case B460800:
	{
	 	// 460800 BAUD, CLK=16MHz 
	  UCA1BR0 = 2;
	  UCA1BR1 = 0;

	  // UCBRF = 2, UCBRS = 3, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x25;
		break;
	}
	default:
	{
	 	// 9600 BAUD, CLK=16MHz 
	  UCA1BR0 = 104;
	  UCA1BR1 = 0;

	  // UCBRF = 3, UCBRS = 0, UCOS16 = 1
	  //				BITS| 7 6 5 4 | 3 2 1  |   0    |
	  // UCAxMCTL = | UCBRFx  | UCBRSx | UCOS16 |
	  UCA1MCTL = 0x31;
		break;
	}
}

 UCA1CTL1 &= ~UCSWRST;			// Initialize UART  
 UCA1IE |= UCRXIE;					// Enable RX Interrupts

 __bis_SR_register( GIE );	// Enable Interrupts

return;	
}

 

I can set the baud rate between 9600 and 460800 baud. :D

 

Oh, also note that I set the DCO to 16MHz. This code is keyed to that detail.

 

 

Let me know how you make out if you try this code.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...