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!