cancel
Showing results for 
Search instead for 
Did you mean: 

Canbus callback not working on stm32f429

SGasp.1
Senior

Hi amazing community. 

 

I am working with stm32f429 and cube ide. 

This is my configuration for the project 

 

SGasp1_0-1712731213125.pngSGasp1_1-1712731235661.png

 

 

 

/**
  * @brief CAN1 Initialization Function
  *  None
  * @retval None
  */
static void MX_CAN1_Init(void)
{

  /* USER CODE BEGIN CAN1_Init 0 */

  /* USER CODE END CAN1_Init 0 */

  /* USER CODE BEGIN CAN1_Init 1 */

  /* USER CODE END CAN1_Init 1 */
  hcan1.Instance = CAN1;
  hcan1.Init.Prescaler = 18;
  hcan1.Init.Mode = CAN_MODE_NORMAL;
  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
  hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
  hcan1.Init.TimeTriggeredMode = DISABLE;
  hcan1.Init.AutoBusOff = DISABLE;
  hcan1.Init.AutoWakeUp = DISABLE;
  hcan1.Init.AutoRetransmission = ENABLE;
  hcan1.Init.ReceiveFifoLocked = DISABLE;
  hcan1.Init.TransmitFifoPriority = ENABLE;
  if (HAL_CAN_Init(&hcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN CAN1_Init 2 */

  /* USER CODE END CAN1_Init 2 */

}

 

 

 

SGasp1_2-1712731325207.png

With the configuration above i am not able to enter inside the following callback funxtion sending messages wit canbus 

 

 

 

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
    CAN_RxHeaderTypeDef header;
    uint8_t data[8];
    uint32_t cmd_id;

    if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &header, data) == HAL_OK)
    {
    	if ((can_dev.rx_queue_in+1)%CAN_RX_QUEUE != can_dev.rx_queue_out && header.IDE == CAN_ID_EXT)
    	{
    		// filtro messaggi destinati al nodo
    		cmd_id = header.ExtId;

    		if (cmd_id == can_dev.cfg_id || (can_dev.base != 0 &&
    				(
    						cmd_id == can_dev.base + can_dev.rec_offset*MSG_CFG_STATUS ||
							cmd_id == can_dev.base + can_dev.rec_offset*MSG_OUT_ENABLE ||
							cmd_id == can_dev.base + can_dev.rec_offset*MSG_INP_ENABLE ||
							cmd_id == can_dev.base + can_dev.rec_offset*MSG_HW_VER    ||
							cmd_id == can_dev.base + can_dev.rec_offset*MSG_FW_VER    ||
							cmd_id == can_dev.base + can_dev.rec_offset*MSG_OUT_FREE

    				))) {
    			can_dev.rx++;

    			memcpy(&can_dev.rx_msg_queue[can_dev.rx_queue_in].header, &header, sizeof(CAN_RxHeaderTypeDef));
    			memcpy(can_dev.rx_msg_queue[can_dev.rx_queue_in].data, data, sizeof(data));
    			can_dev.rx_queue_in = (can_dev.rx_queue_in + 1) % CAN_RX_QUEUE;
    		}
    	}

    	can_dev.error_glb = 0;
    	can_dev.tot_rx++;
    }
}

 

 

 

Can you please tell me if you see mistakes in the configuration or something else ? 

 

Thanks a lot

11 REPLIES 11

You CANNOT ENTER THE CALLBACK if the CAN filter is not correctly configured. As I understood you didn't see the thread I provided to you on how to set FilterBank and SlaveStartFilterBank and the answer is there. You need more effort from your side to help you efficiently.

 

 

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.

Double check NVIC settings, Vector Table entries, and linkage, the IRQHandler's themselves and that they call back into the HAL subsystem with the correct instance, that in turn calls your call back.

 

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