请教MSP430FR5739串口发送问题

2019-03-24 08:40发布

在Timer0中断里面进行数据发送,1S发送一次数据,代码如下:

//Timer0 Interrupt
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
INT_FLAG = 1;
LED1_BLINK;
curr_timestp ++;
timestap_count ++;
wdt_count ++;
*(time_t*)FRAM_USER_START_ADDR = curr_timestp;
if(OSW_TEST_FLAG)
{
unsigned long temp1 = (osw_times_count * 1.0 / OSW_SWITCH_TIMES) * 100000;
if(osw_process_rate != temp1)
{
PutString(" ");
PutLong(osw_times_count);
PutString(" ");
}
}
}

程序运行后每隔十几个小时就会卡死,卡死在

while (!(UCA1IFG&UCTXIFG));这里,每次都是卡死在PutString函数里面,函数代码如下:

void PutString(char *str)
{
unsigned char temp;
unsigned char i=0;
while((temp = str[i++]) != '')
{
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = temp;
}
},

定时器初始化函数:

void TimerAInit()
{
TA0CCTL0 = CCIE; // TACCR0 interrupt enabled
TA0CCR0 = 32768;
TA0CTL = TASSEL_1 + MC_1; // SMCLK, UP mode
}串口初始化函数,开了两个串口,目前只有UCA1串口出问题

void UartInit()
{

// Configure UART pins
P2SEL1 |= BIT0 + BIT1 + BIT5 + BIT6;
P2SEL0 &= ~(BIT0 + BIT1 + BIT5 + BIT6);
// Configure UART 0
UCA0CTL1 |= UCSWRST;
UCA0CTL1 = UCSSEL_1; // Set ACLK = 32768 as UCBRCLK
UCA0BR0 = 3; // 9600 baud
UCA0BR1 = 0;
UCA0MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
// UCBRSx value = 0x53 (See UG)
UCA0CTL1 &= ~UCSWRST; // release from reset
UCA0IE |= UCRXIE; // Enable RX interrupt
// Configure UART 1
UCA1CTL1 |= UCSWRST;
UCA1CTL1 = UCSSEL_1; // Set ACLK = 32768 as UCBRCLK
UCA1BR0 = 3; // 9600 baud
UCA1BR1 = 0;
UCA1MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
// UCBRSx value = 0x53 (See UG)
UCA1CTL1 &= ~UCSWRST; // release from reset
UCA1IE |= UCRXIE; // Enable RX interrupt
}

这个发送数据的程序测试了几次都是一段时间后会卡死,求大家帮助

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
bobde163
2019-03-24 10:16
< 在正常运行的十几个小时内,数据发送都是正常的吗?

一周热门 更多>

相关问题

    相关文章