取消
显示结果 
搜索替代 
您的意思是: 

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?

破坏者
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 项奖励
1 条消息(共 8 条)
5,285 次查看

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 项奖励
2 条消息(共 8 条)
5,271 次查看
解答
接受人 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 项奖励
3 条消息(共 8 条)
5,247 次查看

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

0 项奖励
4 条消息(共 8 条)
5,245 次查看

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 项奖励
5 条消息(共 8 条)
5,234 次查看

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

 

koukileo_0-1643168960439.png

 

0 项奖励
6 条消息(共 8 条)
5,208 次查看

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 项奖励
7 条消息(共 8 条)
5,179 次查看

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 项奖励
8 条消息(共 8 条)
5,166 次查看