我用自己做的COM-CAN收发器以及F2407能够很好的实现通讯,为什么GZ60不能收发呢?请各位大虾指教,我用的是GZ60的DEMO板作为硬件,我的程序如下:
CONFIG2=0x0f; CONFIG1=0x39; DDRC_DDRC0=1; DDRC_DDRC1=0; DDRC_DDRC5=0; DDRC_DDRC6=0;
init_CAN(); DDRF_DDRF0=1; DDRF_DDRF1=1; DDRF_DDRF2=1; DDRF_DDRF3=1; DDRF_DDRF4=1; DDRF_DDRF5=1; DDRF_DDRF6=1; DDRF_DDRF7=1; EnableInterrupts; /* enable interrupts */ PTF_PTF0=1; PTF_PTF1=1;
for(;;) {while(PTC_PTC6==1); PTF_PTF0=0; PTF_PTF1=1; delay(500); temp=CTFLG; temp=temp&0x07; switch(temp){ case 1:trans(0);while(CTFLG_TXE0==0);break; case 2:trans(1);while(CTFLG_TXE1==0);break; case 3:trans(0);while(CTFLG_TXE0==0);break; case 4:trans(2);while(CTFLG_TXE2==0);break; case 5:trans(0);while(CTFLG_TXE0==0);break; case 6:trans(1);while(CTFLG_TXE1==0);break; case 7:trans(0);while(CTFLG_TXE0==0);break; default : break; }; while(PTC_PTC5==1); PTF_PTF1=0; PTF_PTF0=1; };}
void init_CAN() {//CAN初始化 CMCR0=0x01; CMCR1=0x04; CBTR0=0x40;//4M=外部晶振8M/2 CBTR1=0xba;//3,3,10,250K //CIDAC=0x00; //CIDAR0=0x0c; //CIDAR1=0xfe; //CIDAR2=0x27; //CIDAR3=0x43; CIDMR0=0xff; CIDMR1=0xff; CIDMR2=0xff; CIDMR3=0xff; CMCR0=0x00; CRIER=0x0f; while(CMCR0!=0x00); }
interrupt void Can_int(void)//中断子程序 { //unsigned char i; //j=&REC_IDR0; //DisableInterrupts; if(CRFLG==CRFLG&0x01){ //for(i=0;i<=7;i++,j++){ //receive=*j; receive[0]= REC_DSR0; receive[1]= REC_DSR1; receive[2]= REC_DSR2; receive[3]= REC_DSR3; receive[4]= REC_DSR4; receive[5]= REC_DSR5; receive[6]= REC_DSR6; receive[7]= REC_DSR7; CRFLG=0x01; delay(500); temp=CTFLG; temp=temp&0x07; while(temp!=0){ trans(0); }
} ; //EnableInterrupts; } |