pic18F66k80 ECAN應用

作者 blue_sky82 於 2019年03月22日 14:16:53
pic18F66k80 CAN設定後,在CAN Bus上沒有看到訊號。

MCU輸出的地方用示波器量測波形,(供5V)上電後維持5V電壓。

請問一下設定有錯誤嗎?

void InitECAN(void)
{
// Enter CAN module into config mode
CANCON = 0x80; //REQOP<2:0>=100
while(!(CANSTATbits.OPMODE ==0x04));

// Enter CAN module into Mode 0
ECANCON = 0x00;

// Initialize CAN Timing
// 16Mhz 250 Kbps
BRGCON1 = ECAN_SJW << 6;
BRGCON1 |= ECAN_BRP; //BRGCON1 = 0x84; //1000 0100

BRGCON2 = ECAN_PHSEG1 << 3;
BRGCON2 |= ECAN_PROPSEG; //BRGCON2 = 0x19; //0001 1001

BRGCON3 = ECAN_PHSEG2; //BRGCON3 = 0x03; //0000 0011

// Initialize Receive Masks
// The first mask is used that accepts all SIDs and no EIDs
RXM0EIDH = 0x00; //
RXM0EIDL = 0x00;
RXM0SIDH = 0xFF; // Standard ID FILTER
RXM0SIDL = 0xE0;

// The second mask is used to ignore all SIDs and EIDs
RXM1EIDH = 0x00; // 0's for EID and SID
RXM1EIDL = 0x00;
RXM1SIDH = 0xFF;
RXM1SIDL = 0xE0;

// Enable Filters
// Only using two filters
RXFCON0 = 0x03; //Disable all
RXFCON1 = 0x00; //Disable all

// Initialize Receive Filters
// Filter 0 = 0x196
// Filter 1 = 0x19E

RXF0EIDH = 0x00;
RXF0EIDL = 0x00;
RXF0SIDH = 0x32;
RXF0SIDL = 0xC0;

RXF2EIDH = 0x00;
RXF2EIDL = 0x00;
RXF2SIDH = 0x33;
RXF2SIDL = 0xC0;


// Enter CAN module into normal mode
CANCON = 0x00;
while(CANSTATbits.OPMODE==0x00);

// Set Receive Mode for bufferns
RXB0CON = 0x00;
RXB1CON = 0x00;

}

來自: http://www.microchip.com.tw/newbb/viewtopic.php?forum=1&topic_id=22575&post_id=79392