How can I read and write in a register through SPI with Arduino?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pau Sendra Berta
il 28 Mag 2020
Risposto: Vaibhav Tomar
il 31 Mag 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 Commenti
Risposta accettata
Vaibhav Tomar
il 31 Mag 2020
Hey,
You may refer to the following link for interfacing with Arduino:
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Device Driver Blocks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!