How to read data from a 24-bit ADC over SPI and Arduino Uno

6 visualizaciones (últimos 30 días)
Nik__
Nik__ el 12 de Mzo. de 2017
Comentada: Astarag Chattopadhyay el 16 de Mzo. de 2017
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 comentario
Astarag Chattopadhyay
Astarag Chattopadhyay el 16 de Mzo. de 2017
Can you please state the exact issue you are facing here? If you are getting any particular error share the corresponding screenshots.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by