cancel
Showing results for 
Search instead for 
Did you mean: 

problems with timers and i2c

Cnnon.1
Associate

hello, i'm using a stm32f4 discovery to control a dc motor, for this i've used different timers for the different actions i have to do in this one, TIM2 is in charge of reading encoder, TIM3 is the pwm generator that goes to a H bridge, TIM4 i use it in Input Capture mode to measure the speed, and the TIM7 I use it to generate an interpolator of order 7, together they work perfectly, but within my application I want to measure the current, for this I am using a module IN219 which communicates by i2c and I am using an adafruit library, separately I made a current control of the motor and it worked perfectly, but when I introduced it in the code with all the timers I mentioned, the I2C communication was taken and stopped sending me data, I tried changing from i2c1 to i2c2 but there was no difference, I also noticed that if I remove the interpolator sequence in the TIM7 the communication was again more stable, but within my application this sequence is important. I also want to comment that TIM7 has lowered the priority 7, but it doesn't solve things

is there any conflict between the i2c communication and the timers??

Besides all this, I had planned to use the interruptions of my timers to make the reading of this sensor since I need to measure only the current peaks when measuring the current in a modulated signal, but the same thing happens, the communication is frozen if I want to make the current request within a timer.

it is possible to make i2c requests within a timer??

Can someone help me to solve this problem??

2 REPLIES 2
TDK
Guru

> is there any conflict between the i2c communication and the timers??

The peripherals are independent, but interrupts can cause issues as the MCU can only execute one part of the code at a time.

> it is possible to make i2c requests within a timer??

You can call I2C commands from within an interrupt, but it is typically not desirable, as it will prevent other interrupts from running until the I2C command returns. A better solution might be to set a flag in the interrupt and handle the I2C in the main loop. Details depend on your implementation. For using most HAL functions, systick needs to be higher priority than anything else.

If you feel a post has answered your question, please click "Accept as Solution".
LFerr.7
Associate II

I have the same problem. Can you explain the solution if you have it