The CAN messages are being transmitted and received successfully in the Standard ID mode already.
/* Data structure for a CAN message */
typedef struct
{
uint32_t id;
uint32_t dlc;
uint32_t data[4];
} message_object;
#define MSG_OBJ_MAX 0x0020
#define DLC_MAX 8
#define RX_MSG_ID 0x300
#define RX_EXT_MSG_ID 0x00100000
#define TX_MSG_ID 0x200
#define TX_EXT_MSG_ID 0x00200000
void CAN_ConfigureMessages( void )
{
uint32_t i;
uint32_t ext_frame = 0;
/* extended receive only for 32 objects */
for ( i = 0; i < MSG_OBJ_MAX; i++ )
{
LPC_CAN->IF1_CMDMSK = WR|MASK|ARB|CTRL|DATAA|DATAB;
/* Mxtd: 1, Mdir: 0, Mask is 0x1FFFFFFF*/
LPC_CAN->IF1_MSK1 = ID_EXT_MASK & 0xFFFF;
LPC_CAN->IF1_MSK2 = MASK_MXTD | (ID_EXT_MASK >> 16);
/*MsgVal: 1, Mtd: 1, Dir: 0, ID = 0x100000*/
LPC_CAN->IF1_ARB1 = (RX_EXT_MSG_ID+i) & 0xFFFF;
LPC_CAN->IF1_ARB2 = ID_MVAL | ID_MTD | ((RX_EXT_MSG_ID+i) >> 16);
LPC_CAN->IF1_MCTRL = UMSK|RXIE|EOB|DLC_MAX;
LPC_CAN->IF1_DA1 = 0x0000;
LPC_CAN->IF1_DA2 = 0x0000;
LPC_CAN->IF1_DB1 = 0x0000;
LPC_CAN->IF1_DB2 = 0x0000;
/* Transfer data to message RAM */
LPC_CAN->IF1_CMDREQ = i+1;
while( LPC_CAN->IF1_CMDREQ & IFCREQ_BUSY );
}
return;
}
Solved! Go to Solution.
I don't see anything wrong in your code setting the message object configuration and suspect that you don't have the acceptance filter if used or mask setting correctly. Attached here is some code I used long time ago.
Hi all,
This issue is currently resolved. There was nothing wrong with the firmware or hardware configuration for the filter. The issue was with the tool we had used to transmit or receive the extended CAN IDs.
Thanks and Best Regards,
Sudarshan
This code comes from NXP's official example.But I do not know how to change to 29ID.
int main(void)
{
uint32_t CanApiClkInitTable[2];
/* Publish CAN Callback Functions */
CCAN_CALLBACKS_T callbacks = {
CAN_rx,
CAN_tx,
CAN_error,
NULL,
NULL,
NULL,
NULL,
NULL,
};
SystemCoreClockUpdate();
//Board_Init();
baudrateCalculate(TEST_CCAN_BAUD_RATE, CanApiClkInitTable);
LPC_CCAN_API->init_can(&CanApiClkInitTable[0], TRUE);
/* Configure the CAN callback functions */
LPC_CCAN_API->config_calb(&callbacks);
/* Enable the CAN Interrupt */
NVIC_EnableIRQ(CAN_IRQn);
/* Send a simple one time CAN message */
msg_obj.msgobj = 0;
msg_obj.mode_id = 0x345;
msg_obj.mask = 0x0;
msg_obj.dlc = 4;
msg_obj.data[0] = 'T'; // 0x54
msg_obj.data[1] = 'E'; // 0x45
msg_obj.data[2] = 'S'; // 0x53
msg_obj.data[3] = 'T'; // 0x54
LPC_CCAN_API->can_transmit(&msg_obj);
/* Configure message object 1 to receive all 11-bit messages 0x400-0x4FF */
msg_obj.msgobj = 1;
msg_obj.mode_id = 0x400;
msg_obj.mask = 0x700;
LPC_CCAN_API->config_rxmsgobj(&msg_obj);
#if 0
while (1) {
//__WFI(); /* Go to Sleep */
}
#endif
}
Hi VN V,
This code you have given does not match the current code for CAN filtering (29 bits)
Thanks and Regards,
Praseen
Hi Dezheng Tang,
The code you have attached is the default code available as part of the example. Could you please provide the code with the acceptance filter and mask set for receiving only CAN extended 29 bit identifiers? or let me know where and what I need to change.
Thanks and Best Regards,
Praseen
In CAN_ConfigureMessages(), the code you have (can.c) configured all 32 message objects, both STD and EXT messages, both TX and RX, if you want to receive EXT message only, configure EXT messages only.
You can also use the BASIC mode which doesn't use message RAM, see CAN chapter 16.7.2 and 16.7.2.4.4.
Hi Dezheng Tang,
Could you please reply to the above mail, please
Thanks in advance,
Sudarshan
Hi Dezheng Tang,
I used the code you had sent and used the filter in CAN_ConfigureMessages function for CAN reception. This filter is configured for both transmit and receive. So when I tested the code, I found that the extended id part of it was not working as expected. Using the default filter in the function CAN_ConfigureMessages I am able to receive 0x101, 0x105, 0x109, 0x111, 0x115, 0x119 message ID based CAN messages, since the macro RX_MSG_ID is set as 100.
Using the above mentioned filter I should be able to receive the extended CAN ids 0x00100003, 0x00100007 since the value of RX_EXT_MSG_ID is 0x00100000, however this does not happen. Could you please let me know what I am doing wrong?
Thanks and Best Regards,
Sudarshan