MSP430Ware use notes to initialize XT1

Publisher:guqian999Latest update time:2017-02-21 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


  1. #include "inc/hw_memmap.h"  

  2. #include "ucs.h"  

  3. #include "wdt_a.h"  

  4. #include "gpio.h"  

  5. #include "sfr.h"  

  6.   

  7. uint16_t status;  

  8.   

  9. void main (void)  

  10. {  

  11.     // Stop the watchdog  

  12.     WDT_A_hold(WDT_A_BASE);  

  13.   

  14.     //P4.0 keeps output status  

  15.     GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0);  

  16.   

  17.     // Initialize P7.0 and P7.1 as multiplexing functions  

  18.     GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P7 , GPIO_PIN0 | GPIO_PIN1 );  

  19.     // Start XT1 and wait for all crystal oscillator error flags to clear  

  20.     UCS_LFXT1Start( UCS_BASE , UCS_XT1_DRIVE0 , UCS_XCAP_3 );  

  21.   

  22.     // Enable global interrupts  

  23.     __bis_SR_register(GIE);  

  24.   

  25.     while(1)  

  26.     {  

  27.         // Flip P4.0  

  28.         GPIO_toggleOutputOnPin(GPIO_PORT_P4,GPIO_PIN0);  

  29.         // Software delay  

  30.         __delay_cycles(1000000);  

  31.     }  

  32. }  


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:


  1. #include "inc/hw_memmap.h"  

  2. #include "ucs.h"  

  3. #include "wdt_a.h"  

  4. #include "gpio.h"  

  5. #include "sfr.h"  

  6.   

  7. uint32_t clockValue_ACLK = 0;  

  8. uint32_t clockValue_MCLK = 0;  

  9. uint32_t clockValue_SMCLK = 0;  

  10.   

  11. void main (void)  

  12. {  

  13.     // Stop the watchdog  

  14.     WDT_A_hold(WDT_A_BASE);  

  15.   

  16.     //P4.0 keeps output status  

  17.     GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0);  

  18.   

  19.     // Initialize P7.0 and P7.1 as multiplexing functions  

  20.     GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P7 , GPIO_PIN0 | GPIO_PIN1 );  

  21.     // Start XT1 and wait for all crystal oscillator error flags to clear  

  22.     UCS_LFXT1Start( UCS_BASE , UCS_XT1_DRIVE0 , UCS_XCAP_3 );  

  23.   

  24.     // If you use XT1 or XT2, you need to call this function  

  25.     UCS_setExternalClockSource(UCS_BASE,32768,8000000);  

  26.     // Get system clock, system clock, auxiliary clock  

  27.     clockValue_SMCLK = UCS_getSMCLK( UCS_BASE );  

  28.     clockValue_MCLK = UCS_getMCLK( UCS_BASE );  

  29.     clockValue_ACLK = UCS_getACLK( UCS_BASE );  

  30.   

  31.     // Enable global interrupts  

  32.     __bis_SR_register(GIE);  

  33.   

  34.     while(1)  

  35.     {  

  36.         // Flip P4.0  

  37.         GPIO_toggleOutputOnPin(GPIO_PORT_P4,GPIO_PIN0);  

  38.         // Software delay  

  39.         __delay_cycles(1000000);  

  40.     }  

  41. }  


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.


Keywords:MSP430 Reference address:MSP430Ware use notes to initialize XT1

Previous article:MSP430Ware use notes to initialize DCO to 8MHz
Next article:MSP430F5438 study notes DCO frequency multiplication to 8MHZ

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号