Skip to main content
Visitor II
August 10, 2025
Solved

I2C, CAN BUS, DMA

  • August 10, 2025
  • 2 replies
  • 769 views

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:

  1. Set CAN NVIC priority higher than other interrupts:

     
  2. Confirmed CAN1_RX0_IRQHandler() calls HAL_CAN_IRQHandler(&hcan1).
  3. Reduced I2C timeout to avoid blocking (HAL_I2C_Master_Transmit with 2 ms instead of HAL_MAX_DELAY).

  4. Tried opening the CAN filter (mask = 0) to receive all IDs for debugging.

  5. 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.

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    Your code shows you are using ADC and you mention all the other peripherals but it. You haven't attached your stm32xxx_hal_msp.c file so don't know if the ADC is using DMA in circular mode?

    In a project I was working on, I had issues having ContinuousConvMode enabled in that the ADC was always interrupting and certain interrupts would not interrupt. I disabled it and I just used a timer to start the ADC conversion periodically. Try disabling the ContinuousConvMode and see if it makes a difference.

    2 replies

    Technical Moderator
    August 21, 2025

    Hello,

    You said:


    @Soniaa12 wrote:
    • When I test CAN alone, it works perfectly


    Then you said: 


    @Soniaa12 wrote:
    • Is there something else that could block CAN reception without triggering Bus-Off or errors?


    Are you sure CAN is working well for a long time when it is alone?. I don't think Bus-Off is something linked to adding more modules but to something in the HW or software linked to the CAN itself.

    Graduate II
    August 21, 2025

    Your code shows you are using ADC and you mention all the other peripherals but it. You haven't attached your stm32xxx_hal_msp.c file so don't know if the ADC is using DMA in circular mode?

    In a project I was working on, I had issues having ContinuousConvMode enabled in that the ADC was always interrupting and certain interrupts would not interrupt. I disabled it and I just used a timer to start the ADC conversion periodically. Try disabling the ContinuousConvMode and see if it makes a difference.

    Technical Moderator
    August 22, 2025

    @Karl Yamashita wrote:

    Your code shows you are using ADC and you mention all the other peripherals but it. You haven't attached your stm32xxx_hal_msp.c file so don't know if the ADC is using DMA in circular mode?

    In a project I was working on, I had issues having ContinuousConvMode enabled in that the ADC was always interrupting and certain interrupts would not interrupt. I disabled it and I just used a timer to start the ADC conversion periodically. Try disabling the ContinuousConvMode and see if it makes a difference.


    For your info. 

    I didn't accept that solution neither kudoed it.

    Need to investigate the behavior. I'll keep the marking for an eventual internal investigation of that behavior.