I2C read with interrupt crashes

Hi, newbie here.

I am trying to read from a gyro sensor (ST LSM6DOS) with the I2C on portenta. I unfortunately can not use the spi pins since I have used those for other purposes. I attemped to perform an I2C read using the arduino Wire library within an ISR, but the program just crashes no matter what I set the interrupt frequency to. I have a feather M0 and the I2C read within an ISR executed with no problem. I am wondering if I am missing something with timer interrupt on portenta.

Also is there a way to combine DMA with I2C read? Any hints and suggestions are highly appreciated!

I know nothing of the specific hardware you are using but doing something as complex as an I2C read or write within an ISR is asking for trouble. An ISR should be very quick with minimal code. Set a flag in the ISR then do the I2C code in the loop function.

2 Likes

Hi! Thanks for the reply!

I understand the principle of being minimal with an ISR. And currently I am doing exactly what you suggested. But I am a little confused as to why I can perform the I2C read within an ISR on a less powerful chip (ATSAMD21 on Adafruit Feather M0) but not on Portenta. I guess I am asking more about the specifics of the portenta hardware.

You should never attempt this on either processor, regardless of whether it is possible.

It is extremely bad programming practice.

2 Likes

Thanks! I appreciate the advice!