- UID
- 123796
- 性别
- 男
|
单片机是MC9S12DG256,CAN用中断方式接收,并且定时发送CAN消息,问题是接收BUFFER满触发中断后,读取ID接收寄存器的值,在正确的接收ID和我发送的CAN帧的ID之间变化,难道我发送的ID也会被写入到接收ID里面了吗?还有就是验收寄存器也没起什么作用,要么就无法接收任何帧,要么就起不到验收作用,我的初始化程序如下:
void MSCAN0_Init(void) {
CAN0CTL0|=0x01; //软复位控制位
while(!(CAN0CTL0&0x01))//是否进入软复位状态
{}
CAN0BTR0 = 0xC1;
CAN0BTR1 = 0x3A; //Bit Rate=500k
//CAN0BTR0 = 0x0F; /*CAN0BTR0 = 0x0F; set SJW=1, Prescaler value=8*/
//CAN0BTR0 = 0x44;
//CAN0BTR1 = 0x91; /*CAN0BTR1 = 0x91; set TSEG2=2,TSEG1=2 Bit Rate=200k*/
CAN0IDAC = 0x01; //两路32位验收
CAN0IDAR0 = 0x67;
CAN0IDAR1 = 0x9A;
CAN0IDAR2 = 0x0B;
CAN0IDAR3 = 0xA0;
CAN0IDAR4 = 0x67;
CAN0IDAR5 = 0x9A;
CAN0IDAR6 = 0x0B;
CAN0IDAR7 = 0xA0;
CAN0IDMR0 = 0xFF;
CAN0IDMR1 = 0xFF;
CAN0IDMR2 = 0xFF;
CAN0IDMR3 = 0xFF;
CAN0IDMR4 = 0x00;
CAN0IDMR5 = 0x00;
CAN0IDMR6 = 0x00;
CAN0IDMR7 = 0x00;
CAN0CTL1 = 0x80; // CANCTL1_CANE = 1;MSCAN使能
CAN0CTL0_INITRQ = 0; //正常操作
//INTTRQ的清0操作与CMCR0中其他位的写入操作禁止在同一条指中完成
while(CAN0CTL1_INITAK != 0)
{
}
CAN0CTL0_TIME = 1; /*enable internal timer*/
CAN0RIER = 0x01; /*only enable receive buffer full interrupt*/
}
中断进入没问题,感觉是CAN的原理方面,请版主大哥赐教! |
|