cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f042f6 MCU waits at while (HAL_CAN_IsTxMessagePending(&hcan, TxMailbox))

pradeepwagre
Associate III

Below is my following CAN configuration. Extended CAN frame is transferred every 50ms at 1MB/s.

static void MX_CAN_Init(void)
{

/* USER CODE BEGIN CAN_Init 0 */

/* USER CODE END CAN_Init 0 */

/* USER CODE BEGIN CAN_Init 1 */

/* USER CODE END CAN_Init 1 */
hcan.Instance = CAN;
hcan.Init.Prescaler = 3;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_7TQ;
hcan.Init.TimeSeg2 = CAN_BS2_8TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = ENABLE;
hcan.Init.AutoWakeUp = DISABLE;
hcan.Init.AutoRetransmission = ENABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN_Init 2 */
// CAN_FilterTypeDef canfilterconfig;

// canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
// canfilterconfig.FilterBank = 5; // which filter bank to use from the assigned ones
// canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
// canfilterconfig.FilterIdHigh = 0x103<<5;
// canfilterconfig.FilterIdLow = 0;
// canfilterconfig.FilterMaskIdHigh = 0x103<<5;
// canfilterconfig.FilterMaskIdLow = 0x0000;
// canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
// canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
// canfilterconfig.SlaveStartFilterBank = 5; // how many filters to assign to the CAN1 (master can)

// HAL_CAN_ConfigFilter(&hcan, &canfilterconfig);
/* USER CODE END CAN_Init 2 */

}

Stm32f042F6Px waits at while (HAL_CAN_IsTxMessagePending(&hcan, TxMailbox)) until proper CAN network is formed,I am not able to perform other operations.I want this polling method to convert in interrupt method or suggest any alternative for this?

Below CAN transmit code is in Main.c under while loop

while (HAL_CAN_IsTxMessagePending(&hcan, TxMailbox))
 {
 
 }
 if(HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxMailbox) != HAL_OK)
{
 Error_Handler();
}

2 REPLIES 2
SRedd.5
Senior III

It is very simple Enable the CAN interrupts in the  MX_NVIC_Init

/* FDCAN1_IT0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 15, 3);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);

 

 

 

You'd presumably use an IF instead of a WHILE if you didn't want to block.

Otherwise you're going to have to come up with a queuing or dropping strategy if the CAN interface isn't sinking the data. And an interrupt  / callback to move data off the queue when the TX completes or FIFO slot opens up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..