Communication with SPI device connected to an arduino due works with matlab, but not with simulink

조회 수: 6(최근 30일)
Hello,
I've got an SPI device (LDC1101 Inductance-to-Digital Converter) connected to an Arduino Due and try to communicate with it using the MATLAB Support Package for Arduino Hardware (2016a). I'm able to read and write registers of the device with matlab, but I would like to deploy a simulink model to the arduino, and I don't get SPI communication working. I have the Simulink Support Package for Arduino Hardware installed.
In matlab, the following code works:
a = arduino();
dev = spidev(a,'D4','Mode',3,'BitOrder','msbfirst','Bitrate',4000000);
%Example for reading all registers of SPI device
data = [];
for i=0:63
data = [data;{dec2hex(i),dec2bin(AccessLDC(dev,i,0,0))}];
end
function AccessLDC:
function response = AccessLDC(dev,register,data,write)
%Build message for LDC1101
msg = 256*(register + (write==0)*128) + data;
%Write message, 8 lower bits contain response
response = dev.writeRead(msg,'uint16');
%Process message, return 8 lower bits
response = bitand(response,255);
But the attached simulink model does not produce any meaningful results. The matlab Fcn block in the subsystem "AccessLDC" uses the same line of code as in the matlab program.
%Build message for LDC1101
msg = 256*(register + (write==0)*128) + data;
See also the attached configuration parameters of the model. Has anyone a clue of what I'm doing wrong?
  댓글 수: 12
Alberto Mora
Alberto Mora 2020년 7월 6일
편집: Alberto Mora 2020년 7월 6일
Dear Oliver, how did you solve the problem of use LDC1101 with Arduino? Can you share your library? That can help me a lot. Thanks, Alberto.

댓글을 달려면 로그인하십시오.

답변(0개)

범주

Find more on Simulink Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by