- UID
- 121393
- 性别
- 男
|
我写了个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(;;) {
}
} |
|