Jump to main content

##

# 2.8.69 CANx_MessageTransmit Function

## C

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

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

    bool CANx_MessageTransmit(uint32_t id, uint8_t length, uint8_t* data, uint8_t fifoQueueNum, CANFD_MODE mode, CANFD_MSG_TX_ATTRIBUTE msgAttr) // x - Instance of the CAN peripheral

    bool CANx_MessageTransmit(uint32_t id, uint8_t length, uint8_t* data, CAN_MAILBOX_TX_ATTRIBUTE mailboxAttr) // x - Instance of the CAN peripheral

    bool CANx_MessageTransmit(uint8_t bufferNumber, CAN_TX_BUFFER *txBuffer) // x - Instance of the CAN peripheral

## Summary

Transmits a message into CAN bus.

## Description

This routine transmits a message into CAN bus.

## Precondition

CANx_Initialize must have been called for the associated CAN instance.

## Parameters

Param | Description
--- | ---
id | 11-bit / 29-bit identifier (ID)
length | Length of data buffer in number of bytes
data | Pointer to source data buffer
fifoNum | FIFO number
fifoQueueNum | If fifoQueueNum is 0 then Transmit Queue otherwise FIFO
mode | CAN mode Classic CAN or CAN FD without BRS or CAN FD with BRS
msgAttr | Data frame or Remote frame to be transmitted
mailboxAttr | Mailbox type TX Mailbox or Consumer Mailbox or Producer Mailbox
bufferNumber | Tx buffer number
txBuffer | Pointer to Tx buffer

## Returns

Request status. true - Request was successful.

false - Request has failed.

## Example

    uint8_t message[] = {0xAA, 0x55};
        uint32_t messageID = 0x555;
        uint8_t messageLength = 2;
        CAN1_Initialize();
        CAN1_MessageTransmit(messageID, messageLength, message, 0, CAN_MSG_TX_DATA_FRAME);

    uint8_t message[] = {0xAA, 0x55};
        uint32_t messageID = 0x555;
        uint8_t messageLength = 2;
        CAN1_Initialize();
        CAN1_MessageTransmit(messageID, messageLength, message, 1, CANFD_MODE_NORMAL, CANFD_MSG_TX_DATA_FRAME);

    uint8_t buf[] = {0xAA, 0x55};
        CAN0_Initialize();
        CAN0_MessageTransmit(0x555, sizeof(buf), buf, CAN_MAILBOX_DATA_FRAME_TX);

    uint8_t loop_count = 0;
    uint8_t txFiFo[CAN0_TX_FIFO_BUFFER_SIZE];
    CAN_TX_BUFFER *txBuffer = (CAN_TX_BUFFER *)txFiFo;
    memset(txFiFo, 0x00, CAN0_TX_FIFO_BUFFER_ELEMENT_SIZE);
    txBuffer->id = 0x100000A5;
    txBuffer->dlc = 8;
    txBuffer->xtd = 1;
    txBuffer->fdf = 1;
    txBuffer->brs = 1;
    for (loop_count = 0; loop_count < 8; loop_count++){
        txBuffer->data[loop_count] = loop_count;
    }
    // Transmit message from Tx buffer 0
    CAN0_MessageTransmit(0, txBuffer);

## Remarks

None.