cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0 (I2C Slave + RobotDyn Dimmer) Experiencing Jerk Due to I2C Interrupt Handling

RAHIL
Associate II

Hardware Setup

I am using an ESP32S3 as an I2C master and an STM32G0 as an I2C slave. The STM32G0 is performing two tasks:

  1. I2C Slave Communication – Receiving periodic requests (every second) from the ESP32S3 to read dimmer register updates.
  2. AC Fan Control via RobotDyn Dimmer – Handling a Zero-Cross Detection (ZCD) interrupt and generating a PWM signal for the TRIAC to achieve smooth dimming.

 

Interrupt Details

  • The ZCD interrupt is triggered every 95 microseconds to ensure precise dimming. Increasing this value results in noticeable flicker.
  • The I2C interrupt occurs every second to update the slave dimmer registers (which also get updated via push button inputs on the dimmer).
  • I have set the timer interrupt (ZCD) with a higher priority than the I2C interrupt to maintain dimming precision.
  • DMA

 

Issue Faced

Whenever the STM32G0 processes an I2C interrupt, it misses a ZCD interrupt, causing a visible jerk in the dimming process. This likely happens because the I2C interrupt temporarily blocks the ZCD interrupt, leading to skipped TRIAC triggering.

 

 

Pin Configuration

ESP32S3 (I2C Master):

  • I2C_SCL: GPIO 14
  • I2C_SDA: GPIO 21

STM32G0 (I2C Slave + Dimmer Control):

  • ZCD_IN: PB4
  • TRIAC_TRIGGER: PB9
  • I2C_SCL: PB6
  • I2C_SDA: PB7

 

Attempted Solutions

  1. Increased ZCD interrupt priority above I2C interrupt.
  2. Implemented DMA for I2C transactions.

 

Questions

  1. How can I ensure that the ZCD interrupt is never missed, even when the I2C transaction is being processed?
  2. Are there any best practices for handling multiple high-priority interrupts (ZCD + I2C) without affecting real-time performance?

 

Github link for dimmer control example : https://github.com/RobotDynOfficial/RBDDimmer/blob/master/examples/SimpleToggleDimmer/SimpleToggleDimmer.ino

 

NOTE: The code has been ported from Arduino library to STM32 Cube IDE to control dimmer.

 

Any kind of help or suggestions is appreciated .

 

 

2 REPLIES 2
RAHIL
Associate II

Hello everyone !!! 

Is there anyone who can help me out with this , as I am stuck here . I have not got any reply from anyone out there . If there is anyone out there , who can help me out , will be appreciated .

Thank you in advance .

Regards

Rahil

mƎALLEm
ST Employee

Hello,


@RAHIL wrote:

Attempted Solutions

  1. Increased ZCD interrupt priority above I2C interrupt.
  2. Implemented DMA for I2C transactions.

 


You didn't tell what are your findings with the attempted solution? if you decrease the timer interrupt rate do you have the same behavior?

How did you increase the priority? the value needs to be lower for the timer interrupt.

It could be also due to the high interrupt rate that the CPU could not handle. Set a toggling GPIO on I2C and timer interrupt and check what happens with an oscilloscope or a logic analyzer. 

Try also to set the system clock at its maximum (64MHz?) if it was not the case.

 

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.