5230 views|1 replies
- Last login
- 2014-4-17
- Online Time
- 1 hours
- Prestige
- 0 points
- Points
- 0 points
|
|
When debugging today, the CAN card can receive the data sent, but the data sent by the CAN card cannot be received. What may be the reason? The communication part of the program is as follows. void DELAY(void) { for(i=5;--i;) continue; } void __attribute__((__interrupt__)) _T1Interrupt(void); void __attribute__((__interrupt__)) _T4Interrupt(void); void __attribute__((__interrupt__)) _ADCInterrupt(void); void __attribute__((__interrupt__)) _INT0Interrupt(void); //void __attribute__((__interrupt__)) _INT1Interrupt(void); //void __attribute__((__interrupt__)) _INT2Interrupt(void); void __attribute__((__interrupt__)) _C1Interrupt(void); // void initial(void) { IPC0=0X0000;//All interrupt sources are disabled IPC1=0X0000;//All interrupt sources are disabled IPC2=0X0000;//All interrupt sources are disabled IPC3=0X0000;//All interrupt sources are disabled IPC4=0X0000;//All interrupt sources are disabled IPC5=0X0000;//All interrupt sources are disabled PORTEbits.RE0=1; TRISEbits.TRISE8=1; IPC0bits.INT0IP=4; IFS0bits.INT0IF=0; IEC0bits.INT0IE=1; INTCON2=0X000E; //TMR1 T1CON=0X0000; TMR1=0X0000; PR1=0XDFFF; IPC0bits.T1IP=2; IFS0bits.T1IF=0; IEC0bits.T1IE=1; // T1CONbits.TON=1; //Switch input TRISEbits.TRISE1=1; TRISFbits.TRISF6=1; TRISCbits.TRISC14=1; TRISCbits.TRISC13=1; //TMR4 T4CON=0X0000; TMR4=0X0000; PR4=0X0FFF; IPC5bits.T4IP=5; IFS1bits.T4IF=0; IEC1bits.T4IE=1; T4CONbits.TON=1; // //AD TRISBbits.TRISB0=1; TRISBbits.TRISB1=1; TRISBbits.TRISB2=1; ADPCFG=0XFFF8; ADCSSLbits.CSSL0=1; ADCSSLbits.CSSL1=1; ADCSSLbits.CSSL2=1; ADCON3=0X0F05, ADCON2=0X0408; IPC2bits.ADIP=3; IFS0bits.ADIF=0; IEC0bits.ADIE=1; TRISDbits.TRISD2=0; PR3=0X03E8; OC3R=0X01F4; OC3RS=0X01F4; PWMOUT3(); // //can set TRISF=0X0001; canset1(); canset2(); canset3(); T1CONbits.TON=1; } // //can set void canset1(void) { C1CTRLbits.REQOP=4; while(C1CTRLbits.OPMODE!=0x4){} C1RX0CON=0x0000; // C1RXF0SID=0x0000; C1RXF0EIDH=0x0000; C1RXF0EIDL=0x0000; C1RXM0SID=0x0000; C1RXM0EIDH=0x0000; C1RXM0EIDL=0x0000; C1CTRLbits.CANCKS=0; C1CFG1bits.SJW=1-1; C1CFG1bits.BRP=4; //C1CFG2=0x024c; C1CFG2bits.PRSEG=3-1; C1CFG2bits.SEG1PH=2-1; C1CFG2bits.SAM=0; C1CFG2bits.SEG2PHTS=1; C1CFG2bits.SEG2PH=2-1; C1CFG2bits.WAKFIL=0; } // void canset2(void) { C1CTRLbits.REQOP=4; //Configuration modewhile(C1CTRLbits.OPMODE!=0x4){} C1CTRLbits.CANCAP=1; C1TX0CON=0x0003;//Highest message priority} //Set normal working modevoid canset3(void) { C1CTRLbits.REQOP=0; //Set normal working modeIPC6bits.C1IP=1; // C1INTFbits.RX0IF=0; C1INTF=0X0000; //Receive buffer 0 1 interrupt flagIFS1bits.C1IF=0; IEC1bits.C1IE=1; C1INTE=0X0003; //Receive buffer 0 1Enable interruptwhile(C1CTRLbits.OPMODE!=0X0000){} } //Set normal working mode 2 void canset4(void) { C1CTRLbits.REQOP=0; //Set normal working modewhile(C1CTRLbits.OPMODE!=0X0000){} } // void chudian(void) { if(PORTEbits.RE1==1) { k1=1;} else { k1=0;} if(PORTFbits.RF6==1) {k2=1;} else { k2=0;} if(PORTCbits.RC14==1) {k3=1;} else { k3=0;} if(PORTCbits.RC13==1) { k4=1;} else { k4=0;} } // void _INT0Interrupt(void) { DELAY(); IFS0bits.INT0IF=0; IEC0bits.INT0IE=0; PORTEbits.RE0=0; //Fault indicator light is on IEC0bits.INT0IE=1; } // void fasong(void) { C1TX0CONbits.TXREQ=1; //Start sending while (C1TX0CONbits.TXREQ==1) //Wait for sending to complete{for (ii=0;ii<200;ii++){} } } // void _T1Interrupt(void) { T1CONbits.TON=0; IEC0bits.T1IE=0; IFS0bits.T1IF=0; //IEC1bits.C1IE=0; ticount="TICOUNT+1; TICOUNT=3; " if (TICOUNT==1) { d1fabuffer01="0x0061; " c1tx0b1="D1fabuffer01; " c1tx0b2="D1fabuffer02; " c1tx0b3="D1fabuffer03; " c1tx0b4="D1fabuffer04;" canset2(); C1TX0SIDbits.TXIDE=1; C1TX0SIDbits.SRR=0; C1TX0SIDbits.SID10_6=0; C1TX0SIDbits.SID5_0=0; C1TX0EIDbits.EID17_14=0; C1TX0EIDbits.EID13_6=385; C1TX0DLCbits.EID5_0=36; C1TX0DLCbits.DLC=8; C1TX0DLCbits.TXRTR=0; C1TX0DLCbits.TXRB0=1; C1TX0DLCbits.TXRB1=1; canset4(); fasong(); } else if(TICOUNT==2) { // d2fabuffer01="0X1000; //" d2fabuffer02="0X2000; //" d2fabuffer03="0X3000; //" d2fabuffer04="0X4000; " d2fabuffer01="0x0062; " c1tx0b1="D2fabuffer01; " c1tx0b2="D2fabuffer02; " c1tx0b3="D2fabuffer03; " c1tx0b4="D2fabuffer04;" canset2(); C1TX0SIDbits.TXIDE=1; C1TX0SIDbits.SRR=0; C1TX0SIDbits.SID10_6=0; C1TX0SIDbits.SID5_0=0; C1TX0EIDbits.EID17_14=0; C1TX0EIDbits.EID13_6=385; C1TX0DLCbits.EID5_0=37; C1TX0DLCbits.DLC=8; C1TX0DLCbits.TXRTR=0; C1TX0DLCbits.TXRB0=1; //DCfabuffer03=0X0213; //DCfabuffer04=0X0312; dcfabuffer01="0x1000; " c1tx0b1="DCfabuffer01; " c1tx0b2="DCfabuffer02; " c1tx0b3="DCfabuffer03; " c1tx0b4="DCfabuffer04;" canset2(); C1TX0SIDbits.TXIDE=1; C1TX0SIDbits.SRR=0; C1TX0SIDbits.SID10_6=0; / C1TX0SIDbits.SID5_0=0; C1TX0EIDbits.EID17_14=1; C1TX0EIDbits.EID13_6=64; C1TX0DLCbits.EID5_0=17; C1TX0DLCbits.DLC=8; C1TX0DLCbits.TXRTR=0 C1TX0DLCbits.TXRB0=1; C1TX0DLCbits.TXRB1=1; canset4(); fasong(); ticount="0; } " /* else { dpfabuffer01="0X00CA; " dpfabuffer02="0X00A1; " dpfabuffer03="0X00C6; " dpfabuffer04="0X00B1;" c1tx0b1="DPfabuffer01; " c1tx0b2="DPfabuffer02; " c1tx0b3="DPfabuffer03; " c1tx0b4="DPfabuffer04;" canset2(); C1TX0SIDbits.TXIDE=0; C1TX0SIDbits.SRR=0; C1TX0SIDbits.SID10_6=20; C1TX0SIDbits.SID5_0=1; C1TX0DLCbits.DLC=8; C1TX0DLCbits.TXRTR=0; C1TX0DLCbits.TXRB0=1; C1INTFbits.TX0IF=0; IEC0bits.T1IE=1; T1CONbits.TON=1; // IEC1bits.C1IE=1; } // void _T4Interrupt(void) { IEC1bits.T4IE=0; T4CONbits.TON=0; IFS1bits.T4IF=0; chudian(); IEC1bits.T4IE=1; T4CONbits.TON=1; }
|
|