有人遇到过LIN 通信的这个问题吗?
时间:10-02
整理:3721RD
点击:
LIN 通信时 同步段的 数据 0X55 怎么都收不到数据?怎么解决?
这是初始化程序:
void LIN_Init(US usBaud)
{
SCISR2 &= 0x7f ; // 设置AMAP
SCIBD = (US)( (SystemBusClock/16)/usBaud ); //设置SCI波特率
SCICR1 = 0x00; //设置SCI0为正常模式,八位数据位,无奇偶校验
SCICR1 = 0x04;
SCICR2 = 0x2c; //允许接收和发送数据,允许接收中断功能
SCICR1|=(1<<2);
SCISR2 |=(1<<2); //设置BRK13 13位间隔符
}
这是接收函数:
UC LIN_GetChar(LIN_Frame *Frame_Receive)
{
static UC ch;
// LIN接收通道状态
switch(Frame_Receive->State)
{
case IDLE:
if(!( SCISR1&0x22) )
return(FALSE);
if(SCIDRL)
return(FALSE);
break;
case _BREAK:
if(!(SCISR1_RDRF))
return(FALSE);
if(SCIDRL!=0x55);
return(FALSE); /* 程序 一直 死在这里 , 一直收不到 0X55 的数据 */
break;
case SYNCH: /* 获取 ID */
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->PID = ch;
break;
case PROTECTED_IDENTIFIER:
case DATA0:
case DATA1:
case DATA2:
case DATA3:
case DATA4:
case DATA5:
case DATA6:
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->Data[Frame_Receive->State-PROTECTED_IDENTIFIER] = ch;
break;
case DATA7:
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->Check = ch;
break;
case CHECKSUM:
return(FALSE);
}
Frame_Receive->State+=1;
return(TRUE);
}
这是初始化程序:
void LIN_Init(US usBaud)
{
SCISR2 &= 0x7f ; // 设置AMAP
SCIBD = (US)( (SystemBusClock/16)/usBaud ); //设置SCI波特率
SCICR1 = 0x00; //设置SCI0为正常模式,八位数据位,无奇偶校验
SCICR1 = 0x04;
SCICR2 = 0x2c; //允许接收和发送数据,允许接收中断功能
SCICR1|=(1<<2);
SCISR2 |=(1<<2); //设置BRK13 13位间隔符
}
这是接收函数:
UC LIN_GetChar(LIN_Frame *Frame_Receive)
{
static UC ch;
// LIN接收通道状态
switch(Frame_Receive->State)
{
case IDLE:
if(!( SCISR1&0x22) )
return(FALSE);
if(SCIDRL)
return(FALSE);
break;
case _BREAK:
if(!(SCISR1_RDRF))
return(FALSE);
if(SCIDRL!=0x55);
return(FALSE); /* 程序 一直 死在这里 , 一直收不到 0X55 的数据 */
break;
case SYNCH: /* 获取 ID */
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->PID = ch;
break;
case PROTECTED_IDENTIFIER:
case DATA0:
case DATA1:
case DATA2:
case DATA3:
case DATA4:
case DATA5:
case DATA6:
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->Data[Frame_Receive->State-PROTECTED_IDENTIFIER] = ch;
break;
case DATA7:
if(!(SCISR1_RDRF))
return(FALSE);
ch = SCIDRL;
Frame_Receive->Check = ch;
break;
case CHECKSUM:
return(FALSE);
}
Frame_Receive->State+=1;
return(TRUE);
}
已经解决