Skip to main content
AFoki
Associate
March 5, 2019
Question

STM32f105 double CAN receiv problem

  • March 5, 2019
  • 2 replies
  • 777 views

on stm32f105 launched CAN. With the transfer of messages, there were no questions, but there were questions about receiving messages from two CAN.

the code is responsible for processing the message

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO0, &RxHeader, RxData);	
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &RxHeader, RxData);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
}

but this code works both on the message from can1, and on messages from can2.

As a result, I do not understand from which of the kans this message came.

How to divide, what would be separately messages from can1 and can2?

This topic has been closed for replies.

2 replies

AFoki
AFokiAuthor
Associate
March 6, 2019
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{	
	 switch((uint32_t)hcan->Instance)
	 {
	 	 case (uint32_t)CAN1:
	 		 /* CAN1 Process */
				HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
				HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &RxHeader, RxData);
	TxHeader.StdId=RxHeader.StdId; 
	TxHeader.DLC = RxHeader.DLC;
 TxHeader.IDE = RxHeader.IDE;
	HAL_CAN_AddTxMessage(&hcan2, &TxHeader, RxData, &TxMailbox);
	 		 break;
	 	 case (uint32_t)CAN2:
	 		 /* CAN2 Process */
	HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
	HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO0, &RxHeader, RxData);
	TxHeader.StdId=RxHeader.StdId; 
	TxHeader.DLC = RxHeader.DLC;
 TxHeader.IDE = RxHeader.IDE;
	HAL_CAN_AddTxMessage(&hcan1, &TxHeader, RxData, &TxMailbox);
	 		 break;
	 }
}

This is code solved my problem

marceliino.lg
Visitor II
October 25, 2019

hi there

can you post the HAL_CAN_ActivateNotification section of your code?

im having problems to determine how to activate CAN1, CAN2 and CAN3 reception interrupt.

 if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
 {
 HAL_UART_Transmit(&huart3, (uint8_t *)"\n\rCAN1_IT_init_ERROR", 20, 10);
 Error_Handler();
 }

i have this implementation for hcan1 but it doesnt works for hcan2

thanks in advance