Get ALL messages on CAN bus

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get ALL messages on CAN bus

1,024 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sposnjak on Fri Mar 27 06:00:13 MST 2015
Hi all!

I need to spy on CAN bus. What I did is:

Chip_CCAN_Init(LPC_C_CAN0);
Chip_CCAN_EnableTestMode(LPC_C_CAN0);
Chip_CCAN_ConfigTestMode(LPC_C_CAN0, CCAN_TEST_SILENT_MODE);

Chip_CCAN_SetBitRate(LPC_C_CAN0, 250000);
Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));

NVIC_EnableIRQ(C_CAN0_IRQn);

and then in the interrupt I do:

while ( (can_int = Chip_CCAN_GetIntID(LPC_C_CAN0)) != 0 )
{
   if (can_int & CCAN_INT_STATUS)
   {
    can_stat = Chip_CCAN_GetStatus(LPC_C_CAN0);

   // some stuff...
   }
}

I can see that can_int is set to CCAN_INT_STATUS and can_stat is set to CCAN_STAT_RXOK => So we have received something, but I do not understand how  I can retrieve the message content. I tried with Chip_CCAN_GetMsgObject but messages does not look correct.

Is there a way to get all received messages without setting ID (with the use of Chip_CCAN_AddReceiveID) for all?

Thank you.
Labels (1)
0 Kudos
3 Replies

861 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sposnjak on Wed Apr 01 01:43:09 MST 2015
OK.. I managed to do it! Your friend is test with basic mode. So for posterity:

Do the init:

Chip_CCAN_Init(LPC_C_CAN0);
Chip_CCAN_EnableTestMode(LPC_C_CAN0);
Chip_CCAN_ConfigTestMode(LPC_C_CAN0, (CCAN_TEST_SILENT_MODE | CCAN_TEST_BASIC_MODE));

Chip_CCAN_SetBitRate(LPC_C_CAN0, 250000);
Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));

        NVIC_EnableIRQ(C_CAN0_IRQn);

In interrupt:

while (0 != (int_reg = LPC_C_CAN0->INT))
{
if ((CCAN_INT_STATUS == int_reg) && (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);

process_can_msg(&can_msg);

LPC_C_CAN0->STAT = LPC_C_CAN0->STAT & (~CCAN_STAT_RXOK);

return;
}

0 Kudos

861 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sposnjak on Sat Mar 28 00:40:39 MST 2015
Chip is LPC4337 with LPCOpen 2.16 and LPCxpresso 7.6.2.
0 Kudos

861 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Mar 27 06:17:51 MST 2015
Could be useful to give us a hint which chip (and toolchain) you are talking about  :)
0 Kudos