cancel
Showing results for 
Search instead for 
Did you mean: 

TIM4 and I2C don't work together

AMehm.1
Associate

I have a Arduino Mega and a STM8S003F3. I set up I2C communication between them. Arduino Mega is master. STM8S is slave. STM8S runs at 3.3V. Arduino Mega I2C clock frequency is the default(100KHz). TIM4 goes into interrupt every 1ms.

If I don't enable TIM4 interrupt, i2C communication works correctly. If I enable the TIM4 interrupt, it works correctly for a short time (1-2 seconds) but it gets stuck inside the "DEFAULT" event inside the i2c interrupt and TIM4 stops.

As a solution, I added the following code:

ITC_SetSoftwarePriority(ITC_IRQ_TIM4_OVF, ITC_PRIORITYLEVEL_1);
ITC_SetSoftwarePriority(ITC_IRQ_I2C, ITC_PRIORITYLEVEL_2);

This time, it ran correctly for 6-7 minutes, then it got stuck at the "I2C_EVENT_SLAVE_BYTE_TRANSMITTING" event and TIM4 stopped.

I set the Master I2C Clock frequency to 50KHz but nothing has changed. I need help. Thank you in advance.

0 REPLIES 0