Hi,
Based on CAN protocol, in the CAN packet, the destination ID is included, so you can get the actual ID on the CAN receiver side.
This is the CAN receiving packet structure:
typedef struct _mcan_rx_buffer_frame
{
struct
{
uint32_t id : 29; /*!< CAN Frame Identifier. */
uint32_t rtr : 1; /*!< CAN Frame Type(DATA or REMOTE). */
uint32_t xtd : 1; /*!< CAN Frame Type(STD or EXT). */
uint32_t esi : 1; /*!< CAN Frame Error State Indicator. */
};
struct
{
uint32_t rxts : 16; /*!< Rx Timestamp. */
uint32_t dlc : 4; /*!< Data Length Code 9 10 11 12 13 14 15
Number of data bytes 12 16 20 24 32 48 64 */
uint32_t brs : 1; /*!< Bit Rate Switch. */
uint32_t fdf : 1; /*!< CAN FD format. */
uint32_t : 2; /*!< Reserved. */
uint32_t fidx : 7; /*!< Filter Index. */
uint32_t anmf : 1; /*!< Accepted Non-matching Frame. */
};
uint8_t *data;
uint8_t size; /*!< classical CAN is 8(bytes), FD is 12/64 such. */
} mcan_rx_buffer_frame_t;
I copy the code based on CAN example.
while (1)
{
if ((node_type == 'A') || (node_type == 'a'))
{
GETCHAR();
/* Config TX frame data. */
memset(tx_data, 0, sizeof(uint8_t) * CAN_DATASIZE);
for (cnt = 0; cnt < CAN_DATASIZE; cnt++)
{
tx_data[cnt] = cnt;
}
tx_data[0] += numMessage++;
txFrame.xtd = kMCAN_FrameIDStandard;
txFrame.rtr = kMCAN_FrameTypeData;
txFrame.fdf = 0;
txFrame.brs = 0;
txFrame.dlc = 8U;
txFrame.id = txIdentifier << STDID_OFFSET;
txFrame.data = tx_data;
txFrame.size = CAN_DATASIZE;
#if (defined(USE_CANFD) && USE_CANFD)
txFrame.fdf = 1;
txFrame.brs = 1;
txFrame.dlc = DLC;
#endif
txXfer.frame = &txFrame;
txXfer.bufferIdx = 0;
MCAN_TransferSendNonBlocking(EXAMPLE_MCAN, &mcanHandle, &txXfer);
while (!txComplete)
{
}
txComplete = false;
/* Start receive data through Rx FIFO 0. */
memset(rx_data, 0, sizeof(uint8_t) * CAN_DATASIZE);
/* the MCAN engine can't auto to get rx payload size, we need set it. */
rxFrame.size = CAN_DATASIZE;
rxXfer.frame = &rxFrame;
MCAN_TransferReceiveFifoNonBlocking(EXAMPLE_MCAN, 0, &mcanHandle, &rxXfer);
/* Wait until message received. */
while (!rxComplete)
{
}
rxComplete = false;
/* After call the API of rMCAN_TransferReceiveFifoNonBlocking success, we can
* only get a point (rxFrame.data) to the fifo reading entrance.
* Copy the received frame data from the FIFO by the pointer(rxFrame.data). */
memcpy(rx_data, rxFrame.data, rxFrame.size);
PRINTF("Received Frame ID: 0x%x\r\n", rxFrame.id >> STDID_OFFSET);
PRINTF("Received Frame DATA: ");
cnt = 0;
while (cnt < rxFrame.size)
{
PRINTF("0x%x ", rx_data[cnt++]);
}
PRINTF("\r\n");
PRINTF("Press any key to trigger the next transmission!\r\n\r\n");
}
else
{
memset(rx_data, 0, sizeof(uint8_t) * CAN_DATASIZE);
/* the MCAN engine can't auto to get rx payload size, we need set it. */
rxFrame.size = CAN_DATASIZE;
rxXfer.frame = &rxFrame;
MCAN_TransferReceiveFifoNonBlocking(EXAMPLE_MCAN, 0, &mcanHandle, &rxXfer);
while (!rxComplete)
{
}
rxComplete = false;
/* After call the API of rMCAN_TransferReceiveFifoNonBlocking success, we can
* only get a point (rxFrame.data) to the fifo reading entrance.
* Copy the received frame data from the FIFO by the pointer(rxFrame.data). */
memcpy(rx_data, rxFrame.data, rxFrame.size);
//Rong wrote:
uint32_t tempID;
tempID=rxFrame.id;
PRINTF("Received Frame ID: 0x%x\r\n", rxFrame.id >> STDID_OFFSET);
PRINTF("Received Frame DATA: ");
cnt = 0;
while (cnt < rxFrame.size)
{
PRINTF("0x%x ", rx_data[cnt++]);
}
PRINTF("\r\n");
/* Copy received frame data to tx frame. */
memcpy(tx_data, rx_data, CAN_DATASIZE);
txFrame.xtd = rxFrame.xtd;
txFrame.rtr = rxFrame.rtr;
txFrame.fdf = rxFrame.fdf;
txFrame.brs = rxFrame.brs;
txFrame.dlc = rxFrame.dlc;
txFrame.id = txIdentifier << STDID_OFFSET;
txFrame.data = tx_data;
txFrame.size = rxFrame.size;
txXfer.frame = &txFrame;
txXfer.bufferIdx = 0;
MCAN_TransferSendNonBlocking(EXAMPLE_MCAN, &mcanHandle, &txXfer);
while (!txComplete)
{
}
txComplete = false;
PRINTF("Wait Node A to trigger the next transmission!\r\n\r\n");
}
}
}
Hope it can help you
BR
XiangJun Rong