I am trying to use I2C block inside a interrupt but it not working

7 次查看(过去 30 天)
I am using i2c module at i2c1 which works perfectly when it is in polling but i want to use inside a interrupt subroutine which is trigged from ADC end of conversion, i am using a nulceo stm32f466RE, i found a matlab link where it says somthing about these but i do not understand how to use it please help me this

回答(2 个)

Aabha
Aabha 2025-5-6
Hi @Roni,
This issue is commonly observed while using STM32 boards, where I2C is interrupt based. When the I2Cblock is present inside an enabled subsystem, which is triggered by an ‘Interrupt’ block, the I2Cblock does not read or write any data. This is because the interrupt which enables the subsystem has a higher priority than the I2C block.
To fix this issue, you can try the following workaround:
  1. Add a System Initialize block in the model. When a model includes the System Initialize block, the Simulink Code Generator adds external code, which is specified in the ‘SystemInitialize function that is generated by the block. You can specify code for the code generator to add to the declaration, execution, and exit sections of the function code. Please refer to the following link to understand more about the ‘System Initialize’ block: https://www.mathworks.com/help/releases/r2024b/rtw/ref/systeminitialize.html
  2. Add custom code in the ‘System Initialize’ block such that it assigns a higher priority to the ‘I2C’ block, than the ‘Interrupt’ block that drives the ‘I2C’ subsystem. This will ensure that the ‘I2C’ block can perform read or write operations effectively.
I hope this helps.

Adit Kirtani
Adit Kirtani 2025-6-3
Hi,
Kindly contact Technical Support for further assistance:
Thank you,
Adit Kirtani.

产品


版本

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by