21ic问答首页 - LIN的自动波特率问题
LIN的自动波特率问题
shitou458232582022-03-21
大神们好!按照PIC16F18系列自动波特率的时序,在LIN_RX_IDLE里面,ABD使能,在LIN_RX_SYNC里面,读一次RC1REG将RCIF置0,波特率自动填充SP1BRG里面。现在在LIN_RX_SYNC里面,SPIBRG的值读出是对的,但是程序跳到LIN_RX_PID里面,读出PID报错,数据为0。请大神们指点,谢谢!case LIN_RX_IDLE:
if(EUSART1_is_rx_ready() > 0){
//Start Timer
LIN_startTimer(READ_TIMEOUT);
LIN_rxInProgress = true;
LIN_rxState = LIN_RX_BREAK;
BAUD1CONbits.ABDEN = 1;//set auto baud detection
}
break;
case LIN_RX_BREAK:
if(EUSART1_is_rx_ready() > 0){
if(LIN_breakCheck() == true){ //Read Break
LIN_rxState = LIN_RX_SYNC;
} else {
LIN_rxState = LIN_RX_ERROR;
}
}
break;
case LIN_RX_SYNC:
if(EUSART1_is_rx_ready() > 0){
while (BAUDCONbits.ABDEN == 1)
{
if (BAUDCONbits.ABDOVF == 1)
{
BAUDCONbits.ABDEN = 0; // abort auto baud
BAUDCONbits.ABDOVF = 0; // start auto baud
BAUDCONbits.ABDEN = 1; // restart auto baud
}
}
index = EUSART1_Read();
RC1REG_DATA=RC1REG;
if((SP1BRGL+(SP1BRGH<<8))>0)
{
LIN_rxState = LIN_RX_PID;
}else
{
LIN_rxState = LIN_RX_ERROR;
}
}
break;
if(EUSART1_is_rx_ready() > 0){
//Start Timer
LIN_startTimer(READ_TIMEOUT);
LIN_rxInProgress = true;
LIN_rxState = LIN_RX_BREAK;
BAUD1CONbits.ABDEN = 1;//set auto baud detection
}
break;
case LIN_RX_BREAK:
if(EUSART1_is_rx_ready() > 0){
if(LIN_breakCheck() == true){ //Read Break
LIN_rxState = LIN_RX_SYNC;
} else {
LIN_rxState = LIN_RX_ERROR;
}
}
break;
case LIN_RX_SYNC:
if(EUSART1_is_rx_ready() > 0){
while (BAUDCONbits.ABDEN == 1)
{
if (BAUDCONbits.ABDOVF == 1)
{
BAUDCONbits.ABDEN = 0; // abort auto baud
BAUDCONbits.ABDOVF = 0; // start auto baud
BAUDCONbits.ABDEN = 1; // restart auto baud
}
}
index = EUSART1_Read();
RC1REG_DATA=RC1REG;
if((SP1BRGL+(SP1BRGH<<8))>0)
{
LIN_rxState = LIN_RX_PID;
}else
{
LIN_rxState = LIN_RX_ERROR;
}
}
break;
您需要登录后才可以回复 登录 | 注册