Community
cancel
Showing results for 
Search instead for 
Did you mean: 
YLu11
New Contributor I
1,762 Views

Array Storage Sequence when Reading Multiple Bytes

I am trying to get multiple bytes from my sensor and I am not sure what is the correct sequence that Intel Edison use to store data to a buffer array.

Specifically, I am trying to use this method to get data from Ublox gps module stored in address # 0xFD and # 0xFE:

uint8_t buf [2];

mraa_i2c_read_bytes_data(m_i2c, 0xFD, buf, 2); //this should give me data from address # 0xFE as well because of auto-increment of address counter

Now, the following code is from upm ADIS16448 library.

So this code suggests that the upper byte is stored inside buf[1] instead of buf[0]. Does that mean that in my case, the data from # 0xFE is stored in buf[0] and data from # 0xFD is stored in buf[1]? And What will happen if I declare buf size to be 3 for example?

Thanks in advance

5 Replies
idata
Community Manager
100 Views

Hello lyfkyle,

There's something I don't understand about your question. You mention that you need to understand how buffers are "filled" and you mention the mraa command to read I2C bytes but then you post a section of the ADIS16448 library which works with SPI.

Nevertheless, the way the bytes "enter" in the ADIS16448 library is not through buf, but instead they are received through x and then ordered into _dataOut which is what's returned.

Peter.

YLu11
New Contributor I
100 Views

Hello Peter:

I am sorry for the confusion in my code, The code of ADIS16448 suggests that the x[1] stores the upper byte while x[0] stores the lower byte. So I assume that in my case, if I run mraa_i2c_read_bytes_data(m_i2c, 0xFD, buf, 2), buf[1] stores data from # 0xFD and buf[0] stores data from # 0xFE, I am just asking to confirm my speculation.

Thank you very much.

Lyfkyle

idata
Community Manager
100 Views

I believe you are right, however I believe arfoll might be able to reply to this question more accurately.

 

 

Peter.
Brendan_L_Intel
Employee
100 Views

You have the right idea, that's what it'll do.

YLu11
New Contributor I
100 Views

Hi all,

I am posting this as clarification as I finally realized what caused me the confusion.

I have recently discovered that ADIS16448 actually stores upper byte at an address higher than the address of the lower byte. That is the reason why buf[1] contains upper byte while buff[0] contains the lower byte. So if I run the mraa_i2c_read on another device which stores the data in its registers using the reverse order, the data I get in my buffer will be in reverse order as well.

lyfkyle

Reply