cancel
Showing results for 
Search instead for 
Did you mean: 

I2C, CAN BUS, DMA

Soniaa12
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Karl Yamashita
Principal

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.

CANable V3 firmware | CAN-X CAN bus analyzer software for CANable V3 |
TimerCallback tutorial! | UART and DMA Idle with multiple UART instances tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.

View solution in original post

2 REPLIES 2
mƎALLEm
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Karl Yamashita
Principal

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.

CANable V3 firmware | CAN-X CAN bus analyzer software for CANable V3 |
TimerCallback tutorial! | UART and DMA Idle with multiple UART instances tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.