STM32F1 HAL CAN2 Not Recieving

1.4k views Asked by At

I am using a Custom board with a STM32F107VCT6 controller on it. The main purpose of this board is to interface two can networks, do some calculations and relay some data over SPI to another controller and some to the other CAN network and vice-versa.

I have the CAN1 network receiving and transmitting exactly how I would like it to perform; however the CAN2 network is only able to transmit (thus not a hardware fault)

Upon copying the code, yet changing the filter bank to a value greater than 14, as suggested by many other forums; as well as setting the other requirements to change to CAN2 it still does not receive in either interrupt or polling mode.

I have used the STM32Cube MX to generate the same initialisation code as for CAN1, albeit on the different bus with different interrupt priorities.

But the code doesnt work, it is as if there is no messages on the bus. I am using a Microchip CAN bus analyser to send and receive test messages.

Another detail: I have still got CAN1 running, just without data going to it; as such all its clocks are still running.

Here is my test code:

Main Loop

int main(void)
{
  HAL_Init();
  SystemClock_Config();

  MX_GPIO_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_RTC_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();

  CAN_FilterConfTypeDef  sFilterConfig2;

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

  HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig2);

  hcan2.pRxMsg = &RxMessage2;


    while (1)
    {

        HAL_CAN_Receive (&hcan2, CAN_FIFO1, 1000);

        {
            uint8_t buf[100], l = sprintf(buf, " ID: %d DLC: %d Data: %d %d %d %d %d %d %d %d \n\r", RxMessage2.StdId, RxMessage2.DLC, RxMessage2.Data[0], RxMessage2.Data[1], RxMessage2.Data[2], RxMessage2.Data[3], RxMessage2.Data[4], RxMessage2.Data[5], RxMessage2.Data[6], RxMessage2.Data[7]);
            HAL_UART_Transmit(&huart1, buf, l, 1000);
        }

        if (RxMessage2.StdId !=0) {
            while(1);
        }
    }
}

Any input is greatly appreciated, Cheers, Tom

1

There are 1 answers

0
Azzentys On

In your Filter Config, add additional line stating the starting number of Slave Filter Banks.

sFilterConfig2.SlaveStartBankNumber = 14;

With this, the CAN filter banks are definitely split into two different parts. Then, you can use Filter Bank numbers from 14 to 28 for CAN2.