各位大侠,你们做过5系列的串口波特率自适应吗?我现在使用的是msp430F5510,单片机与PC机通信,只是从单片机发送给PC主机,但不知道PC端的波特率,所以要做单片机的波特率自适应,5系列都有串口自适应功能,但是不是很清楚怎么实现。在官网上下了一个例程,但它是1系列的,1系列单片不带波特率自适应。它是这样做的
int autobaud(void)
{
baudrates rate;
while (!(UTCTL0 & TXEPT)); // Confirm no TXing before setup
UCTL0 |= SWRST; // Place USART in reset
URCTL0 = URXEIE; // Allow erroneous input to interrupt
UCTL0 &= ~SWRST; // Take USART out of reset
setbaud(BAUD115K);
switch (getchar()) // Get UART character
{
case 0x0d :
rate = BAUD115K; // Perfect match!
break;
case 0xe6 :
rate = BAUD57600;
break;
case 0x1c :
rate = BAUD38400;
break;
case 0xe0 :
rate = BAUD19200;
break;
case 0x80 :
rate = BAUD14400;
break;
case 0x00 :
delay_8_33ms(); // Delay program execution to
// make sure a byte-receiption
// at 1200bps is over
setbaud(BAUD9600); // Set new baud rate
switch (getchar()) // Get 2nd UART character
{
case 0x0d : // Perfect match!
rate = BAUD9600;
break;
case 0xe6 :
rate = BAUD4800;
break;
case 0x78 :
rate = BAUD2400;
break;
case 0x80 :
rate = BAUD1200;
break;
default :
return -1; // Failure
}
break;
default :
return -1; // Failure
}
delay_8_33ms(); // Delay program execution to
setbaud(rate);
showbaud(rate);
return 0; // success
}
请问在5系列中可以这样做吗?谢谢,附件是例程