0

I can configure CAN filters from main.c file, but I want also to configure them by sending frame from the other node. There is the code from interrupt I want to use to configure filters:

    HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
    sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
    sFilterConfig.BankNumber = hcan.pRxMsg->Data[1];
    sFilterConfig.FilterNumber = hcan.pRxMsg->Data[2];
    sFilterConfig.FilterIdHigh  = (hcan.pRxMsg->Data[3])<<5;
    sFilterConfig.FilterIdLow = 0;
    sFilterConfig.FilterMaskIdHigh = 0;
    sFilterConfig.FilterMaskIdLow = 0;
    sFilterConfig.FilterFIFOAssignment = 0;
    sFilterConfig.FilterActivation = ENABLE;
    HAL_CAN_ConfigFilter(&hcan, &sFilterConfig);

For example I'm sending Data[1] = 1, Data[2]=0. When I'm sending the frame, the LED changes it's state, so it should work. I used analogous code in main.c file to configure filter while programming STM and it works properly. It's that even possible to configure CAN filters while STM is working? If yes, then where am I wrong?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Juras
  • 23
  • 1
  • 9
  • I don't know. What does the datasheet/reference manual state about the modes in which the filter registers may be accessed? – doynax Feb 21 '17 at 11:41
  • 1
    We need a description of what result you are getting with your current code. Your answer does not yet even state that the code shown is not achieving the intended result. (i.e. you should be looking at what happens on the lines on a scope and comparing that to your expectations) – Toby Feb 21 '17 at 11:54
  • `sFilterConfig.FilterIdHigh = (hcan.pRxMsg->Data[3])<<5;` looks suspect. – joop Feb 21 '17 at 12:10
  • @joop Why?_____ – Bence Kaulics Feb 21 '17 at 12:16
  • mainly because I don't know the types and sizes of `sFilterConfig.FilterIdHigh` and `hcan.pRxMsg->Data[3]`. (for instance, `->Data[]` could be a signed character) – joop Feb 21 '17 at 12:29
  • I don't have any scope now to check what is on the bus. sFilterConfig.FilterIdHigh can be a number between 0x000-0xFFFF, and Data[] is a byte value. I checked reference manual and there I found that first bit in FMR register should be set to start configuration for the filters, and cleared when it's done. I added the lines " hcan.Instance->FMR|=1<<0;" at the beginning of the code and hcan.Instance->FMR&=~(1<<0); at the end of the code. Now LED toggles only once, with first received CAN message. Then it stop responding. – Juras Feb 21 '17 at 13:37

0 Answers0