我用的是ATmage128+sja1000做的can总县通信,下面是SJA1000的初始化程序: #define REG_CONTROL 0x8000 //内部控制寄存器 #define REG_COMMAND 0x8001 //命令寄存器 #define REG_STATUS 0x8002 //状态寄存器 #define REG_INTERRUPT 0x8003 //中断寄存器 #define REG_ACR 0x8004 //验收代码寄存器 #define REG_AMR 0x8005 //验收屏蔽寄存器 #define REG_BTR0 0x8006 //总线定时寄存器0 #define REG_BTR1 0x8007 //总线定时寄存器1 #define REG_OCR 0x8008 //输出控制寄存器 #defineWriteSjaReg(Adr,value) *((unsigned char *)Adr)=value #defineReadSjaReg(Adr) *((unsignedchar *)Adr)
void sja_init() { WriteSjaReg(REG_CONTROL,0x01); while((ReadSjaReg(REG_CONTROL)&0x01)==0) { WriteSjaReg(REG_CONTROL,0x01); }
WriteSjaReg(REG_CDR,0x48); WriteSjaReg(REG_ACR,0x11); WriteSjaReg(REG_AMR,0x00); WriteSjaReg(REG_OCR,0xaa); WriteSjaReg(REG_BTR0,0x00); WriteSjaReg(REG_BTR1,0x1c); //500kbps WriteSjaReg(REG_CONTROL, 0x1E); //进入操作模式 while((ReadSjaReg(REG_CONTROL)&0x01)==1) { WriteSjaReg(REG_CONTROL,0x1E); } }
请教各位高手,我的读写函数有什么错吗?我的问题是数据没有写入进去,也没有读取到寄存器里面的值,请问这个问题怎么解决啊,谢谢!!
|