片子是MC9S12DP256B,收发器是MC33388,现在就是想发送消息,然后在上位机接收。
16M晶振做时钟源,波特率是125K,下面是程序:
void CANInit(void) {
CAN0CTL0 = 0x01; /* 进入初始化模式
while (!(CAN0CTL1&0x01)){}; /* 等待初始化模式确认
CAN0CTL1 = 0x80; /* 使能MSCAN模块
CAN0BTR0 = 0xC7;
CAN0BTR1 = 0x3A;
CAN0IDAC = 0x10;
CAN0CTL0 = 0x00; /* Exit Initialization Mode Request */
while ((CAN0CTL1&0x01) != 0){}; /* Wait for Normal Mode */
}
void CAN_Transmit(void)
{ CAN0TBSEL= 0x01; CAN0TXIDR0 = 0x00; CAN0TXIDR1 = 0x08; //扩展桢 CAN0TXIDR2 = 0x00; CAN0TXIDR3 = 0x04; //发送ID=2 CAN0TXDSR0 = 200; CAN0TXDSR1 = 212; CAN0TXDSR2 = 111; CAN0TXDSR3 = 23; CAN0TXDSR4 = 89; CAN0TXDSR5 = 155; CAN0TXDSR6 = 199; CAN0TXDSR7 = 0; CAN0TXDLR = 0x08; CAN0TXTBPR = 0x00; CAN0TFLG = 0x01; }
#pragma CODE_SEG DEFAULT void main () {
CANInit(); for (;;) { CAN_Transmit(); }
}
运行后,测到的波形不正确。请各位指点指点 |