主题中讨论的其他器件:MSP430F67641
尊敬的团队:
我正在通过9600波特率的异步 UART 连接射频模块。 我的射频模块每2秒接收一次数据、并进行写操作以供控制器 MSP430F67641读取。
我面临的问题是、每当我在代码中放置断点时、我都会得到一个溢出错误集(UCOE 和 UCRXERR 集)、并且在我完成完全复位之前、我不再能够接收任何数据。
当我不使用断点停止目标并允许其持续运行时、我不会遇到此问题。 我知道、如果我用断点停止内核、外部射频仍会接收一些数据并将数据写入控制器、并且肯定会错过一些数据。 但我希望 UART 模块也能在不接收任何内容的情况下暂停、并且只会丢失中间数据而不是溢出错误。
在断点时、我没有注意到我在其他项目中使用的其他 MSP430控制器中的这种奇怪的溢出行为。
我的代码的关键部分。 请在这里提供帮助吗?
谢谢
Surya
void SetClock_24Mhz()
{
SetVCore(3);
// Setup UCS
UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
UCSCTL5 |= DIVS__2 | DIVA__4 | DIVM__1;
UCSCTL4 |= SELM__REFOCLK | SELS__REFOCLK | SELA__REFOCLK; /* 24MHz MCLK, 12MHz SMCLK, ACLK (6Mhz)*/
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_7; // Select DCO range 24MHz operation
UCSCTL2 = FLLD_1 | 732; // Set DCO Multiplier for 24MHz
// (N + 1) * FLLRef = Fdco
// (732 + 1) * 32768 = 24MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
__delay_cycles(250000);
__delay_cycles(250000);
__delay_cycles(250000);
__delay_cycles(250000);
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
SFR_clearInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
__delay_cycles(250000);
}
void Uart_Init_9600()
{
// Setup P2.2 UCA2RXD, P2.3 UCA2TXD
P2SEL |= BIT2 | BIT3; // Set P2.2, P2.3 to non-IO
P2DIR |= BIT2 | BIT3; // Enable UCA2RXD, UCA2TXD
// Setup eUSCI_A2
UCA2CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA2CTLW0 |= UCSSEL__SMCLK | UCRXEIE; // SMCLK (12Mhz) accurate -> 12009472 Hz
/*
* Baud Rate calculation (9600) [PAge No- 586 user guide 2433]
* 12009472/(9600) = 1250 [Greater than 16. So proceed with next calc's]
* (1250.987/16) = 78.186 => (UCA1BR0 = 78)
*
* UCBRFx = (0.186*16) = 2.98 => 3 roundoff
* User's Guide Table 22-4: Decimal value of (0.00) is UCBRSx = 0x00
*/
UCA2BRW = 78; // 24MHz 9600
UCA2MCTLW = UCBRF_3 | UCOS16; // Modln UCBRSx=0, UCBRFx=0x13,
UCA2CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA2IE |= UCRXIE; // Enable USCI_A2 RX interrupt
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A2_VECTOR
__interrupt void USCI_A2_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A2_VECTOR))) USCI_A2_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (__even_in_range(UCA2IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break; // No interrupt
case USCI_UART_UCRXIFG: // RXIFG
UCA2_Status = UCA2STATW;
if (UCA2_Status & UCRXERR)
{
// This part of code is hit when i set a breakpoint and some data is receiveid during that time
DummyRX = UCA2RXBUF; // Dummy read to clear out data
UARTErrorCnt++;
}
else
{
UartRxBuff[UartRxCnt] = UCA2RXBUF; // TX -> RXed character
/* Check if new line received and set processing flag */
if(UartRxBuff[UartRxCnt] == 0x0A) { UartRxFlg = true; }
UartRxCnt++;
}
/* If RX buffer exceeds then process and flush garbage data */
if(UartRxCnt >= UartRxBuffMAX)
{
UartRxCnt = UartRxBuffMAX;
UartRxFlg = true;
}
break;
case USCI_UART_UCTXIFG: break; // TXIFG
case USCI_UART_UCSTTIFG: break; // TTIFG
case USCI_UART_UCTXCPTIFG: break; // TXCPTIFG
default: break;
}
}