sja1000发送缓冲区写发送数据总是提示写错误,会是什么原因?大家帮忙看一下。下面是我的发送函数。(sja1000初始化正常)运行进入第二else的switch语句时直接跳到default:status = SJA_WTXBUF_ERR;语句,我要发送的数据是
unsigned char data send_data[11]={0x08,0xaa,0x40,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
发送函数:
char SJASendData(unsigned char *databuf,
unsigned char cmd
)
{
char status=0;
unsigned char len=0;
unsigned char temp = (*databuf&0x0f);
if(temp>8)temp=8;
if( (ReadSJAReg(REG_CAN_SR)&TCS_BIT) ==0)
//sja1000发送缓冲区锁定(0) 释放状态(1)才可写
{
status = SJA_TXBUFLOCK;
}
else if( (ReadSJAReg(REG_CAN_SR)&RS_BIT) !=0)
//正在接收(1) ,空闲(0)状态才可发送
{
status = SJA_WTXBUF_ERR;
}
else //发送缓冲区释放状态,没有在接受数据,可发送
{
switch(*databuf&0xC0)
{
case 0x00://标准帧、数据帧
len=STD_FRAMEID_LENTH+temp+1;
WriteSJARegBlock(REG_CAN_TXFMINFO,databuf,len);
status=SJASystemPrgCMD(cmd);
break;
case 0x40://标准帧、远程帧
len=STD_FRAMEID_LENTH+1;
WriteSJARegBlock(REG_CAN_TXFMINFO,databuf,len);
status=SJASystemPrgCMD(cmd);
break;
case 0x80://扩展帧、数据帧
len=EXT_FRAMEID_LENTH+temp+1;
WriteSJARegBlock(REG_CAN_TXFMINFO,databuf,len);
status=SJASystemPrgCMD(cmd);
break;
case 0xC0://扩展帧、远程帧
len=EXT_FRAMEID_LENTH+1;
WriteSJARegBlock(REG_CAN_TXFMINFO,databuf,len);
status=SJASystemPrgCMD(cmd);
break;
default:status = SJA_WTXBUF_ERR;
break;
}
}
return status;
} |