7 Replies Latest reply on Jun 23, 2016 4:59 AM by JoMe_264151

# How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

Hello Every one,

My questions looks confusing at start but its pretty straight forward explaining below.

I have an external DAC (DAC8563) which i want to set using spi communication. I want to send 24 bits from PSOC program via SPI Master to my dac chip.

But i dont have the possibility to send directly 24 bits. So i decided to do zero padding or adding don't care bits.

Now my bits looks like this : txdata  = (c << 29) || (a << 26) || (x << 10); // 32 bit data input register.

txdata = xx0000001111111111111111xxxxxxxx

Now i want to split these bits into three 8 bits, so that i can directly write these bits.

I was thinking to split these bits into "txdada_hi, txdada_middle, txdada_lo ". But i dont know how i can do this.

I need help regarding this or any better solution is also welcome.

Best Regards

Awais

• ###### 1. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

(c << 29) || (a << 26) || (x << 10); // 32 bit data input

|| is the logical OR, the binary OR you nneed is only one |

what are c, a and x in your above line?

To extract "txdada_hi " from a 32bit signed int "Data" use

txdada_hi = (uint8)((Data & 0x00ff0000) >> 16);

accordingly

txdada_med = (uint8)((Data & 0x0000ff00)>> 8);

and

txdata_Low = (uint8)(Data & 0x000000ff);

Bob

• ###### 2. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

Here are these:

uint8 c = 0x000; // control values
uint8 a = 0x000; // address select (000- DAC-A)

uint16 data = 0xffff;// 16 bit Data (all 1s)
int32 txdata = 0;

Regards

Awais

• ###### 3. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

uint8 a = 0x000; // address select (000- DAC-A)

That does not fit into an uint8

Bob

• ###### 4. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

Ahan!

Then how should i put them?

Regards

Awais

• ###### 5. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

each hexadecimal digit occupies 4 bits, so uint8 c = 0x000; would mean to have a 12bit constant pressed into an 8bit variable.

Try to describe exactly how you want your 24bit to be built.

Bob

• ###### 6. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

I always  mix this thing. Please correct me Bob.

On page 37, Table 14. DAC856x Data Input Register Format in the attachment are the bit format. Can you please have a look on it and guide me how it would be.

Regards

Awais

• ###### 7. Re: How To split 32 Bits into three 8 bits or two 16 bits, inorder to transfer 24 bits via SPI Master?

Well, something like

uint32 TxData;

uint8 A,C;

uint16 D;

TxData = (((uint32)A & 0x07) << 16) | ((uint32)C&0x07 << 19) | (uint32)D;

Bob