|
点击此处下载 ourdev_477258.rar(文件大小:392K) (原文件名:万利CAN和串口调成功.rar)
滤波器设置:
CAN_wrFilter (33, STANDARD_FORMAT); // Enable reception of messages
子程序:
void CAN_wrFilter (unsigned int id, unsigned char format) {
static unsigned short CAN_filterIdx = 0;
unsigned int CAN_msgId = 0;
if (CAN_filterIdx> 13) { // check if Filter Memory is full
return;
}
// Setup identifier information
if (format == STANDARD_FORMAT) { // Standard ID
CAN_msgId |= (unsigned int)(id << 21) | CAN_ID_STD;
} else { // Extended ID
CAN_msgId |= (unsigned int)(id << 3) | CAN_ID_EXT;
}
CAN->FMR |= CAN_FMR_FINIT; // set Initialisation mode for filter banks
CAN->FA0R &= ~(unsigned int)(1 << CAN_filterIdx); // deactivate filter
// initialize filter
CAN->FS0R |= (unsigned int)(1 << CAN_filterIdx);// set 32-bit scale configuration
CAN->FM0R |= (unsigned int)(1 << CAN_filterIdx);// set 2 32-bit identifier list mode
CAN->sFilterRegister[CAN_filterIdx].FR0 = CAN_msgId; // 32-bit identifier
CAN->sFilterRegister[CAN_filterIdx].FR1 = CAN_msgId; // 32-bit identifier
CAN->FFA0R &= ~(unsigned int)(1 << CAN_filterIdx); // assign filter to FIFO 0
CAN->FA0R |= (unsigned int)(1 << CAN_filterIdx); // activate filter
CAN->FMR &= ~CAN_FMR_FINIT; // reset Initialisation mode for filter banks
CAN_filterIdx += 1; // increase filter index
}
请教大家本机地址是十进制33吗?我要使滤波器不屏蔽在哪里设置?这个程序我跟智林的扳子可以通讯,但跟SJA1000始终不能通讯,不知问题在哪里?
能够解释一下这是在干吗:1 << CAN_filterIdx,没有见过. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|