I2C synchronous/blocking issue

Post here first, or if you can't find a relevant section!
Post Reply
shepan
Posts: 3
Joined: Tue Jan 07, 2020 11:55 am

I2C synchronous/blocking issue

Post by shepan »

I need to regularly poll a sensor on I2C and to process samples + access a DAC on SPI, both operations are periodic, time critical and triggered by dedicated interrupts. I am using STM32Duino on Blue Pill and the Wire library for I2C.

My impression is that I2C reads are blocking, which introduces occasional delays on the other periodic operation (samples processing + SPI). Is this really the case? If so, is there any workaround?

Thanks!! :)
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2C synchronous/blocking issue

Post by fpiSTM »

Could you share you example sketch?
Andy2No
Posts: 15
Joined: Mon Dec 30, 2019 8:34 pm

Re: I2C synchronous/blocking issue

Post by Andy2No »

shepan wrote: Tue Jan 07, 2020 12:06 pm My impression is that I2C reads are blocking, which introduces occasional delays on the other periodic operation (samples processing + SPI). Is this really the case? If so, is there any workaround?
I2C/IIC is fairly slow, so you'd probably need to make sure each operation didn't happen until sufficient time had passed since the last one completed...

Have you tried just polling it less often?

Maybe you could make a cut down version of your sketch, which is kept simple but still shows the problem?
shepan
Posts: 3
Joined: Tue Jan 07, 2020 11:55 am

Re: I2C synchronous/blocking issue

Post by shepan »

Thank you for the replies! I am investigating the issue and will post code, but I need to simplify it before I can share. In the meantime I believe that I isolated the problem:

The issue is with the SparkFun_VL53L1X library, which relies on Wire. Specifically the VL53L1_RdWord function. When I check the traces on the oscilloscope, it seems that the interrupt (based on Timer 3) stops for a few cycles just in the last part of the I2C communication.

What puzzles me is that I see the issue only when polling the sensor for a "word". When I poll it for bytes, there is no issue at all. Could it be that Wire disables certain interrupts only when reading a word, but not when reading a byte?
shepan
Posts: 3
Joined: Tue Jan 07, 2020 11:55 am

Re: I2C synchronous/blocking issue

Post by shepan »

Here you see the traces when polling a word from the VL53L1x. The yellow trace is the signal genersted with Timer 3. The purple is SCL on I2C. Clearly during the last part of the answer from the sensor Timer 3 goes into trouble.

https://www.dropbox.com/s/0xv1w77kpca5g ... 224550.jpg
victor_pv
Posts: 9
Joined: Wed Dec 18, 2019 7:33 pm

Re: I2C synchronous/blocking issue

Post by victor_pv »

i2c and SPI peripherals both can be used with the DMA controller, so they work independently of the CPU.
You could use DMA with one and the CPU (software) with the other, or both with DMA.
Post Reply

Return to “General discussion”