Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assembling a command for sending a command to DAC8004

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,505
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,114
Hello,I am trying to see how do i assemble the data i need to send over the SPI to set it in a certain state.
so taken from the tables i try to assemble something:
Write to buffer
given cahnnel A address 0000
we have 16-bit data 0000 0000 0000 1001
D3-D0: dont care so i put 0000
D24-D27: 0000

So i just put all those numbers together and send it threw SPI MOSI?
Thanks.

1596906828975.png

1596906688543.png


1596906350900.png
 

So i just put all those numbers together and send it threw SPI MOSI?
Thanks.
Yes - but note that you also have to provide the clock of course and drive the SYNC pin low to tell it the first bit is about to be sent and then high after the last bit to make it accept the data.

Brian.
 
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating
In most cases, SPI interfaces are operated in 8-bit mode, different peripherals are expecting different number of bytes. I don't see a particular advantage in assembling the data to a double word before sending it.

As mentioned above, the command framing is achieved by activating chip select, sending the required number of bytes and deactivating CS.
 
Last edited:
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating
Hi,

In addition what FvM wrote:
We recently had a SPI probkem because of endianness...a 16 bit word was transferred with wrong byte order.
Thus I recommend to use byte arrays.

Klaus
 

Hello Klauss,Yes this is my big concern too,i tried to find it in the reference manual shown bellow.where can i see the order at which my SPI in EFM32LG sends data.
Is it MSB first in descending order.
or LSB first in ascending order?
Thanks.



Hi,

In addition what FvM wrote:
We recently had a SPI probkem because of endianness...a 16 bit word was transferred with wrong byte order.
Thus I recommend to use byte arrays.

Klaus
 

Hi,

SPI sends one byte as 8 bits MSB first.

Chapter 17.5.1 UART CTRL REGISTER, bit 10 = MSBF

You should use a scope to verify SPI signals.

Klaus
 

Hello Klauss, so if i have 4 frames and i send them LSB first then its like a stack each new bite will push the others to the right?
a1 is LSB
a1 -> null
a2 -> a1
a3 -> a2 a1
a4 -> a3 a2 a1
1597000056543.png
 
Last edited:

Hi,

A scope beam is running left to right. Thus the first but sent out is in the left side.
It may be shifted, it may be multiplexed...it does nit matter.

I wonder why you talk about 4 frames.
I wonder why you talk about LSB. Don't confuse yourself by talking about the wrong bit order.
You talk about "bite". I don't know this unit. It's either "bit" or "byte" ... a byte is 8 bits.
I don't know which one you mean.

Klaus
 

Hello Klauss,I talk about 4 frames because as shown in the photo bellow each command is 0-31 , so its 32 bits ,in each frame we have 8 bits of data (no start or stop bits) thus 32/8=4
So if we set MSBF as 0
and my four frames (say we have only 3 bits in each frame):
a1 a2 a3(a3 is LSB)
b1 b2 b3(b3 is LSB)
c1 c2 c3(c3 is LSB)
d1 d2 d3(d3 is LSB)
so if we send frame "a" first then "b" then "c" then "d"
in my DAC it will be recieved as:
d1 d2 d3 c1 c2 c3 b1 b2 b3 a1 a2 a3
Correct?
1597048792933.png
 
Last edited:

Hi

A"frame" can be anything. 8 bits of a byte or 32 bit of a communication.

Your example is confusing.
"MSB first" is quite descriptive.
And for sure if the receiver needs to receive MSB first you have to transmit MSB first.

Again: please accept that SPI is MSB first. So setting MSBF=0 is definitely wrong.

See figure 1 at the DAC datasheet. From left to right DB31 (MSB) ... down to DB0 (LSB).

bytes: fist the byte that contains DB31 down to DB24
then DB23 ... DB16
then DB15 ... DB8
then DB7 ... DB0

Klaus
 

Hello Klauss,Yes MSBF=1 to make MSB send first because SPI algorithm works with that setting.
So regarding what you said earlier,ithough i coudl semd only 8 bits per frame,32 at once is great. how do i make a 32 bit communication frame to send from SPI handle?

Thanks.
 
Last edited:

Hi,

I write an "A"
A

I write 4 times "A"
AAAA

Where is the problem?
If you can send one byte via SPI .... why not simply send three other bytes?
There is nothing unusual. I assume sending multiple bytes via SPI is done more often than sending a single byte.

I'm not able to write C code ... but I can understand a bit.
So pseudo code:
uint8_t tarr[4] ;define an array with 4 bytes
Tarr[0] = 0b01010101 ; bits 7...0
Tarr[1] = 0b01010101 ; bits 15...8
Tarr[2] = 0b01010101 ; bits 23...16
Tarr[3] = 0b01010101 ; bits 31...24
Often there is an SPI function to send the whole array.
Read your library documentation.

If you need bytewise send the data, then you have to count 3 down to 0...

Klaus
 
Last edited:
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating
how do i make a 32 bit communication frame to send from SPI handle
There is nothing clever in SPI, you can send as many bits as necessary, it is just usually easier to handle big data streams in smaller 8-bit chunks. The 'frame' is everything from the enable (SYNC) going active to it going inactive again. I have an SPI module that daisy chains several 40-bit devices and needs an SPI 'frame' of 160 bits!
Using Klaus's pseudo example (and yes you can code in C Klaus! :))
Code:
uint8_t tarr[4]  ;define an array with 4 bytes
Tarr[0] = 0b01010101 ; bits 7...0     // these are the 32 bits you want to send but stored in 8-bit variables
Tarr[1] = 0b01010101 ; bits 15...8
Tarr[2] = 0b01010101 ; bits 23...16
Tarr[3] = 0b01010101 ; bits 31...24

uint8_t  ByteCounter, BitCounter;
SYNC = LOW;     // tell it data is on its way
ByteCounter = 3;
(A) BitCounter = 7;
put Tarr[ByteCounter] bit [BitCounter] on the data line
toggle the clock line
decrement the BitCounter, if it isn't zero, go back to (A)
decrement the ByteCounter, if it isn't zero, go back to  (A)
SYNC = HIGH;   // tell it all the bits have now been sent and can be used

Brian.
 
Last edited:
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top