How can I use writeRead command for SPI device with a uint12 precision?

1 Ansicht (letzte 30 Tage)
I have a ADC shield for arduino MEGA with 12bit resolution that communicate with arduino via SPI, when I use the writeRead command I can choose only between uint8 or uint16 precision, when I use uint8 I receive the correct data of the converted signal (but the precision of the ADC drop because it's 12-bit), instead if I use uint16 the data that I receive isn't correct. Do you now a method or a trick for use my ADC without lose resolution or get a wrong measure?

Akzeptierte Antwort

Maitreyee Mordekar
Maitreyee Mordekar am 25 Jan. 2017
Hi Stefano,
Looks like you will have to read the data as uint16 and then mask the bits that are not desired.
You will have to check the specifications of the shield if the bits that are not of significance to you are in the most significant nibble or the least significant nibble.
If the non-desired 4 bits from the value read are in the most significant nibble, then just perform bitwise AND with the binary value '0000111111111111'. Else if the required data is in the lower nibble, you could right shift the data by 4 places using bitshift function.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by