I am confused with the description of the CAN messaeg filter in the LPC43xx manual. The cpu has 2 CAN interfaces. Every CAN interface has two message interface to filter the CAN bus for defined identifier. For each message interface I can define up to 32 identifier.
1) Does it mean, that I can define 64 identifier for CAN0 and 64 identifier for CAN1 or only 32 for CAN0 and 32 for CAN1?
2) If I can scan only 32 identifier for each CAN-bus (the picture in the manual at page 1236 shows this) - why I need two message interfaces for each CAN bus?
3) If I want to change the identifier or to remove it from the filter list - how to do this?
4) Is there any code example available to show the using/modification of message filter?
5) Can I change the message filter during running CAN-bus or should I disable the CAN-interrupt during this process?
Hi Andreas Kneissl,
This question nearly the same as your anther question, please refer to my reply in your anther question at first:
https://community.nxp.com/thread/441359
You can configure the can in the test mode, and enable the basic mode.
Please modify the code like this:
CCAN_MSG_OBJ_T can_msg;
void CAN0_IRQHandler(void)
{
CCAN_MSG_OBJ_T msg_buf;
uint32_t can_int, can_stat, i;
while ( (can_int = Chip_CCAN_GetIntID(LPC_C_CAN0)) != 0 ) {
//if ((can_int & CCAN_INT_STATUS) )
if ((CCAN_INT_STATUS == can_int) && (CCAN_STAT_RXOK & LPC_C_CAN0->STAT))
{
//CCAN_MSG_OBJ_T can_msg;
can_msg.id = (uint32_t) (LPC_C_CAN0->IF[1].ARB1 | LPC_C_CAN0->IF[1].ARB2 << 16);
if (can_msg.id & (0x1 << 30)){
can_msg.id &= CCAN_MSG_ID_EXT_MASK;
}
else {
can_msg.id >>= 18;
can_msg.id &= CCAN_MSG_ID_STD_MASK;
}
can_msg.dlc = (uint8_t) (LPC_C_CAN0->IF[1].MCTRL & CCAN_IF_MCTRL_DLC_MSK);
*((uint16_t *)&can_msg.data[0]) = (uint16_t) (LPC_C_CAN0->IF[1].DA1 & 0x0000FFFF);
*((uint16_t *)&can_msg.data[2]) = (uint16_t) (LPC_C_CAN0->IF[1].DA2 & 0x0000FFFF);
*((uint16_t *)&can_msg.data[4]) = (uint16_t) (LPC_C_CAN0->IF[1].DB1 & 0x0000FFFF);
*((uint16_t *)&can_msg.data[6]) = (uint16_t) (LPC_C_CAN0->IF[1].DB2 & 0x0000FFFF);
DEBUGOUT("can_msg ID :%x\r\n", can_msg.id);
DEBUGOUT("can_msg data :");
for (i = 0; i < can_msg.dlc; i++) {
DEBUGOUT("%x ", can_msg.data[i]);
}
DEBUGOUT("\r\nFeed back...\r\n");
Rx_Flag =1;
LPC_C_CAN0->STAT = LPC_C_CAN0->STAT & (~CCAN_STAT_RXOK);
return;
}
}
}
int main(void)
{
CCAN_MSG_OBJ_T send_obj;
SystemCoreClockUpdate();
Board_Init();
set_pinmux();
DEBUGOUT(WelcomeMenu);
/* Set CCAN peripheral clock under 100Mhz for working stable */
Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVC, true, false);
Chip_CCAN_Init(LPC_C_CAN0);
Chip_CCAN_EnableTestMode(LPC_C_CAN0);//jjadd
// Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));//jjadd //CCAN_TEST_SILENT_MODE |
Chip_CCAN_SetBitRate(LPC_C_CAN0, 500000);
Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));
send_obj.id = CCAN_TX_MSG_ID;
send_obj.dlc = 4;
send_obj.data[0] = 'A';
send_obj.data[1] = 'B';
send_obj.data[2] = 'C';
send_obj.data[3] = 'D';
Chip_CCAN_Send(LPC_C_CAN0, CCAN_MSG_IF1, false, &send_obj);
Chip_CCAN_ClearStatus(LPC_C_CAN0, CCAN_STAT_TXOK);
Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));
NVIC_EnableIRQ(C_CAN0_IRQn);
while (1) {
}
}
After modify like the above code, I can receive all the IDs.
The test result is:
Wish it helps you!
If you still have question, please let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Kerry,
I have the same question as the original in this thread. Your answer does not help. The question wasn't how to receive all messages but how does the receive filtering work. I don't want to receive from all nodes I just want to receive from a range of nodes. Is that possible? I would also be interested in all of the questions the original poster had.
1) Does it mean, that I can define 64 identifier for CAN0 and 64 identifier for CAN1 or only 32 for CAN0 and 32 for CAN1?
2) If I can scan only 32 identifier for each CAN-bus (the picture in the manual at page 1236 shows this) - why I need two message interfaces for each CAN bus?
3) If I want to change the identifier or to remove it from the filter list - how to do this?
4) Is there any code example available to show the using/modification of message filter?
5) Can I change the message filter during running CAN-bus or should I disable the CAN-interrupt during this process?
Thank you,
Garyio