AnsweredAssumed Answered

STM32F373CCT and CAN bus

Question asked by rozenko.serge on Jul 7, 2016
Latest reply on Jul 13, 2016 by Amel N
Hello.
I have CAN bus with three devices USB2CAN Adapter and two Controllers with STM32F373CCT. When only Adapter and one Controller is connected to CAN bus everything is correctly working. But if I have connected second Controller to CAN bus in few minutes receiving message from CAN will be frozen at one of the Controllers. But if I have commented Error_Handler_CAN() in HAL_CAN_RxCpltCallback the transmitting will be continue normally work.
PS
Unfortunately reinitialisation of the CAN module in Error_Handler_CAN() don't froze receiving.

Receiving interrupt handler:
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* CanHandle)
  {
  if((hcan.pRxMsg->StdId == 0x480) && (NewDataFromCAN == 0))
    {
    BUF_Data[0]          = hcan.pRxMsg->Data[0];
    BUF_Data[1]          = hcan.pRxMsg->Data[1];
    BUF_Data[2]          = hcan.pRxMsg->Data[2];
    BUF_Data[3]          = hcan.pRxMsg->Data[3];
    BUF_Data[4]          = hcan.pRxMsg->Data[4];
    BUF_Data[5]          = hcan.pRxMsg->Data[5];
    BUF_Data[6]          = hcan.pRxMsg->Data[6];
    BUF_Data[7]          = hcan.pRxMsg->Data[7];//hcan.pRxMsg->Data[6];
 
//  HAL_CAN_Transmit(&hcan, 100);//100
    NewDataFromCAN       = 1;
    }
 
  if(Error_Code = HAL_CAN_Receive_IT(&hcan, CAN_FIFO0) != HAL_OK)
    {
    /* Reception Error */
    Error_Handler_CAN();
    }
  }
The functionHAL_CAN_Receive_IT is returning error code 0x01

Initialising of the CAN module:
...
 MX_CAN_Init();
 ...
 CAN_FilterConfTypeDef canFilterConfig;
 canFilterConfig.FilterNumber = 0;
 canFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
 canFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
 canFilterConfig.FilterIdHigh = 0x0000;
 canFilterConfig.FilterIdLow = 0x0000;
 canFilterConfig.FilterMaskIdHigh = 0x0000 << 5;
 canFilterConfig.FilterMaskIdLow = 0x0000;
 canFilterConfig.FilterFIFOAssignment = 0;
 canFilterConfig.FilterActivation = ENABLE;
 canFilterConfig.BankNumber = 1;
 HAL_CAN_ConfigFilter(&hcan, &canFilterConfig);
 
 HAL_CAN_Receive_IT(&hcan, CAN_FIFO0);
 
/*##Configure Transmission process #####################################*/
 hcan.pTxMsg->StdId = (MB_number == 1) ? 0x400 : 0x401;//0x321;
 hcan.pTxMsg->ExtId = 0x01;
 hcan.pTxMsg->RTR = CAN_RTR_DATA;
 hcan.pTxMsg->IDE = CAN_ID_STD;
 hcan.pTxMsg->DLC = 8;

Error handler for CAN receiving:
void Error_Handler_CAN(void)
{
  /* USER CODE BEGIN Error_Handler */
  /* User can add his own implementation to report the HAL error return state */
 
  SPI_Data[0] = 0xFF;
  SPI_Data[1] = 0xFF;
  HAL_CAN_DeInit(&hcan);
 
  while(SPI_Data[0] != 0)
    {
    HAL_SPI_Transmit(&hspi2, ((uint8_t*)&SPI_Data[0]),1,1000);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);            // SPI strob
    for(My_i=0; My_i<10; My_i++){__NOP();}
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
 
    SPI_Data[0] >>= 1;
    SPI_Data[1] = Error_Code;
    HAL_Delay(1500);
    }
  MX_CAN_Init();
  My_CAN_FilterConf();
  /* USER CODE END Error_Handler */
}

Outcomes