芯片:MSP430FR6972
问题描述:
串口配置:波特率115200,时钟源SMCLK=1M,在低功耗模式LPM3下接收到的数据是错的。在LPM1模式正常或者把波特率设置为9600也是正常的
在论坛找到一个和我同样问题的提问,但是解答不够充分。
https://e2echina.ti.com/question_answer/microcontrollers/msp430/f/55/p/100453/538570#538570
程序代码:
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
PM5CTL0 &= ~LOCKLPM5; MSP_Clock_Config();
MSP_USCI1_Init();
Init_Var();
_EINT();
while(1)
{
if(USCI1_RTx->Rxflag == 1)
{
USCI1_Send_nByte(USCI1_RTx->Rxbuf, USCI1_RTx->Rxlen); USCI1_RTx->Rxflag=0;
USCI1_RTx->Rxlen=0;
} LPM3; }
}
串口配置:
void MSP_USCI1_Init(void)
{
/* Configure UART pins */
P3SEL0 |= BIT4 | BIT5; P3SEL1 &= ~(BIT4 | BIT5);
UCA1CTLW0 = UCSWRST;
UCA1CTLW0 |= UCSSEL__SMCLK;
/* 115200 */
// UCA1BR0 = 8;
// UCA1MCTLW = 0xD600;
// UCA1BR1 = 0;
/* 9600 */
UCA1BR0 = 6;
UCA1BR1 = 0;
UCA1MCTLW |= UCOS16 | UCBRF_8 | 0x2000;
UCA1CTL1 &= ~UCSWRST;
UCA1IE |= UCRXIE;}
灰小子:
波特率需要115200时,推荐使用更高的时钟频率。
时钟频率在1MHz,波特率设置115200时,RX Error(%) neg为-17.04,还是比较高的
JIUGEN LI:
回复 灰小子:
意思是在LPM3模式下串口肯定是能用的是吧(指能正常唤醒接收数据),还有我如果外接高频晶振是不是能解决这个问题
Susan Yang:
请您参考下下面的例程,SMCLK=1MHZ,115200/* --COPYRIGHT--,BSD_EX* Copyright (c) 2014, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**********************************************************************************MSP430 CODE EXAMPLE DISCLAIMER** MSP430 code examples are self-contained low-level programs that typically* demonstrate a single peripheral function or device feature in a highly* concise manner. For this the code may rely on the device's power-on default* register values and settings such as the clock configuration and care must* be taken when combining code from several examples to avoid potential side* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware* for an API functional library-approach to peripheral configuration.** --/COPYRIGHT--*/ //****************************************************************************** //MSP430FR6x7x Demo - USCI_A0 External Loopback test @ 115200 baud // //Description: This demo connects TX to RX of the MSP430 UART //The example code shows proper initialization of registers //and interrupts to receive and transmit data. If data is incorrect P1.0 LED is //turned ON. //ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = 1MHz // // //MSP430FR6972 //----------------- //RST -|P2.0/UCA0TXD|----| //||| //-||| //|P2.1/UCA0RXD|----| //|| //|P1.0|---> LED // //Andreas Dannenberg //Texas Instruments Inc. //September 2014 //Built with IAR Embedded Workbench V5.60 & Code Composer Studio V6.0 //****************************************************************************** #include <msp430.h>volatile unsigned char RXData = 0; volatile unsigned char TXData = 1;int main(void) {WDTCTL = WDTPW | WDTHOLD;// Stop watchdog// Configure GPIOP1OUT &= ~BIT0;// Clear P1.0 output latchP1DIR |= BIT0;// For LED on P1.0P2SEL0 |= BIT0 | BIT1;// USCI_A0 UART operationP2SEL1 &= ~(BIT0 | BIT1);// Disable the GPIO power-on default high-impedance mode to activate// previously configured port settingsPM5CTL0 &= ~LOCKLPM5;// Configure USCI_A0 for UART modeUCA0CTLW0 = UCSWRST;// Put eUSCI in resetUCA0CTL1 |= UCSSEL__SMCLK;// CLK = SMCLKUCA0BR0 = 8;// 1000000/115200 = 8.68UCA0MCTLW = 0xD600;// 1000000/115200 - INT(1000000/115200)=0.68// UCBRSx value = 0xD6 (See UG)UCA0BR1 = 0;UCA0CTL1 &= ~UCSWRST;// release from resetUCA0IE |= UCRXIE;// Enable USCI_A0 RX interruptwhile (1){while(!(UCA0IFG & UCTXIFG));UCA0TXBUF = TXData;// Load data onto buffer__bis_SR_register(LPM0_bits | GIE);// Enter LPM0, interrupts enabled} }#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void) #else #error Compiler not supported! #endif {switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG)){case USCI_NONE: break;case USCI_UART_UCRXIFG:RXData = UCA0RXBUF;// Read bufferif(RXData != TXData)// Check value{P1OUT |= BIT0;// If incorrect turn on P1.0while(1);// Trap CPU}TXData++;// increment data byte__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 on retibreak;case USCI_UART_UCTXIFG: break;case USCI_UART_UCSTTIFG: break;case USCI_UART_UCTXCPTIFG: break;} }
JIUGEN LI:
回复 Susan Yang:
姐,我配置没错,只是在LPM3下接收到的数据就是错的,不进入LPM3的话接收都是正常的,后面我增加频率到4M倒是好一些,一串字符有一两个乱码。不知道外接高频晶振会不会好。
Susan Yang:
回复 JIUGEN LI:
若是您的波特率要求比较高的话,建议您使用较高的时钟频率,是可以外接高频晶振的
灰小子:
回复 JIUGEN LI:
可以用。但要注意误码的情况。
用内部的dco做高频时钟源也是可以的。