Communication with SPI device connected to an arduino due works with matlab, but not with simulink
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
tilldia
el 22 de Jul. de 2017
Hello Oliver, I work at this time with a S-Function for Arduino integration too. I try to integrate EtherCAT with a Arduino EasyCAT Shield in Simulink. It's works fine with the Arduino Due. But there are Problems with the Due in the SPI Libary. What SPI libary you used for your Project? Maybe you have a better one than me.
Thanks a lot.
Alberto Mora
el 6 de Jul. de 2020
Editada: Alberto Mora
el 6 de Jul. de 2020
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.
Respuestas (0)
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!