我用的是S51+SJA1000+TJA1050做的两个一样的板子通信 一个发送一个接收 现在出现的问题是接收端老是提示数据溢出。下面是我的发送接收程序,懂行的帮我看看,提出意见,谢谢、!!
void init_can() { WriteSjaReg(REG_CONTROL,0x01); WriteSjaReg(REG_ACR,0x00); WriteSjaReg(REG_AMR,0xFF); WriteSjaReg(REG_BTR0,0x03); WriteSjaReg(REG_BTR1,0x1C); WriteSjaReg(REG_CDR,0x48); WriteSjaReg(REG_OCR,0xaa); WriteSjaReg(REG_CONTROL,0x1E); }
void SendData(void) { SendBuf[0] = 0x11; SendBuf[1] = 0x28; if((ReadSjaReg(REG_CONTROL)&0x01)==0) //JA1000处于工作模式 { if((ReadSjaReg(REG_CONTROL)&0x08)==0x08) { if((ReadSjaReg(REG_CONTROL)&0x04)==0x04) { *((unsigned char xdata *)REG_TxBuffer1) = 0x55; *((unsigned char xdata *)REG_TxBuffer2) = 0; *((unsigned char xdata *)REG_TxBuffer3) =0; *((unsigned char xdata *)REG_TxBuffer4) = 0; *((unsigned char xdata *)REG_TxBuffer5) = 0; *((unsigned char xdata *)REG_TxBuffer6) = 0; *((unsigned char xdata *)REG_TxBuffer7) = SendBuf[6]; *((unsigned char xdata *)REG_TxBuffer8) = 0; *((unsigned char xdata *)REG_TxBuffer9) = 0; *((unsigned char xdata *)REG_TxBuffer10) = 0;
BCAN_CMD_PRG(TR_CMD); //置位发送请求位 P2_1=0; } } } else //SJA1000在复位模式 { printf("SJA1000 is working as Reset Mode!
"); init_can(); } }
接收程序: void ReceiveData(void) { unsigned char DataLong; if(ReadSjaReg(REG_STATUS) & 0x01 == 0x01) { RcvBuf[0] = *((unsigned char xdata *)REG_RxBuffer1); RcvBuf[1] = *((unsigned char xdata *)REG_RxBuffer2); RcvBuf[2] = *((unsigned char xdata *)REG_RxBuffer3); RcvBuf[3] = *((unsigned char xdata *)REG_RxBuffer4); RcvBuf[4] = *((unsigned char xdata *)REG_RxBuffer5); RcvBuf[5] = *((unsigned char xdata *)REG_RxBuffer6); RcvBuf[6] = *((unsigned char xdata *)REG_RxBuffer7); RcvBuf[7] = *((unsigned char xdata *)REG_RxBuffer8); RcvBuf[8] = *((unsigned char xdata *)REG_RxBuffer9); RcvBuf[9] = *((unsigned char xdata *)REG_RxBuffer10);
//P2_1=0;
if(ReadSjaReg(REG_STATUS) & 0x03 == 0x03) { WriteSjaReg(REG_COMMAND,0x0c); //释放缓冲区并清除溢出标志 P2_2 = 0; (问题就在这里,这个LED亮,数据溢出!) } else { WriteSjaReg(REG_COMMAND,0x04);; //释放缓冲区 P2_3 = 0; } } } } |