我要用C8051F506实现只发送不接收,只能由计算机上的CAN卡来接收,而不能被CAN总线上的其他设备(CAN上只有这种设备和计算机CAN卡)接收。这样,若计算机不接收或网络故障时,设备就会阻塞,从而有指示灯指示发送故障。现在的情况是,若CAN上只有两个同样的设备时,其中一个发送会被另外一个确认了。请教大家,怎么实现只发送而不接收任何报文呢?
我的初始化程序如下:
/// <summary>
/// 初始化CAN
/// </summary>
/// <returns></returns>
void Init_Can(void)
{
uint8_t i;
SFRPAGE = CAN0_PAGE;
CAN0CN |= 0x01; // Start Intialization mode
CAN0CN |= 0x4E; // Enable Status, Error, Module Interrupts, Enable access to bit timing register
// CAN0BT = 0x5CCF; //Based on 16 Mhz CAN clock, set the CAN bit rate to 50kbps
CAN0BT = 0x5CCB; //12Mhz CAN clock, set the CAN bit rate to 50kbps
// CAN0BT = 0x49C7; //125K
// CAN0BT = 0x49C3; //250K
// CAN0BT = 0x49C1; //500K
// CAN0BT = 0x49C0; //1M,不用
CAN0IF1CM = 0x00F0; // Write Operation, Transfer ID Mask, MDir, MXtd, Transfer ID, Dir, Xtd,
//MsgVal, Transfer Control Bits, Don't set TxRqst or transfer data
for (i = 1; i <= 32; i++)
{
// Set remaining message objects to be Ignored
CAN0IF1A2 = 0x0000; // Set MsgVal to 0 to Ignore
CAN0IF1CR = i; // Start command request
while (CAN0IF1CRH & 0x80) {} // Poll on Busy bit
}
//即使将下面这个for()注释,也即所有32个message object设置为无效,也不能阻止接收
for (i = 1; i <= MAX_MESSAGE_OBJ; i++)
{
CAN0IF1M1 = 0xffff; // 29位ID
CAN0IF1M2 = 0xffff; // Enable Extended Identifier for filtering, Used Direction bit for filtering, Use ID bits 28-0 for filtering
CAN0IF1MC = 0x1880 | 5; // Enable Transmit Interrupt, Message Object is a Single Message, Message Size set by #define
CAN0IF1A1 = DeviceID;
CAN0IF1A2 = 0xe000 | (DeviceID >> 16);//Msgval为1
CAN0IF1MC = 0x0880 | 5;
CAN0IF1CR = i;
while (CAN0IF1CRH & 0x80) {} // Poll on Busy bit
}
CAN0CN &= ~0x41; // Return to Normal Mode and disable
// access to bit timing register
SFRPAGE = ACTIVE_PAGE;
}
} |