SPI problem spidev library to interface with one sensor and it requires to send 32 bits of data.

March 9, 2023, 06:12

noah25011

I want to send 32 bits of data (lets say 0X128932). But, xfer2 sends just 8 bits of data or list of 8 bits of data. So, I am sending 32 bits of data in list as [0x12,0x89,0x32] as I have saleae and i am checking the spi waveform on the logic analyser. So, I want to ask is 0x128932 same as [0x12,0x89,0x32] ??

noah25011

note here the data send is [0x19,0x00,0x00] Is this equivalent to 0x190000??

noah25011

Also, how to receive 16 bit value in spi?

noah25011

since it will be send 8 bits at a time

andy_s

iirc it is in sequence

andy_s

"content" is application level, so it depends on you what you can send

andy_s

how you split is up to you.

andy_s

That is up to you entirely...

noah25011

But i have no idea how to do it

noah25011

This is wat i am asking

andy_s

lets say you have digit 128932h. that is 1214770d.

andy_s

you know it will be 4x2^8

andy_s

so...

andy_s

something is wrong, that is not 4byte number.

andy_s

Atmp = 1214770 / 256 / 256 Atmp = 4745.1953125 / 256 Atmp = 18.535919189453125 A = int(Atmp) = 18

andy_s

it will be 3byte.

andy_s

Btmp = (Atmp - A) 256 Btmp = 0.535919189453125 256 Btmp = 137.1953125 B = int(Btmp) = 137

andy_s

C = (Btmp - B) 256 C = 0.1953125 256 C = 50

andy_s

your digits to send are 18, 137, 50 in decimal. Convert it to hex and you get 12h, 89h, 32h

andy_s

simple math 🙂 <@1082203653999448095>

andy_s

or you can just split it by two if you have it already as hex.

andy_s

but that would involve string.

andy_s

OR ... you know what ...

andy_s

just divide by 100 😄

andy_s

not sure tho, if int supports hexa values

noah25011

can u hckec

noah25011

check the new post

andy_s

what new post

noah25011

so between spi.write and spi.read

noah25011

the chip select is getting high

noah25011

during a complete spi transaction chip select should be low right

andy_s

no idea, sorry, dont know spi protocol by heart...