LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert SPI Data Correctly?

Solved!
Go to solution

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] = SPI.transfer(0);
adc_val[i] <<= 8; //shift to left
adc_val[i] |= SPI.transfer(0);
adc_val[i] <<= 8;
adc_val[i] |= SPI.transfer(0);

for (i=0; i <= 2; i++){ // Single ended Measurements
if(adc_val[i] > 0x7fffff){ //if MSB == 1
adc_val[i] = adc_val[i]-16777216; //do 2's complement

 Where am I doing wrong?

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

 

問題.png數值.png

0 Kudos
Message 1 of 8
(1,331 Views)

Hi koukileo,

 


@koukileo wrote:
adc_val[i] = SPI.transfer(0);
adc_val[i] <<= 8; //shift to left
adc_val[i] |= SPI.transfer(0);
adc_val[i] <<= 8;
adc_val[i] |= SPI.transfer(0);

for (i=0; i <= 2; i++){ // Single ended Measurements
if(adc_val[i] > 0x7fffff){ //if MSB == 1
adc_val[i] = adc_val[i]-16777216; //do 2's complement

What about this one:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,317 Views)
Solution
Accepted by topic author koukileo

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~

Code part from this article: SPI on myRIO with synchronous 8 channel ADC

 

koukileo_0-1643131118584.png

koukileo_1-1643131125952.png

 

0 Kudos
Message 3 of 8
(1,293 Views)

Your code is great too~ Made me understand new ways.

0 Kudos
Message 4 of 8
(1,291 Views)

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/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(1,280 Views)

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

 

koukileo_0-1643168960439.png

 

0 Kudos
Message 6 of 8
(1,254 Views)

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/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(1,225 Views)

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

0 Kudos
Message 8 of 8
(1,212 Views)