还是不行,上面4步我都检查了,还是一样的问题,一个节点收不到另外一个节点的应答信号,发送标志位一直为1,我查了另外一个节点的接入点(82c251的RX),有波形输入啊,那硬件应该没问题啊,自检也可以啊,程序我找了好多个,难道是程序的问题?
#include "SJA_BCANCONF.H"
#include <string.h>
/* 初始化SJA1000 */
unsigned char SJA1000_Config_Normal()
{
if(BCAN_CREATE_COMMUNATION()) return 1;//读写测试寄存器失败
if(BCAN_ENTER_RETMODEL()) return 2; //复位失败
if(BCAN_SET_OUTCLK (0x1a,0x88)) return 4;//设置OCR=0X1A,T0推挽输出 CDR=0X00,peli模式,输入没有启用旁路功能 时钟输出为 fOSC/2 失败
if(BCAN_SET_BANDRATE(0x00)) return 3; //设置波特率通信 失败
if(BCAN_SET_OBJECT(0x44,0x55,0x66,0x00,0x00,0x00,0x00,0x0f)) return 5;
if(BCAN_MODE_COMMUNATION(0x08)) return 8;//设置单滤波模式 包括恢复到工作模式
return 0;//初始化成功
}
#include "regx52.h" //创作时间2009-03-04
#include <intrins.h>
#include "lcd1602.c"
#include "key.c"
#include"SJA_BCANCONF.c"
bit SuccessFlag=1;
unsigned test=1;
unsigned temp;
//
void main()
{
SJA1000_RST=1;
delay1ms(200); //启动等待,等LCD讲入工作状态
LCDInit(); //LCD初始化
SJA1000_RST=0;//SJA1000硬件复位
delay1ms(2);
SJA1000_RST=1;
delay1ms(5);
DisplayOneChar(5,0,SJA1000_Config_Normal()+'0');//SJA1000 initial
SuccessFlag=BCAN_DATA_WRITE(SendData);//发数据
if(!SuccessFlag)
{
DisplayOneChar(10, 0, '0');
BCAN_CMD_PRG(TR_CMD); //启动发送命令
}
else DisplayOneChar(10, 0, '1');
SJA_BCANAdr = REG_STATUS; //访问地址指向状态寄存器
temp=*SJA_BCANAdr;
DisplayOneChar(4, 1, temp/100+'0');//显示SR的值
DisplayOneChar(5, 1,(temp/10)%10+'0');
DisplayOneChar(6, 1,temp%10+'0');
temp&=0x20;
while(temp == 0x20) //检查是否发送完成
{
DisplayOneChar(11, 0, '1');
temp=*SJA_BCANAdr;
DisplayOneChar(4, 1, temp/100+'0');
DisplayOneChar(5, 1,(temp/10)%10+'0');
DisplayOneChar(6, 1,temp%10+'0');
temp&=0x20;
}
DisplayOneChar(11, 0, '0');
test^=1;
led3=test;//test跟踪按键的变化
}break;
SJA_BCANAdr= REG_Receive_Counter;//查看接收缓冲区中信息的个数
temp=*SJA_BCANAdr;
DisplayOneChar(14, 1, temp/10+'0');
DisplayOneChar(15, 1, temp%10+'0');
SuccessFlag=BCAN_DATA_RECEIVE(ReceiveData);//接收数据
if(!SuccessFlag)
{
DisplayOneChar(15, 0, '0');
for(k=0;k<13;k++)//显示数据
{
DisplayOneChar(k, 1, ReceiveData[k]+'0');
}
}
else DisplayOneChar(15, 0, '1');
while(1);
}
code unsigned char SendData[13]={0x88,0x44,0x55,0x66,0x00,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x02}; //扩展帧,长度为8
unsigned char ReceiveData[13]={0,0,0,0,0,0,0,0,0,0,0,0,0}; //存放接收数据 |