Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using CAN1 and CAN2 simultaneously only works by modifying the initializeFilters() function. #37

Open
tscheskn opened this issue May 28, 2024 · 1 comment

Comments

@tscheskn
Copy link

Hello,
I'm using both CAN1 and CAN2 on a STM32F446RE. CAN1 works fine.
But with the default initializeFilters() functions that is called in setBaudRate(), CAN2 was only able to send but not receive messages.
The fix I found was also setting the SlaveStartFilterBank to 14 for CAN2:

void STM32_CAN::initializeFilters() {
  CAN_FilterTypeDef sFilterConfig;
  // We set first bank to accept all RX messages
  sFilterConfig.FilterBank = 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 = CAN_RX_FIFO0;
  sFilterConfig.FilterActivation = ENABLE;
#ifdef CAN2
  // Filter banks from 14 to 27 are for Can2, so first for Can2 is bank 14. This
  // is not relevant for devices with only one CAN
  if (_canPort == CAN1) {
    sFilterConfig.SlaveStartFilterBank = 14;
  }
  if (_canPort == CAN2) {
    sFilterConfig.FilterBank = 14;
    sFilterConfig.SlaveStartFilterBank = 14; // SlaveStartFilterBank also needs to be set for CAN2 apparently
  }
#endif

  HAL_CAN_ConfigFilter(n_pCanHandle, &sFilterConfig);
}

I'm not sure if this is a special issue with my setup (I can provide more details if necessary) or a general issue.

@pazi88
Copy link
Owner

pazi88 commented May 28, 2024

Could be common issue. I should soon have my new board in hands that has both CAN1 and CAN2 available, so I can test this too and include the fix in library, if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants