How to read data from a 24-bit ADC over SPI and Arduino Uno
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 24-bit ADC MCP3550 and I want to read a voltage value over SPI and Arduino Uno. The slave (MCP3550) can only send information over the SDO-line.
There a few examples how to write and read over SPI using Arduino and Raspberry PI.
https://www.mathworks.com/help/supportpkg/raspberrypiio/examples/analog-input-using-spi.html
https://www.mathworks.com/examples/matlab/mw/arduinoio_product-SPIPotentiometerExample-communicate-with-spi-device-on-arduino-reg-hardware
I still cannot understand how to read the voltage value over the SPI protocol on this particular ADC. From Bit 20 to bit 0, the output code is given MSb first (MSb is bit 20 and LSB is Bit 0).
Here is the code:
a = arduino('com1', 'uno', 'Libraries', 'SPI');
MCP3550 = spidev(a,'D10','Mode',1,'BitOrder','msbfirst','Bitrate',4000000);
for x = 1:1:50 % I'd like to read 50 values
data = writeRead(MCP3550,[1, bin2dec('10000000'), 10]); % I have copied this and the following two rows from the Raspberry Pi tutorial
highbits = bitand(data(2), bin2dec('11'));
voltage = double(bitor(bitshift(highbits, 8), data(3)));
voltage1 = (2.5/4194304) * voltage; % 2.5V ref and 22-bit conversion
end
clear MCP3550 a
1 Kommentar
Astarag Chattopadhyay
am 16 Mär. 2017
Can you please state the exact issue you are facing here? If you are getting any particular error share the corresponding screenshots.
Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!