I2C, CAN BUS, DMA
Hello,
I’m working on a project with an STM32F446RE where I read data from a CAN bus at 500 kbps (CAN1_RX0) and also use I2C to control an MCP4725 DAC, plus timers and DMA for other tasks.
The problem:
-
When I test CAN alone, it works perfectly — I can receive all messages from my device (a motorcycle inverter).
-
When I run the full code with all peripherals connected and active (CAN + I2C + TIM2 + DMA), the CAN stops receiving after a short time, or doesn’t receive at all.
-
On the motorcycle, this happens consistently, but on the bench with CAN only, it works fine.
What I tried so far:
-
Set CAN NVIC priority higher than other interrupts:
- Confirmed CAN1_RX0_IRQHandler() calls HAL_CAN_IRQHandler(&hcan1).
-
Reduced I2C timeout to avoid blocking (HAL_I2C_Master_Transmit with 2 ms instead of HAL_MAX_DELAY).
-
Tried opening the CAN filter (mask = 0) to receive all IDs for debugging.
-
Enabled HAL_CAN_ErrorCallback
Despite all these changes, when all peripherals are running in the motorcycle environment, CAN stops working (no messages received) while I2C and timers keep running.
My questions:
-
Could this still be an interrupt priority problem?
-
Is there something else that could block CAN reception without triggering Bus-Off or errors?
Any advice or similar experience would be appreciated.
I have attached my main code
Thank you.
