1.9.3.8 CANx_MessageReceive Function

C

The prototype of CANx_MessageReceive() varies based on device family. Refer to the generated header file for the actual prototype to be used.

bool CANx_MessageReceive(uint32_t *id, uint8_t *length, uint8_t *data, uint16_t *timestamp, uint8_t fifoNum, CAN_MSG_RX_ATTRIBUTE *msgAttr) // x - Instance of the CAN peripheral

bool CANx_MessageReceive(uint32_t *id, uint8_t *length, uint8_t *data, uint32_t *timestamp, uint8_t fifoNum, CANFD_MSG_RX_ATTRIBUTE *msgAttr) // x - Instance of the CAN peripheral

bool CANx_MessageReceive(uint32_t *id, uint8_t *length, uint8_t *data, uint16_t *timestamp, CAN_MAILBOX_RX_ATTRIBUTE mailboxAttr, CAN_MSG_RX_ATTRIBUTE *msgAttr) // x - Instance of the CAN peripheral

bool CANx_MessageReceive(uint8_t bufferNumber, CAN_RX_BUFFER *rxBuffer) // x - Instance of the CAN peripheral

Summary

Receives a message from CAN bus.

Description

This routine receives a message from CAN bus.

Precondition

CANx_Initialize must have been called for the associated CAN instance.

Parameters

Param Description
id Pointer to 11-bit / 29-bit identifier (ID) to be received.
length Pointer to data length in number of bytes to be received.
data Pointer to destination data buffer
timestamp Pointer to Rx message timestamp, timestamp value is 0 if Timestamp is disabled
fifoNum FIFO number
mailboxAttr Mailbox type either RX Mailbox or RX Mailbox with overwrite
msgAttr Data frame or Remote frame to be received
bufferNumber Rx buffer number
rxBuffer Pointer to Rx buffer

Returns

Request status. true - Request was successful.

false - Request has failed.

Example

uint8_t rx_message[8], rx_messageLength;
uint32_t rx_messageID;
CAN_MSG_RX_ATTRIBUTE msgAttr;
CAN1_Initialize();
CAN1_MessageReceive(&rx_messageID, &rx_messageLength, rx_message, 0, 1, &msgAttr);
uint8_t rx_message[8], rx_messageLength;
uint32_t rx_messageID;
CANFD_MSG_RX_ATTRIBUTE msgAttr;
CAN1_Initialize();
CAN1_MessageReceive(&rx_messageID, &rx_messageLength, rx_message, 0, 2, &msgAttr);
uint8_t buf[8], id, length;
uint16_t timestamp = 0;
CAN_MSG_RX_ATTRIBUTE msgAttr;
CAN0_Initialize();
CAN0_MessageReceive(&id, &length, buf, &timestamp, CAN_MAILBOX_DATA_FRAME_RX_OVERWRITE, &msgAttr);
uint8_t rxBuffer[CAN0_RX_BUFFER_SIZE];
memset(rxBuffer, 0x00, CAN0_RX_BUFFER_ELEMENT_SIZE);
// Read message from Rx Buffer 0
CAN0_MessageReceive(0, (CAN_RX_BUFFER *)rxBuffer);

Remarks

None.