I2C object creation in Simulink

1 回表示 (過去 30 日間)
Valmir Sadiku
Valmir Sadiku 2013 年 5 月 8 日
Hi,
im trying to create an i2c object in simulink for reading an sensor. In Matlab every thing works fine and i can read the data out of the sensor :
mpu_6050 = i2c('aardvark',0,hex2dec('68'));
fopen(mpu_6050);
fwrite(mpu_6050,65);
y = fread(mpu_6050,1);
fclose(mpu_6050);
When i try to add an Matlab-Function-Block to Simulink:
function y = mpu6050_read()
mpu_6050 = i2c('aardvark',0,hex2dec('68'));
fopen(mpu_6050);
fwrite(mpu_6050,65);
y = fread(mpu_6050,1,'*char');
fclose(mpu_6050);
end
i will get this error:
The 'i2c' class does not support code generation.
Is it really not possible to use the i2c class in simulink or do i have to use it in another way?
Regards V.Sadiku
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2013 年 5 月 9 日
編集済み: Kaustubha Govind 2013 年 5 月 9 日
Would you like to simply use your Simulink model for simulation within the MATLAB environment, or do you also intend to generate standalone C/C++ code from it?
Valmir Sadiku
Valmir Sadiku 2013 年 5 月 10 日
I want only use the Simulink model only for simulation, that's why i don't understand this error message.

サインインしてコメントする。

採用された回答

Kaustubha Govind
Kaustubha Govind 2013 年 5 月 10 日
The MATLAB Function block always generates C-code from the MATLAB code for faster execution. If you intend to run the block only for simulation, you can continue to use functions unsupported for code-generation by declaring them as extrinsic functions. I don't think fopen, fwrite, fread and fclose are supposed for code-generation either, so please declare all of them as extrinsic. You will also need to pre-allocate the output of fread, 'y', as described in this previously answered question.
  3 件のコメント
Valmir Sadiku
Valmir Sadiku 2013 年 5 月 13 日
Now i have an additional question: I would use it with the Windows Real Time Target, is it possible? It would be very nice if i can use it or it exits any workaround for that!
Regards V.Sadiku
Kaustubha Govind
Kaustubha Govind 2013 年 5 月 13 日
I would recommend creating a new question for this to make sure other experts see this. I would guess that this is not possible, because coder.extrinsic is meant for execution within the MATLAB environment only. Targets like Real-Time Windows Target create a standalone binary that runs outside the MATLAB environment (in this case, a Real-Time Windows kernel, I believe). The only workaround is to create your own C implementation of that functionality and call it using coder.ceval.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by