2024-12-17 09:03 PM - last edited on 2024-12-18 12:49 AM by SofLit
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
2024-12-18 01:00 AM - edited 2024-12-18 01:26 AM
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:
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?
2024-12-18 03:10 AM
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
2024-12-18 03:20 AM
@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.