cancel
Showing results for 
Search instead for 
Did you mean: 

Understand bxCAN TX mailbox

Ash1
Associate II

Hi all

I want to understand behavior of TX mailbox here I am trying to send three ID but only i able to see two ID at a time in TI0R. I have fewer doubts which I hope you can clear.

Doubt 1:  Do I have to use three different mail box for three ID or One is enough .

Doubt 2. Like in RX mailbox I have locking mechanism in which I can see different RX frame in RXFIFO0 so I mean to say It can hold upto three different messages. So is there any logic in TX mailbox also to locked or to see all ID because I think it is overwriting the buffer.

CAN_TxHeaderTypeDef txHeader;
uint8_t tx_data[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
uint32_t tx_mailbox_used;

txHeader.StdId = 0x3e8; // Example CAN ID
txHeader.RTR = CAN_RTR_DATA;
txHeader.IDE = CAN_ID_STD;
txHeader.DLC = 8;

if (HAL_CAN_AddTxMessage(&hcan1, &txHeader, tx_data, &tx_mailbox_used) != HAL_OK)
{
  Error_Handler();
}

txHeader.StdId = 0x2bc; // Example CAN ID
txHeader.RTR = CAN_RTR_DATA;
txHeader.IDE = CAN_ID_STD;
txHeader.DLC = 8;

if (HAL_CAN_AddTxMessage(&hcan1, &txHeader, tx_data, &tx_mailbox_used) != HAL_OK)
{
  Error_Handler();
}

txHeader.StdId = 0x100; // Example CAN ID
txHeader.RTR = CAN_RTR_DATA;
txHeader.IDE = CAN_ID_STD;
txHeader.DLC = 8;

if (HAL_CAN_AddTxMessage(&hcan1, &txHeader, tx_data, &tx_mailbox_used) != HAL_OK)
{
  Error_Handler();
}

HAL_Delay(1000);
}

B.R

Ashish

3 REPLIES 3
SofLit
ST Employee

Hello,

First, please see How to insert source code , I've edited your post.

Second, not sure what the problem is, but when sending a CAN frame you need to select an empty mailbox (it's already managed in the HAL).

Please review the reference manual:

SofLit_1-1734512292897.png

SofLit_0-1734512211276.png

See also the HAL implementation of HAL_CAN_AddTxMessage():

 

    /* Check that all the Tx mailboxes are not full */
    if (((tsr & CAN_TSR_TME0) != 0U) ||
        ((tsr & CAN_TSR_TME1) != 0U) ||
        ((tsr & CAN_TSR_TME2) != 0U))
    {
      /* Select an empty transmit mailbox */
      transmitmailbox = (tsr & CAN_TSR_CODE) >> CAN_TSR_CODE_Pos;

      /* Store the Tx mailbox */
      *pTxMailbox = (uint32_t)1 << transmitmailbox;

 

PS: could you please state on this thread please? 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

HI

So when to set this TME0 in TSR during intialization time .

can you tell me when to set and when I can Clear this bit or only one time during initialization I have to  set.

Explain me in theory .

B.R

Ashish


@Ash1 wrote:

 

So when to set this TME0 in TSR during intialization time .

can you tell me when to set and when I can Clear this bit or only one time during initialization I have to  set.

Explain me in theory .


Did you read the reference manual?

And you don't have to care of that when you are using HAL.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.