Arduino SPI writeRead function unavailable in Simulink
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to execute multiple SPI writes in one solver step of a simulink program. So I enclosed all of my SPI write calls in one functions and I initialize the relevant objects before running the simulink code. However, at execution simulink complains about 'writeRead' function being undefined when it tries to execute the transfers. I have included the two program segments that I am using.
% init.m
global arduinodev; global extdac;
arduinodev = arduino('COM4', 'Due', 'Libraries', 'SPI');
extdac = device(arduinodev, 'SPIChipSelectPin', 'D52', 'SPIMode', 1, 'bitorder', 'msbfirst') ;
% MATLAB Function
function dacWrite(extdac, values)
%DACWRITE Writes the 6 values received to the Helmholtz Cage Controller
%DAC
%
l = length(values);
if ( l ~= 6 )
return
end
% code n
coden = 0b10000000 ;
for dac = 1:6
cmd = bitor(coden, dac) ;
val = uint16(values(dac));
if ( val > 0x0fff )
val = 0x0fff ;
end
low = bitshift(uint8(bitand(val,0x00ff)),4);
high = uint8(bitshift(uint16(val),-4,'uint16'));
%fprintf("0x%x 0x%x 0x%x\n", cmd, high, low);
dacout = [cmd, high, low];
writeRead(extdac, dacout);
end %for
dacout = [ 0b11000001 0x00 0x00 ] ; % loadn
writeRead(extdac, dacout);
end
Here is the image of the Simulink Code Block that I am using:
And here is the error I am getting:
Undefined function or variable 'writeRead'.
Function 'MATLAB Function' (#23.590.615), line 21, column 9:
"writeRead(extdac, dacout)"
댓글 수: 0
채택된 답변
Walter Roberson
2020년 1월 9일
편집: Walter Roberson
2020년 1월 13일
In the case where you are using either no acceleration or else only the first step of acceleration, then you can use coder.extrinsic() to have Simulink talk to the MATLAB engine to run the function.
However, there is currently no way to generate deployable code for the writeRead() call. Notice that https://www.mathworks.com/help/supportpkg/arduinoio/ref/writeread.html does not have any section for "extended capabilities", so there is no code generation available for it.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Run on Target Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!