Board logo

标题: [求助] [打印本页]

作者: 张俊野    时间: 2008-10-30 21:47     标题: [求助]

那位大哥 能帮小弟看看这个程序怎么发不出数去啊 我都要疯了 好几天就看这几句话 也调不通

我在这里谢谢了 帮我看看 这个can程序吧。

#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
unsigned char data0;
unsigned char id0=0x12;
unsigned char id1=0x00;
unsigned char len=0x08;
unsigned char data1[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
void DELAYNS(unsigned int k)
{
unsigned int j=10000;
while(j--)
for(;k>0;k--);
}
void CAN_Init(void) {

CAN0CTL0 = 0x01;
while(!(0x01&CAN0CTL1));
CAN0CTL1_CANE = 1;
CAN0CTL1_LISTEN = 0;
CAN0BTR0 = 0x01;
CAN0BTR1 = 0x10;
CAN0IDAC = 0X10;
CAN0CTL0_INITRQ = 0;
while((0x01&CAN0CTL1)!=0);
}
void CAN_Send(void){
unsigned char txbuf;
CAN0TBSEL = CAN0TFLG;
txbuf = CAN0TBSEL;
CAN0TXIDR0 = id0;
CAN0TXIDR1 = id1;

CAN0TXDSR0 = data1[0];
CAN0TXDSR1 = data1[1];
CAN0TXDSR2 = data1[2];
CAN0TXDSR3 = data1[3];
CAN0TXDSR4 = data1[4];
CAN0TXDSR5 = data1[5];
CAN0TXDSR6 = data1[6];
CAN0TXDSR7 = data1[7];

CAN0TXDLR = len;
CAN0TXTBPR = 0;
CAN0TFLG = txbuf;
}
void main(void) {
unsigned int i;
DELAYNS(0x4000);
CAN_Init();
DELAYNS(0x4000);
for(i=0;i<100;i++){

DELAYNS(0x1000);
DELAYNS(0x1000);
DELAYNS(0x1000);
CAN_Send();
}

}


作者: fayefayehoo    时间: 2008-10-31 16:07

收发器的使能在哪里?

是canl、canh上没信号还是tx脚上没信号?


作者: 张俊野    时间: 2008-10-31 19:19

不是CAN0TBSEL = CAN0TFLG; CAN0TFLG = txbuf;

这两条语句控制的吗 ?

tx上就没信号。各位 帮帮我把 我真的没办法了 等着用这个呢 。


作者: 张俊野    时间: 2008-10-31 19:24

CAN0CTL1_CANE = 1;
这个是啊
作者: fayefayehoo    时间: 2008-11-4 10:24

没使能transceiver的话,TX脚信号还是应该有的。

can的时钟源再选一下。

CAN0CTL1_CLKSRC

0 -> Oscillator Clock as MSCAN clock
1 -> Bus Clock as MSCAN clock

[此贴子已经被作者于2008-11-4 10:24:45编辑过]






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