cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

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.

   

 

   

Looking forward for your suggestion.

   

 

   

Best Regards

   

Awais

0 Likes
Reply
1 Solution
Esteemed Contributor II

Well, something like

   

uint32 TxData;

   

uint8 A,C;

   

uint16 D;

   

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

   

 

   

Bob

View solution in original post

0 Likes
Reply
7 Replies
Esteemed Contributor II

(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

0 Likes
Reply
Anonymous
Not applicable

Thankyou Bob for your reply.

   

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

0 Likes
Reply
Esteemed Contributor II

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

   

That does not fit into an uint8

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Ahan!

   

Then how should i put them?

   

Looking forward for your reply.

   

Regards

   

Awais

0 Likes
Reply
Esteemed Contributor II

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

0 Likes
Reply
Anonymous
Not applicable

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.

   

Looking forward for your reply

   

Regards

   

Awais

0 Likes
Reply
Esteemed Contributor II

Well, something like

   

uint32 TxData;

   

uint8 A,C;

   

uint16 D;

   

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

   

 

   

Bob

View solution in original post

0 Likes
Reply