MSP430FR6972,时钟用DCO, 8MHZ,串口接收在9600时可以,但115200就丢字节是怎么回事?
示波器看串口信号时间精度并无大的偏差。
void Init_Clock(void)
{
// Startup clock system with max DCO setting ~8MHz
CSCTL0_H = CSKEY >> 8; // Unlock clock registers
CSCTL1 = DCOFSEL_3 | DCORSEL; // Set DCO to 8MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
do
{
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG; // Clear oscillator fault flag
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
CSCTL0_H = 0; // Lock CS registers
}
//////////////////////////////////////////
//
// Configure USCI_A0 for UART mode
//
//////////////////////////////////////////
void Init_eUCA0 (void)
{
// Configure USCI_A0 for UART mode
UCA0CTLW0 = UCSWRST; // Put eUSCI in reset
UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
UCA1BR0 = 4; // 115200
UCA1BR1 = 0x00;
UCA1MCTLW |= UCOS16 | UCBRF_5 | 0x5500;
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
UCA0IE |= UCTXCPTIE; // UART Transmit Complete Interrupt Enable
}
///////////////////////////////////////////////
//
// eUSCI_A0 interrupt service routine
//
///////////////////////////////////////////////
#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
{
unsigned char uc_1;
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE:
break;
case USCI_UART_UCRXIFG: // UCAxRXBUF has received a complete character.
uc_1 = UCA0RXBUF;
S1_RXD_Buf[P_S1_R++] = uc_1; //收到就送缓存
break;
case USCI_UART_UCTXIFG: //UCAxTXBUF empty
if(P_S1_T<P_S1_T1)
{
UCA1TXBUF = S1_TXD_Buf[P_S1_T++];
}
else
{
B_S1_Busy = 0; //清除发送忙标志
}
break;
case USCI_UART_UCSTTIFG: //Start bit was received
break;
case USCI_UART_UCTXCPTIFG: //UCAxTXBUF is empty
if(P_S1_T<P_S1_T1)
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = S1_TXD_Buf[P_S1_T++];
}
else
{
B_S1_Busy = 0; //清除发送忙标志
}
break;
}
}
此帖出自
小平头技术问答
UCA1BR1 = 0x00;
UCA1MCTLW |= UCOS16 | UCBRF_5 | 0x5500;
这个配置没问题吗?
一周热门 更多>