Board logo

标题: [求助]CAN程序,初次用C32做,强人指点! [打印本页]

作者: suckmyball    时间: 2006-6-19 15:18     标题: [求助]CAN程序,初次用C32做,强人指点!

做一个CAN的接口板,用的是MC9S12C32单片机,下面是我写的程序,不知道对不对,但总是调不通。用DG128单片机作接受。CAN收发器用的是MAX3050。还有,datasheet上看,接收中断号为38,但总是进不去。


void can_init(void){
   CANCTL0_INITRQ=1;          // msCAN Initialization Mode
   while(!CANCTL1_INITAK);    //1 = Initialization Mode Active MSCAN has entered Initialization Mode.
   CANCTL1_CANE=1;              // CAN enable;
   CANIDAC=0x23;               //8*8 filter;
   CANBTR1_TSEG_20 =5;  /* Tseg2=6 */
   CANBTR1_TSEG_10 =8; /* Tseg1=9 */
   CANIDAR0=0x00;
   CANIDAR1=0x01;
   CANIDAR2=0x02;
   CANIDAR3=0x03;
   CANIDAR4=0x41;
   CANIDAR5=0x41;
   CANIDAR6=0x41;
   CANIDAR7=0x41;
  
   CANIDMR0=0xff;
   CANIDMR1=0xff;
   CANIDMR2=0xff;
   CANIDMR3=0xff;
   CANIDMR4=0xff;
   CANIDMR5=0xff;
   CANIDMR6=0xff;
   CANIDMR7=0xff;
  
   CANBTR0=0x63;           //SJW1:SJW0=0:1;Synchronization jump width 2 Tq clock cycles
   CANBTR1=0x13;           //SAMP=one time;time segment 2=2 Tq clock cycles
   CANCTL0_INITRQ=0;         //INITRQ=0
   while(CANCTL1_INITAK);    // confirm that msCAN has quitted from initialization mode;
   //CANRIER=0x01;         
  
   //CANTIER=0x07;             //msCAN  Interrupt Enable
 }


 void can_transmission(void){
      CANTBSEL=CANTFLG;
      CANTXIDR0=0x10;
      CANTXIDR1=0x11;
      CANTXDSR0=0x47;
      CANTXDSR1=0x47;
      CANTXDSR2=0x46;
      CANTXDSR3=0x45;
      CANTXDSR4=0x44;
      CANTXDSR5=0x43;
      CANTXDSR6=0x47;
      CANTXDSR7=0x48;
      CANTXDLR=8;      //
      CANTXTBPR=0x00;        //设置发送缓冲区优先级
      CANTFLG=CANTBSEL;
      }


void main(void) {
  /* put your own code here */
 
  can_init();
  EnableInterrupts;
  for(;;) {can_transmission();} /* wait forever */
}






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