Jump to content
43oh

How to initialize MSP430F5510 correctly?


Recommended Posts

Hi,

 

i got RobG's development board some days ago and started playing with it.

Soon i have discovered some points that i don't understand... I started with RobG's UART-example and modified it a little bit.

 

The changes that i made so far:

1. It now runs at 24 MHz (clocked by XT2)

2. stripped some unneccessary NOP's (no operation)

3. inlined some functions for initialization and handling

 

/***
USB-Includes
***/

#include "USB_config/descriptors.h"

#include "USB_API/types.h"
#include "USB_API/device.h"
#include "USB_API/usb.h"
#include "USB_API/UsbCdc.h"
#include "usbConstructs.h"

/***
HAL-Includes
***/

#include "F5510/HAL_UCS.h"
#include "F5510/HAL_PMM.h"

/***
USB-Variables
***/

// Flag set by event handler to indicate data has been received into USB buffer
volatile BYTE bCDCDataReceived_event = false;

#define BUFFER_SIZE 32
char dataBuffer[bUFFER_SIZE] = "";

///////////////////////////////////////////////////////////

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

// initialize all ports and set them to output-direction
P1OUT = 0x00; P1DIR = 0xFF;
P2OUT = 0x00; P2DIR = 0xFF;
P3OUT = 0x00; P3DIR = 0xFF;
P4OUT = 0x00; P4DIR = 0xFF;
P5OUT = 0x00; P5DIR = 0xFF;
P6OUT = 0x00; P6DIR = 0xFF;
PJOUT = 0x00; PJDIR = 0xFF;

// Higher V_Core needed for Coreclock at 24 MHz
SetVCore(PMMCOREV_3);

// Initialization of clock module
// enable XT2 pins
P5SEL |= 0x0C;

// use REFO for FLL and ACLK
// ???
UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (SELREF__REFOCLK);
UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);

// MCLK will be driven by the FLL (not by XT2), referenced to the REFO
// Start the FLL, at the freq indicated by the config
// ???
Init_FLL_Settle(USB_MCLK_FREQ / 1000, USB_MCLK_FREQ / 98361);

// Start the "USB crystal" - constant USB_MCLK_FREQ
XT2_Start(XT2DRIVE_0);

// Initialization of USB module
// Init USB
USB_init();

// Enable USB event handling routines
USB_setEnabledEvents(kUSB_allUsbEvents);

// See if we're already attached physically to USB, and if so, connect to it
// Normally applications don't invoke the event handlers, but this is an exception.
if (USB_connectionInfo() & kUSB_vbusPresent) {
	if (USB_enable() == kUSB_succeed) {
		USB_reset();
		USB_connect();
	}
}

///////////////////////////////////////////////////////////
// enable interrupts
__bis_SR_register(GIE);

// MCLK = XT2
SELECT_MCLK(SELM__XT2CLK);

// no divisor - full speed
MCLK_DIV(1);

// main loop
while (1) {
	// generate a clock on P1.0 to measure it
	toggle(P1OUT, BIT0);

	// ST_ENUM_ACTIVE
	if ((USBPWRCTL & USBBGVBV) && (USBCNF & PUR_EN) && (bEnumerationStatus == ENUMERATION_COMPLETE) && (!(bFunctionSuspended == TRUE))) {
		while (bCDCDataReceived_event) {
			// Clear flag early -- just in case execution breaks below because of an error
			bCDCDataReceived_event = false;

			// Count has the number of bytes received into dataBuffer
			WORD count = cdcReceiveDataInBuffer((BYTE*) dataBuffer,	BUFFER_SIZE, CDC0_INTFNUM);

			// process incomming data
			WORD c = 0;
			while (c < count) {
				DataHandling(dataBuffer[c]);
				c++;
			}
		}
	}
}
}

/*
* ======== UNMI_ISR ========
*/
#pragma vector = UNMI_VECTOR
__interrupt void UNMI_ISR(void) {
switch (__even_in_range(SYSUNIV, SYSUNIV_BUSIFG)) {
	case SYSUNIV_NONE:
//			__no_operation();
		break;
	case SYSUNIV_NMIIFG:
//			__no_operation();
		break;
	case SYSUNIV_OFIFG:
		// clear OSC flags
		UCSCTL7 &= ~(DCOFFG + XT1LFOFFG + XT2OFFG);
		SFRIFG1 &= ~OFIFG; //Clear OFIFG fault flag
		break;
	case SYSUNIV_ACCVIFG:
//			__no_operation();
		break;
	case SYSUNIV_BUSIFG:
		// clear bus error flag
		SYSBERRIV = 0;
		// disable
		USB_disable();
		break;
}
}

 

USB CDC is up and running, if the values for the FLL are wrong Windows won't detect the proper device.

If everything is fine the speed i tested got over 4.000.000 baud without problems.

 

So the questions that i have after the first hours working with the MSP430F5510 are:

- Are there some Interrupt-Routines for handling incomming data? The actual method is really inefficient (Polling in an endless loop)

- How does the FLL work? How to set proper parameters? Wrong values lead to a lock because it can't settle.

- What is REF0? Why use it for FLL and ACLK instead of XT2?

 

Maybe some of you can answer or help me out ... still a lot of things to learn the next days ;)

Link to post
Share on other sites

Interrupt-Routines for handling incomming data on UART?

Check "MSP430F550x_uscia0_uart_XX.c" files in slac394 MSP430F550x MSP430F5510 C Code Examples.

 

Interrupt-Routines for handling incomming data on USB?

Check "UsbIsr.c" and "usbEventHandling.c" files in MSP430 USB Developers Package.

 

USB can't work without any external (XT1/XT2) oscillator.

 

Anyway, all answers for your questions are in...

slau208j (MSP430x5xx MSP430x6xx Family User's Guide)

and all the things regarding USB with all examples in...

MSP430_USB_Developers_Package (http://www.ti.com/tool/msp430usbdevpack)

 

After reading, and after analyzing USB code examples, if you still will have some questions, no problem, I can help.

Link to post
Share on other sites

No UART - reading them directly over the CDC-API.

I already had a look into the Eventhandling in the examples - but they poll permanently for incomming data.

I will check the USBisr later because this actually has no priority to me - first i want to get it running and understand what to do ;)

 

RobG's board has an 24 MHz external oscillator that i use for clocking the CPU (MCLK).

 

I figured out that i don't need the FLL when using the external crystal to clock the CPU.

 

Anyway, all answers for your questions are in...

slau208j (MSP430x5xx MSP430x6xx Family User's Guide)

and all the things regarding USB with all examples in...

MSP430_USB_Developers_Package (http://www.ti.com/tool/msp430usbdevpack)

 

Exactly this is the Problem - not everything is covered there and the examples provided in the USB_Dev_Package are very poor (minimalistic) programmed. Just copy-and-paste of the same source with some modifications for each example.

Link to post
Share on other sites

The NOP's where located in the interrupt routine and had no use (the example also works completely without the interrupt-part):

 

	switch (__even_in_range(SYSUNIV, SYSUNIV_BUSIFG)) {
	case SYSUNIV_NONE:
//			__no_operation();
		break;

 

USB-Initialization and Communication is working fine without them ;)

 

Actually the following minimalistic example works fine - only the XT2 is raising OSC-faults and i dont know why :(

/***
Standard-Includes
***/

#include "stdbool.h"

/***
USB-Includes
***/

#include "USB_config/descriptors.h"

#include "USB_API/types.h"
#include "USB_API/device.h"
#include "USB_API/usb.h"
#include "USB_API/UsbCdc.h"
#include "usbConstructs.h"

/***
HAL-Includes
***/

#include "F5510/HAL_UCS.h"
#include "F5510/HAL_PMM.h"

/***
USB-Variables
***/

// Flag set by event handler to indicate data has been received into USB buffer
volatile BYTE bCDCDataReceived_event = false;

#define BUFFER_SIZE 32
char dataBuffer[bUFFER_SIZE] = "";

#define toggle(port, pin) { port ^= pin; }

/***
Handling of incomming data
***/
void DataHandling(BYTE input) {
if (input == 0x00) {
	// do something
}

}

/***
MAIN
***/
void main(void) {
// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;

// initialize all ports and set them to output-direction
P1OUT = 0x00; P1DIR = 0xFF;
P2OUT = 0x00; P2DIR = 0xFF;
P3OUT = 0x00; P3DIR = 0xFF;
P4OUT = 0x00; P4DIR = 0xFF;
P5OUT = 0x00; P5DIR = 0xFF;
P6OUT = 0x00; P6DIR = 0xFF;
PJOUT = 0x00; PJDIR = 0xFF;

// Higher Vcore needed for 24 MHz
SetVCore(PMMCOREV_3);

// enable XT2 pins
P5SEL |= 0x0C;

UCSCTL6 |= XT2DRIVE_3;

// Start crystal
UCSCTL6 &= ~XT2OFF;

// wait at least 2ms for XT2 to settle
__delay_cycles(50000);

// Clear all OSC fault Flags
UCSCTL7 = 0;

// Clear OFIFG (= Oscillator fault interrupt flag)
SFRIFG1 &= ~OFIFG;

// MCLK = XT2-Freq.
SELECT_MCLK(SELM__XT2CLK);

// full speed
MCLK_DIV(1);

// Init USB
USB_init();

// Enable USB event handling routines
USB_setEnabledEvents(kUSB_allUsbEvents);

// See if we're already attached physically to USB, and if so, connect to it
// Normally applications don't invoke the event handlers, but this is an exception.
if (USB_connectionInfo() & kUSB_vbusPresent) {
	if (USB_enable() == kUSB_succeed) {
		USB_reset();
		USB_connect();
	}
}

// enable interrupts
__bis_SR_register(GIE);

// main loop
while (1) {
	toggle(P4OUT, BIT6);

	// ST_ENUM_ACTIVE
	if ((USBPWRCTL & USBBGVBV) && (USBCNF & PUR_EN) && (bEnumerationStatus == ENUMERATION_COMPLETE) && (!(bFunctionSuspended == TRUE))) {
		while (bCDCDataReceived_event) {
			// Clear flag early -- just in case execution breaks below because of an error
			bCDCDataReceived_event = false;

			// Count has the number of bytes received into dataBuffer
			WORD count = cdcReceiveDataInBuffer((BYTE*) dataBuffer,	BUFFER_SIZE, CDC0_INTFNUM);

			// process incomming data
			WORD c = 0;
			while (c < count) {
				DataHandling(dataBuffer[c]);
				c++;
			}
		}
	}
}
}

 

edit: needed to disable XT2_Start() in USB_enable()-function because of the OSC-faults

 

Never heard of df.de - what is it? Sounds like a german community? maybe you can PN me ;)

Link to post
Share on other sites
http://www.df.de aka domainfactory is a domain provider, used to register your very own domain for your webspace or other services.

GoDaddy.com and united-domains.de are other examples.

Thank you, no i don't use this provider - my provider is one that has his office near my home so i can reach them when problems occur ;)

 

Someone has more tips for me? Who else uses the MSP430F5510 or the Development board of RobG?

Link to post
Share on other sites

Exactly this is the Problem - not everything is covered there and the examples provided in the USB_Dev_Package are very poor (minimalistic) programmed. Just copy-and-paste of the same source with some modifications for each example.

 

USB_Dev_Package is maybe written on unnecessary complicated way, but everything is there. I done deep study on data sheets and source code and at end everything was perfectly clear.

 

In USB_Dev_Package, USB module is running by XT2 clock, and rest of the system is running by DCO (for example at 25MHz). Check in the "main.c" function "VOID Init_Clock (VOID)".

 

Configuration is in "descriptors.h", and for example in my case it was...

 

// MCLK frequency of MCU, in Hz
// For running higher frequencies the Vcore voltage adjustment may required.
// Please refer to Data Sheet of the MSP430 device you use
#define USB_MCLK_FREQ 25000000          // MCLK frequency of MCU, in Hz
#define USB_PLL_XT 2                    // Defines which XT is used by the PLL (1=XT1, 2=XT2)
#define USB_XT_FREQ USBPLL_SETCLK_12_0  // Indicates the freq of the crystal on the XT1/2 oscillator
#define USB_DISABLE_XT_SUSPEND 1        // If non-zero, then USB_suspend() will disable the
                                       // oscillator that is designated by USB_PLL_XT; if zero, 
                                       // USB_suspend won't affect the oscillator

 

System was running by DCO, on max frequency of 25MHz. USB module was running by XT2 on 12MHz. Didn't have any problems with testing TI USB examples, and everything was working OK.

 

Anyway, I written my own USB code in assembler. Not using TI code any more. You can see CDC enumeration process here...

http://www.43oh.com/forum/viewtopic.php?f=10&t=3300#p23790

Link to post
Share on other sites

I already figured this out ;) I thought about initializing USB myself by setting the registers manually - but using the HAL is way easier and better when switching to another device.

 

I already made the following changes to the "descriptor.h" and USB is working fine! ;)

#define USB_MCLK_FREQ 24000000
#define USB_PLL_XT 2
#define USB_XT_FREQ USBPLL_SETCLK_24_0

 

I dont use the internal DCO so i don't need to set up the FLL because there is no need anymore to stabilize the clock.

 

However USB is working fine. I already set up communication between

Link to post
Share on other sites

Why use DCO if you have the peripherals already onboard? As RobG stated above the external XTAL is more precise (compared to DCO without FLL). I don't have an oscilloscope here so i can't check if DCO with FLL is comparable to XTAL. The temperature drift of the internal clock-generators is higher then the drift of the crystal. I know that the USB-PLL is not related to the other clocks of the

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.

×
×
  • Create New...