How can I read and write in a register through SPI with Arduino?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pau Sendra Berta
le 28 Mai 2020
Réponse apportée : Vaibhav Tomar
le 31 Mai 2020
Hi everybody,
I am working on a project where we want to use MATLAB to configure and read data from a device (EVAL-AD5941ELCZ) that performs impedance measurements. To connect to this device, we use an Arduino UNO board and the SPI library. The connection with Arduino seems to be done correctly and the connection with the measurement device as well. But the problem is that I am not able to write and read from the registers of this device through the SPI communication.
For example, what I need is to write the data 0x02C9 to the register address 0x0908
The code I'm using is the following:
close all;
clear all;
a = arduino();
spidev = device(a, 'SPIChipSelectPin', 'D10');
readCmd = hex2dec('0x6d');
writeCmd = hex2dec('0x2d');
readFifoCmd = hex2dec('0x5f');
writeDigitalPin(a,'D10',0); %Set CS pin from Arduino to a LOW value
writeRead(spidev, [writeCmd hex2dec('0x02C9') hex2dec('0x0908')]); %write data to the register
out = writeRead(spidev, [readCmd hex2dec('0x02C9') hex2dec('0x0908')]) %read data from the register
writeDigitalPin(a,'D10',1); %Set CS pin from Arduino to a HIGH value
And the errors that MATLAB notifies me are the following:
- Uno Pin D10 is reserved by SPI. To release the resource, clear all variables holding onto this resource.
- Invalid dataIn array values. All array values must be integers between 0 and 255.
Does anyone know how I can read and write in a register like the one in the example?
Thank you very much.
0 commentaires
Réponse acceptée
Vaibhav Tomar
le 31 Mai 2020
Hey,
You may refer to the following link for interfacing with Arduino:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!