MATLAB Answers

Why do I get 'undefined reference to "c-method" ' error when trying to load my matlab function to arduino uno?

27 views (last 30 days)
Tina
Tina on 9 Feb 2018
Commented: Tina on 13 Feb 2018
Hi, I have a Simulink model containing a matlab function block. In this function two methods from my .c file are called, hc595_Init and hc595_SendData. These should set the selected pins as outputs and set them to low/high. When I try to download the simulink model to my arduino Uno I get the following error:
Error(s) encountered while building "Fan": ### Failed to generate all binary outputs
In the code generation report it says:
C:\Program Files\MATLAB\R2017b\Fan_ert_rtw/Fan.c:61: undefined reference to `hc595_Init' C:\Program Files\MATLAB\R2017b\Fan_ert_rtw/Fan.c:134: undefined reference to `hc595_SendData' collect2.exe: error: ld returned 1 exit status gmake: * [../Fan.elf] Error 1 C:\Program Files\MATLAB\R2017b\Fan_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 C:\Program Files\MATLAB\R2017b\Fan_ert_rtw>An_error_occurred_during_the_call_to_make Der Befehl "An_error_occurred_during_the_call_to_make" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
Can anybody tell me why this error occurs?
Thanks!

  2 Comments

Tina
Tina on 12 Feb 2018
yes I do, this is my code of the mask:
function sendToHC595(data, serPin, sckPin, rckPin, gPin)
persistent initflag;
if strcmp(coder.target, 'rtw'),
if isempty(initflag),
% initialise output pins and send data to HC595 ic
coder.ceval('hc595_Init', serPin, sckPin, rckPin, gPin);
initflag = 1;
% send data to HC595 ic
coder.ceval('hc595_SendData', data, serPin, sckPin, rckPin);
else
% send data to HC595 ic
coder.ceval('hc595_SendData', data, serPin, sckPin, rckPin);
end
end

Sign in to comment.

Accepted Answer

Shashank
Shashank on 13 Feb 2018
You need to add the your .c and .h files in the Simulation Target pane of the Configuration parameters of the model. Here is the exact procedure you need to follow:
Hope this helps.
- Shashank

  1 Comment

Tina
Tina on 13 Feb 2018
Thanks for your answer... I don't have a .h file but I directly included the .c file, I think this should work, too. Do I really need a .h file? In which directory do I have to save them? In the same as my Simulink Model?
I got another error now but still don't know how to solve it:
IC:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/shared/externalmode_daemon/include -o Fan.o Fan.c Fan.c:24:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token ShiftRegister.c ^ Fan.c: In function 'Fan_initialize': Fan.c:201:3: error: 'ShiftRegister' undeclared (first use in this function) ShiftRegister.c ^ Fan.c:201:3: note: each undeclared identifier is reported only once for each function it appears in Fan.c:202:1: error: expected ';' before '}' token } /* Model terminate function / ^ gmake: ** [Fan.o] Error 1 C:\Program Files\MATLAB\R2017b\Fan_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 C:\Program Files\MATLAB\R2017b\Fan_ert_rtw>An_error_occurred_during_the_call_to_make Der Befehl "An_error_occurred_during_the_call_to_make" ist entweder falsch geschrieben oder konnte nicht gefunden werden. ### Creating HTML report file Fan_codegen_rpt.html ### Build procedure for model: 'Fan' aborted due to an error. Error(s) encountered while building "Fan": ### Failed to generate all binary outputs.
It looks like MATLAB can't create a .c file to download it to my arduino...

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by