初始化程序如下:
void ECAN_init(void)
{
TRISB2=0;
TRISB3=1;
// Put module into Configuration mode.
ECANSetOperationMode(ECAN_MODE_CONFIGURATION);
//boudrate=250K Fosc=8M Tbit=4us BRP=2 ==> TQ=[2*BRP]/Fosc=0.5us
//SJW=1 Nominal bitrate=8TQ (Sync_seg=1TQ propseg=1TQ phseg1=3TQ phseg2=3TQ)
ECANSetBaudRate(2,1,1,3,3,1,0,0,1); //(BRP, SJW, Propseg, Phseg1, Phseg2, SEG2PHTS,SAM,WAKDIS,WAKFIL)
//Initialize ECAN I/O(Set CANTX2, TXDRIVE and CAN Capture modes.)
CANIOControl(0x20); // CANTx VDD ,disable capture
//Set ECAN functional mode.
ECANCON=0x10; //mode0 legacy mode ,RB0
// Set RXB0 and RXB1 buffer modes.
RXB0CON=(ECAN_RECEIVE_ALL_VALID <<5)|(ECAN_DBL_BUFFER_MODE_DIS<<2);
RXB1CON=(ECAN_RECEIVE_ALL_VALID <<5);
RXB0D0=0; RXB1D0=0;
RXB0D1=0x6A; RXB1D1=0;
RXB0D2=0; RXB1D2=0;
RXB0D3=0; RXB1D3=0;
RXB0D4=0; RXB1D4=0;
RXB0D5=0; RXB1D5=0;
RXB0D6=0; RXB1D6=0;
RXB0D7=0; RXB1D7=0;
//Initialize the Recieve Filter & Mask Registers
CANFilterMask(ECAN_TX_ETD_FRAME);
//set ECAN Operation mode
//ECANSetOperationMode(ECAN_MODE_NORMAL);
ECANSetOperationMode(ECAN_MODE_LOOPBACK);
//Initialize ECAN interrupt
//PIE3: IRXIE WAKIE ERRIE TXB2IE TXB1IE TXB0IE RXB1IE RXB0IE
PIR3=0x00; //clear all interrupt
PIE3=0x01; //enable RXB0 intterput
IPR3=0x01; //
}
现象: 1)只使用一个MCU,烧录,调试,不能正常初始化,要在CNATX脚上点一下,用什么金属都可(只要触发一下即可),便可进入正常/回环模式。
2)相关的的PCBA,烧录,调试,无论如何都不能正常初始化,程序停在 ECANSetOperationMode(ECAN_MODE_LOOPBACK);这个位置
/********************ECANSetOperationMode************************************/
void ECANSetOperationMode(uint8 mode)
{
CANCON &= 0x1F; // clear previous mode
CANCON |= mode; // set new mode
while((ECANGetOperationMode())!= mode ); // Wait till desired mode is set.
}
/********************ECANGetOperationMode************************************/
uint8 ECANGetOperationMode(void)
{
return(CANSTAT&0xE0);
} |