1357 views|0 replies

3836

Posts

19

Resources
The OP
 

MSP430Ware use notes to initialize XT1 [Copy link]

1. Platform Description MSP430F5438

2. Why use MSPWare?

Due to work reasons, STM32 is used more in school, and STM32 DriverLib is more convenient to use. When I first learned MSP430, I was back to the era of register operation, which was a little bit uncomfortable. Later, I found that MSP also has DriverLib, but not many people use it. I explored it little by little with this example document and compared it with register operation. After a period of hard work, I became familiar with it.

3. Trends in Embedded System Programming

I personally think that DriverLib will become the mainstream, which can shorten the difficulty of using MCU. As the capacity of Flash and RAM continues to increase, there is no need to study every function. The key is to get started with MCU faster and solve practical problems. The new MCUs that have just been launched on the market also have DriverLib, which shortens the time to get started and quickly captures the market.

4. Sample code, start XT1. TI's sample code lacks the code to initialize the P7.0 and P7.1 peripheral functions, so it cannot run. A few modifications are made here.


#include "inc/hw_memmap.h"
#include "ucs.h"
#include "wdt_a.h"
#include "gpio.h"
#include "sfr.h"

uint16_t status;

void main (void)
{
// Stop watchdog
WDT_A_hold(WDT_A_BASE);

// P4.0 keeps output status
GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0);

// Initialize P7.0 and P7.1 as multiplexed functions
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P7 , GPIO_PIN0 | GPIO_PIN1 );
// Start XT1 and wait for all error flags of crystal oscillator to be cleared
UCS_LFXT1Start( UCS_BASE , UCS_XT1_DRIVE0 , UCS_XCAP_3 );

// Enable global interrupt
__bis_SR_register(GIE);

while(1)
{
// Flip P4.0
GPIO_toggleOutputOnPin(GPIO_PORT_P4,GPIO_PIN0);
// Software delay
__delay_cycles(1000000);
}
}

If XT1 or XT2 is used, UCS_setExternalClockSource(UCS_BASE,XT1_CLK,XT2_CLK) needs to be called before calling UCS_getSMCLK, UCS_getMCLK, and UCS_getACLK;

Although functions such as UCS_getSMCLK have no practical use for this code, they are still very helpful for setting the UART or SPIder baud rate.

The modified code is as follows:


#include "inc/hw_memmap.h"
#include "ucs.h"
#include "wdt_a.h"
#include "gpio.h"
#include "sfr.h"

uint32_t clockValue_ACLK = 0;
uint32_t clockValue_MCLK = 0;
uint32_t clockValue_SMCLK = 0;

void main (void)
{
// Stop watchdog
WDT_A_hold(WDT_A_BASE);

// P4.0 keeps output status
GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0);

// Initialize P7.0 and P7.1 as multiplexed functions
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P7 , GPIO_PIN0 | GPIO_PIN1 );
// Start XT1 and wait for all error flags of crystal oscillator to be clear
UCS_LFXT1Start( UCS_BASE , UCS_XT1_DRIVE0 , UCS_XCAP_3 );

// If you use XT1 or XT2, you need to call this function
UCS_setExternalClockSource(UCS_BASE,32768,8000000);
// Get system clock, system clock, auxiliary clock
clockValue_SMCLK = UCS_getSMCLK( UCS_BASE );
clockValue_MCLK = UCS_getMCLK( UCS_BASE );
clockValue_ACLK = UCS_getACLK( UCS_BASE );

// Enable global interrupt
__bis_SR_register(GIE);

while(1)
{
// Flip P4.0
GPIO_toggleOutputOnPin(GPIO_PORT_P4,GPIO_PIN0);
// Software delay
__delay_cycles(1000000);
}
}

By default, ACLK selects XT1 clock, in which case XT1 clock is 32768 Hz, FLL reference clock is XT1, and DCODIV is 1048576 Hz after frequency multiplication. The reference clocks of SMCLK and MCLK are both DCODIV.

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list