MATLAB Answers

Sarah
0

Using Arduino libraries for S-function in Simulink

Asked by Sarah
on 13 Aug 2017
Latest activity Commented on by Gergo Igneczi on 24 Feb 2019
I have been trying to implement an S-function block in my Simulink model to control multiple magnetometers through an I2C multiplexer. The board I am using is an Arduino Due. I keep running into issues that seem to be related to the compatibility of Arduino code and Matlab code. The code that I am using to build my S-function block works perfectly in Arduino IDE, but seems to have issues in Simulink. I have the support package for Arduino and in this S-function I have included the wire and Mag3110 libraries. Below is the error I am getting.
In file included from ../Mag_wrapper.cpp:25:0:
../SparkFun_MAG3110.cpp:80:23: error: variable or field 'readMag' declared void
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../SparkFun_MAG3110.cpp:80:23: error: 'int16' was not declared in this scope
../SparkFun_MAG3110.cpp:80:30: error: 'x' was not declared in this scope
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../SparkFun_MAG3110.cpp:80:33: error: 'int16' was not declared in this scope
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../SparkFun_MAG3110.cpp:80:40: error: 'y' was not declared in this scope
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../SparkFun_MAG3110.cpp:80:43: error: 'int16' was not declared in this scope
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../SparkFun_MAG3110.cpp:80:50: error: 'z' was not declared in this scope
void MAG3110::readMag(int16* x, int16* y, int16* z){
^
../Mag_wrapper.cpp:30:2: error: 'int16' does not name a type
int16 x, y, z;
^
../Mag_wrapper.cpp:31:11: error: 'int y1' redeclared as different kind of symbol
int x1, y1, z1;
^
In file included from ../Mag_wrapper.cpp:17:0:
c:\programdata\matlab\supportpackages\r2017a\3p.instrset\arduinoide.instrset\idepkgs\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\math.h:469:15: error: previous declaration of 'double y1(double)'
extern double y1 _PARAMS((double));
^
../Mag_wrapper.cpp: In function 'void Mag_Outputs_wrapper(uint8_T*, uint8_T*, uint8_T*, const real_T*)':
../Mag_wrapper.cpp:77:16: error: 'tcaselect' was not declared in this scope
tcaselect(1);
^
../Mag_wrapper.cpp:78:27: error: no matching function for call to 'MAG3110::readMag(uint8_T**, uint8_T**, uint8_T**)'
mag.readMag(&x, &y, &z);
^
../Mag_wrapper.cpp:78:27: note: candidate is:
In file included from ../Mag_wrapper.cpp:24:0:
../SparkFun_MAG3110.h:134:8: note: void MAG3110::readMag(int*, int*, int*)
void readMag(int* x, int* y, int* z);
^
../SparkFun_MAG3110.h:134:8: note: no known conversion for argument 1 from 'uint8_T** {aka unsigned char**}' to 'int*'
../Mag_wrapper.cpp:80:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
x1 = x;
^
../Mag_wrapper.cpp:81:8: error: assignment of function 'double y1(double)'
y1 = y;
^
../Mag_wrapper.cpp:81:8: error: cannot convert 'uint8_T* {aka unsigned char*}' to 'double(double)' in assignment
../Mag_wrapper.cpp:82:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
z1 = z;
^
../Mag_wrapper.cpp:89:16: error: 'tcaselect' was not declared in this scope
tcaselect(3);
^
../Mag_wrapper.cpp:90:28: error: no matching function for call to 'MAG3110::readMag(uint8_T**, uint8_T**, uint8_T**)'
mag1.readMag(&x, &y, &z);
^
../Mag_wrapper.cpp:90:28: note: candidate is:
In file included from ../Mag_wrapper.cpp:24:0:
../SparkFun_MAG3110.h:134:8: note: void MAG3110::readMag(int*, int*, int*)
void readMag(int* x, int* y, int* z);
^
../SparkFun_MAG3110.h:134:8: note: no known conversion for argument 1 from 'uint8_T** {aka unsigned char**}' to 'int*'
../Mag_wrapper.cpp:93:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
x2 = x;
^
../Mag_wrapper.cpp:94:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
y2 = y;
^
../Mag_wrapper.cpp:95:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
z2 = z;
^
../Mag_wrapper.cpp:102:16: error: 'tcaselect' was not declared in this scope
tcaselect(7);
^
../Mag_wrapper.cpp:103:28: error: no matching function for call to 'MAG3110::readMag(uint8_T**, uint8_T**, uint8_T**)'
mag2.readMag(&x, &y, &z);
^
../Mag_wrapper.cpp:103:28: note: candidate is:
In file included from ../Mag_wrapper.cpp:24:0:
../SparkFun_MAG3110.h:134:8: note: void MAG3110::readMag(int*, int*, int*)
void readMag(int* x, int* y, int* z);
^
../SparkFun_MAG3110.h:134:8: note: no known conversion for argument 1 from 'uint8_T** {aka unsigned char**}' to 'int*'
../Mag_wrapper.cpp:105:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
x3 = x;
^
../Mag_wrapper.cpp:106:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
y3 = y;
^
../Mag_wrapper.cpp:107:8: error: invalid conversion from 'uint8_T* {aka unsigned char*}' to 'int' [-fpermissive]
z3 = z;
^
../Mag_wrapper.cpp: In function 'void Mag_Update_wrapper(uint8_T*, uint8_T*, uint8_T*, real_T*)':
../Mag_wrapper.cpp:132:29: error: a function-definition is not allowed here before '{' token
void tcaselect(uint8_t i) {
^
../Mag_wrapper.cpp:142:1: error: expected '}' at end of input
}
^
gmake: *** [Mag_wrapper.o] Error 1
### Creating HTML report file mag_test_codegen_rpt.html
### Build procedure for model: 'mag_test' aborted due to an error.
Error(s) encountered while building "mag_test":
### Failed to generate all binary outputs.

  1 Comment

Hi,
Did you manage to find a solution for this? I am running into the same porblems, although all headers and C files are in the same folder as my S-FUNCTION.
Thanks

Sign in to comment.

1 Answer

Answer by Shashank on 16 Aug 2017

Hi Sarah,
This might be a good starting point for your application:
- Shashank

  0 Comments

Sign in to comment.