Simulink hangs on connecting to Arduino Mega 2560 Rev3 in certain models
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear reader;
Most of my Simulink models for the Arduino Mega 2560 hang after a successful download upon connecting to the target, though some of them work.
The external mode does work with certain very simple models. I've needed to use the procedure described here to build and connect to my first successful model. For example an analog input>double conversion>Embedded function for a y = u(5/1024); voltage conversion> scope combination works flawlessly.
However, as soon as I add another analog input, the connection to the target goes haywire. The minimum not working example is two analog inputs with two scopes. The exact procedure goes like this: the building process is successful, and it says " Model Successfully Downloaded to Arduino Mega 2560 ". But then, upon trying to connect to the target board, the process hangs at " Initializing " and either Matlab crashes or after a while I get " Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm': Timed-out waiting for first connect response packet. " I've also tried to run a simple embedded function with an extended Kalman filter inside (no inputs or outputs on Arduino) and a scope, but the same thing happened.
Details:
- MATLAB Version: 8.0.0.783 (R2012b)
- Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)
- Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode
- Board: Arduino Mega 2560
- Fixed Step Discrete Solver (tried 1, 0.1 sec)
- External mode enabled.
- Baud rates 9600
- Overrun detection enabled, on pin 13
- Computer Lenovo ThinkPad T410i
Any help would be much appreciated.
Gergely
댓글 수: 2
Amit Charantimath
2014년 7월 24일
Hello Gergely,
The External Mode implementation in 2012b supports low traffic communication between host and the target. It works well with very few scopes (one in your case.) The latest Matlab version 2014a has robust support for multiple scopes logging. Please download the latest version for robust external mode.
I can provide you a quick fix that can help external mode increase its performance with Matlab 2012b. But this involves changing the ring buffer size of the serial Tx/Rx module on the Arduino Source Files. If you are using this fix, please ensure that you consider how this fix affects your other serial modules (if used in your implementation.)
For Arduino Mega 2560, in the file HardwareSerial.cpp. Change the following macro from
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
to
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 128
(Support Package path for HardwareSerial,cpp file ..\Targets\R2012b\arduino-1.0\hardware\arduino\cores\arduino)
This will ensure that the serial buffers are large enough to hold data even at high traffic between host and target. Note: Eventually the external mode can cause problems when the communication reaches its breaking point. (more scopes.)
Thanks,
Amit M. Charantimath
Embedded Targets Engineer, Mathworks
Amir Mashayekh
2018년 1월 14일
I have exactly this problem in R2017b version. i would be gratful if anyone can help me.
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!