AnsweredAssumed Answered

CAN2 interrupt not working

Question asked by user 143 on Oct 26, 2017
Latest reply on Nov 2, 2017 by user 143

Hey guys,

I've got some issues with the CAN2 interrupt on the STM32F107 controller, I don't get an interrupt.

I'm using CubeMX and a STM32F10C Eval board. 

First I tried CAN1 an this works fine so far. Everytime there is a message on the CAN Bus, I get an interrupt and can read out the data. 

Then I configuried CAN2 in CubeMX with the same parameter as CAN1, and I have left CAN1 active.

I know that I need CAN1 active to use CAN2, because CAN2 hasn't direct access to the SRAM.

I also enabled RX0 and RX1 interrupt.

Then I add this lines to my main() function:

if(HAL_CAN_Receive_IT(&hcan2, CAN_FIFO0) != HAL_OK)
{
  Error_Handler();
}

 

And after all I configuried the Filter for CAN2:

CAN_FilterConfTypeDef  sFilterConfig;

hcan2.Instance = CAN2;
hcan2.pTxMsg = &TxMessage;
hcan2.pRxMsg = &RxMessage;

sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 0;

if(HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)
{
     Error_Handler();
}

I just want to use CAN2, because of that I set the BankNumber to 0, which (I think) means, that every bank is available for CAN2. 

 

And here is my interrupt routine:

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan)
{
     HAL_GPIO_TogglePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin);

     if(HAL_CAN_Receive_IT(hcan, CAN_FIFO0) != HAL_OK)
     {
          Error_Handler();
     }
}

 

Sending data on CAN2 is no problem, this works fine. 

I also see on the oscilloscope that the transceiver is transmitting the data to the controller. 

 

When I change hcan2 to hcan1, then I can use this code with CAN1, which workes fine. 

In both cases I have configuried CAN1 and CAN2 with CubeMX.

 

Where could be my mistake?

 

Thank you

Outcomes