大虾们帮我看看毛病出哪了。初始化MODR时就跳步出去,一直循环,我的读SJA1000程序有错吗?用的是MEGA162单片机
uint Read_SJA1000(uint address)
{
uchar data;
asm("nop");
ALE_on;
asm("nop");
DDRA=0xff;
PORTA=address;
asm("nop");
ALE_off;
asm("nop");
cs_on;
asm("nop");
rd_on;
asm("nop");
DDRA=0x00;
PORTA=0xff;
asm("nop");
data=PINA;
asm("nop");
rd_off;
cs_off;
asm("nop");
return data;
}
void Write_SJA1000(uint address , uint data)
{
asm("nop");
ALE_on;
asm("nop");
DDRA=0xff;
PORTA=address;
asm("nop");
ALE_off;
asm("nop");
cs_on;
asm("nop");
wr_on;
asm("nop");
PORTA=data;
asm("nop");
wr_off;
cs_off;
asm("nop");
asm("nop");
}
void initSJA1000()
{
uchar i,j;
CLI();
Write_SJA1000(MODR , 0x01);//复位模式
while(!(Read_SJA1000(MODR)&0x01))
{
Write_SJA1000(MODR , 0x01); //到这就一直跳步出去,一直循环
}
Write_SJA1000(CDR , 0x88);
Write_SJA1000(BTR0 , 0x40);
Write_SJA1000(BTR1 , 0x1C);
Write_SJA1000(OCR , 0x1A);
Write_SJA1000(ACR0 , 0x00);
Write_SJA1000(ACR1 , 0x00);
Write_SJA1000(ACR2 , 0x00);
Write_SJA1000(ACR3 , 0x00);
Write_SJA1000(AMR0 , 0xFF);
Write_SJA1000(AMR1 , 0x00);
Write_SJA1000(AMR2 , 0xFF);
Write_SJA1000(AMR3 , 0x00);
Write_SJA1000(EWLR , 0xff);
do
{
Write_SJA1000(MODR , 0x00);
}while((Read_SJA1000(MODR))&0x01);
Write_SJA1000(IER , 0x07);
SEI();
} |