# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to Convert SPI Data Correctly?

I have an ADC of ADS1256, I try to use Myrio to read the data via SPI, but I get stuck when converting the data~ Can you help how to get the correct data?(ADS1256datasheet )

I gave a set of ARDUINO's code which works fine, and I tried to emulate his conversion without success.

I'm trying to put this code on labview now, can anyone help me?

Spoiler
adc_val[i] <<= 8; //shift to left

for (i=0; i <= 2; i++){ // Single ended Measurements
if(adc_val[i] > 0x7fffff){ //if MSB == 1

Where am I doing wrong?

Note, FORLOOP is used to read multiple values ​​consecutively.

Message 1 of 8
(294 Views)

## Re: How to Convert SPI Data Correctly?

Hi koukileo,

@koukileo wrote:
adc_val[i] <<= 8; //shift to left

for (i=0; i <= 2; i++){ // Single ended Measurements
if(adc_val[i] > 0x7fffff){ //if MSB == 1

Best regards,
GerdW

using LV2016/2019/2020 on Win8.1/10+cRIO
Message 2 of 8
(280 Views)
Solution
Accepted by topic author koukileo

## Re: How to Convert SPI Data Correctly?

Thanks for your reply, I finally understand my problem, the ADC is 24bit data, so I want to divide it into three sections with 8bit. The code is as follows~

Message 3 of 8
(256 Views)

Message 4 of 8
(254 Views)

## Re: How to Convert SPI Data Correctly?

Hi koukileo,

@koukileo wrote:

Thanks for your reply, I finally understand my problem, the ADC is 24bit data, so I want to divide it into three sections with 8bit. The code is as follows…

Quite convoluted!

Whenever you start to copy&paste the same code several times you should think about using a loop to call that code repeatedly! (And when you combine this with LabVIEW autoindexing feature it becomes really easy…)

Best regards,
GerdW

using LV2016/2019/2020 on Win8.1/10+cRIO
Message 5 of 8
(243 Views)

## Re: How to Convert SPI Data Correctly?

Thanks for your advice~ I forgot to have this method. Thank you very much~

Message 6 of 8
(217 Views)

## Re: How to Convert SPI Data Correctly?

Hi koukileo,

@koukileo wrote:

Thanks for your advice~ I forgot to have this method. Thank you very much~

Why use a loop (or duplicated code) at all when you only need the result of the first iteration?

Best regards,
GerdW

using LV2016/2019/2020 on Win8.1/10+cRIO
Message 7 of 8
(188 Views)

## Re: How to Convert SPI Data Correctly?

What you can see in the picture is to demonstrate the use.
I actually have a 3-axis accelerometer, so I end up needing 3 DATA~
Best regards

Message 8 of 8
(175 Views)