请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430FR2475 您好;
我的软件在一段时间后以8MHz 频率出现了频率变化、但在16MHz 频率下无法正常工作。 我怀疑计时器模块、UART 配置和主时钟配置;
如果我在库中犯了任何错误、您能检查一下并发表评论吗?
时钟配置
void initClockTo8MHz() { __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; __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while (CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)) ; // FLL Lock } void initClockTo16MHz() { // Configure one FRAM waitstate as required by the device datasheet for MCLK // operation beyond 8MHz _before_ configuring the clock system. FRCTL0 = FRCTLPW | NWAITS_1; // Clock System Setup __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_5; // Set DCO = 16MHz CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while (CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)) ; // FLL locked }
UART 配置
* This is for 115200 Baud rate (8Mhz) */ UCA1BRW = 4; UCA1MCTLW |= 0x0500; UCA1MCTLW |= UCBRF_3; UCA1MCTLW |= UCOS16_1; UCA1CTLW0 &= ~UCSWRST; UCA1CTLW1 = 0; UCA1IE |= UCRXIE; /* * This is for 115200 Baud rate (16Mhz) */ /* UCA1BRW = 8; UCA1MCTLW |= 0x0000; UCA1MCTLW |= UCBRF_11; UCA1MCTLW |= UCOS16_1; UCA1CTLW0 &= ~UCSWRST; UCA1CTLW1 = 0; UCA1IE |= UCRXIE; */
计时器库
#include <msp430.h> #include <stdint.h> #include "TIMER_MODULE.h" /* * This function will initialize the Timer module */ void timerInit(void) { TA1CCTL0 |= CCIE; // TACCR0 interrupt enabled TA1CCR0 = 1000 - 1; // timer will roll over every 1000 clock cycle / pwm period TA1CTL |= TASSEL_2 + ID_3 + MC_1 + TACLR; // TimerA1 SMLCK(TASSEL_2), CLOCK divide by 8(ID_3) pwm start(MC_1), Reset the timer clear TAR (TACLR) } /* * This function will return the current time with resolution * of 10 microsecond in each ticking */ uint32_t timerMicros(void) { return micros + TA1R; } /* * This function will return the current time with resolution * of 1 millisecond in each ticking */ uint32_t timerMillis(void) { return millis; } /* * This function will return the current time with resolution * of 1 second in each ticking */ uint32_t timerSecond(void) { return (millis / 1000); } /* * This function will reset all timers */ void timerReset(void) { millis = 0; } /* * This function will reset millis */ void timerResetMillis(void) { millis = 0; } /* * This function will reset seconds */ void timerResetSecond(void) { second = 0; } /* * This is an ISR to handle the timer */ #pragma vector = TIMER1_A0_VECTOR __interrupt void Timer_A_CCR0_ISR(void) { millis++; micros += 1000; }