Board logo

标题: [求助]DG128 CAN 问题 [打印本页]

作者: 毛毛虫    时间: 2007-12-9 14:27     标题: [求助]DG128 CAN 问题

我写了个MSCAN的程序,但调试不通,请问什么原因?
我初始化时,开了接收中断,用Loopback Self Test Mode,在CAN中断中用了断点,但是程序运行不到断点。
源程序如下:
void InitCAN(unsigned char nChan){
MODRR = 0x00;

while(!CAN0CTL1_INITAK) //Initialization Mode
CAN0CTL0_INITRQ = 1;

CAN0CTL1_CANE = 1; //Enable CAN0
CAN0CTL1_CLKSRC = 0; //Fcan = Foscclk
CAN0CTL1_LOOPB = 1; //Loopback Self Test Mode

CAN0BTR0 = 0x32; //SJW = 0,Baud Rate Prescaler = 50
CAN0BTR1 = 0xD8; //SA MP = 1,Time Segment 2 = 6,Time Segment 1 = 9

CAN0IDAC_IDAM = 0;

CAN0IDMR0 = 0xff;
CAN0IDMR1 = 0xff;
CAN0IDMR2 = 0xff;
CAN0IDMR3 = 0xff;
CAN0IDMR4 = 0xff;
CAN0IDMR5 = 0xff;
CAN0IDMR6 = 0xff;
CAN0IDMR7 = 0xff;

CAN0IDAR0 = 0x00;
CAN0IDAR1 = 0x00;
CAN0IDAR2 = 0x00;
CAN0IDAR3 = 0x00;
CAN0IDAR4 = 0x00;
CAN0IDAR5 = 0x00;
CAN0IDAR6 = 0x00;
CAN0IDAR7 = 0x00;

while(CAN0CTL1_INITAK)
CAN0CTL0_INITRQ = 0; //Normal Mode

CAN0RIER_RXFIE = 1; //Enable Receiver Full Interrupt
}

byte CAN0_SendFrame(byte BufferNum,dword CANID,byte FrameType,byte Length,byte *Data)
{
unsigned char *adr,i;

CAN0TXIDR0 = CANID >> 3;
CAN0TXIDR1 = CANID << 5;
if(FrameType) CAN0TXIDR1 |= 0x10;
else CAN0TXIDR1 &= 0xef;
CAN0TXIDR1 &= 0xf7;

adr = &CAN0TXDSR0;
for(i=0;i
CAN0TXDLR = Length;

switch(BufferNum){
case 0:
if(CAN0TFLG_TXE0) {
CAN0TFLG_TXE0 = 0;
CAN0TBSEL_TX0 = 1;
}
else return ERR_TXFULL;
break;
case 1:
if(CAN0TFLG_TXE1) {
CAN0TFLG_TXE1 = 0;
CAN0TBSEL_TX1 = 1;
}
else return ERR_TXFULL;
break;
case 2:
if(CAN0TFLG_TXE2) {
CAN0TFLG_TXE2 = 0;
CAN0TBSEL_TX2 = 1;
}
else return ERR_TXFULL;
break;
default:
return ERR_VALUE;
}
return ERR_OK;
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 38 void CAN0RX_ISR(void) {

CAN0RFLG_RXF = 1;
}
#pragma CODE_SEG DEFAULT

void main(void) {
InitCAN(0);
EnableInterrupts;
CAN0_SendFrame(0,CANID0,0,8,buf);
for(;;) {
}
}
作者: 毛毛虫    时间: 2007-12-11 11:26

附件为我做的一个CAN的工程,在Loopback Self Test Mode下,CAN能收到信息并通过串口1发送到计算机上显示。
当把// CAN0CTL1_LOOPB = 1;注释掉后,也就是CAN处于正常收发模式时,我用PCICAN卡能收到数据,但XDP512上的CAN收不到数据。
请问为什么?http://bbs.chinaecnet.com/uploadImages/TestCan1.rar




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0