writesja1000(MODADDR, 0x09);
//设置方式寄存器,进入复位操作以初始化
writesja1000(CDRADDR, 0x88);
//设置时钟分频寄存器,选PeliCAN模式
writesja1000(AMR0ADDR, AMR0 );
//设置接收屏蔽寄存器0
writesja1000(AMR1ADDR, AMR1);
//设置接收屏蔽寄存器1
writesja1000(AMR2ADDR, AMR2);
//设置接收屏蔽寄存器2
writesja1000(AMR3ADDR, AMR3);
//设置接收屏蔽寄存器3
writesja1000(ACR0ADDR, ACR0);
//设置接收验收代码寄存器0
writesja1000(ACR1ADDR, ACR1);
//设置接收验收代码寄存器1
writesja1000(ACR2ADDR, ACR2);
//设置接收验收代码寄存器2
writesja1000(ACR3ADDR, ACR3);
//设置接收验收代码寄存器3
writesja1000(BTR0ADDR, 0x03);
//设置总线定时器0
writesja1000(BTR1ADDR, 0xFF);
//设置总线定时器1
writesja1000(OCRADDR, 0xAA);
//设置输出寄存器
writesja1000(RBSAADDR, 0x00);
//设置接收数据缓冲区首地址
writesja1000(TXERRADDR, 0x00);
//清除发送错误寄存器
writesja1000(RXERRADDR, 0x00);
//清除接收错误寄存器
readsja1000(ECCADDR);
//清除错误代码捕捉寄存器
writesja1000(IERADDR, 0xFF);
//打开中断使能寄存器
writesja1000(MODADDR, 0x08);
//设置方式寄存器,进入政党操作模式以收发数据
writesja1000()和readsja1000()是封装好的底层函数,其具体实现如下:
static void writesja1000(unsigned char addr, unsigned char data)
{
*SJAADDR = addr;
*SJADATA = data;
}
static unsigned char readsja1000(unsigned char addr)
{
*SJAADDR = addr;
return *SJADATA;
}