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.

SPI with 16 bit registers and not 8 bit.

Xenon02

Full Member level 3
Joined
Nov 12, 2022
Messages
158
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
2,215
Hello !

I want to a quick question about SPI.
I've read alot about them and usually the SPI is shown with 8 bit registers like here :

1699311536326.png


And I've seen some videos and info that SPI usually have 16 bit registers and not 8 bit.



The thing is I am not sure what happens with one situation.
If I want to transmit 1 byte and receive 2 bytes then in total the whole transaction is 3 byte. So what happens with 4-th byte ? I know that 1st byte transmitted the master will receive dummy byte, and 2 bytes received by slave, the master will transmit 2 dummy bytes, but the 4th byte ? Is the 4th byte both dummy from master and dummy from slave ? Because the full transaction between Master and Slave for 16 bit register must be minimally 16 bits and not 8 bits like in the picture.

Second question is that whenever Master or Slave want's to transmit information the other side automatically fulls it's register with dummy byte ? For example Slave sends data to Master then Master fills his register with dummy byte and sends it ? Usually these dummy bytes are ignored but It's good to know if it's a hardware thing or what that fills the registers with something(like okey now slave you receive data so you must clear your register with "0"). Like what is connected more to shift registers ? What clears the registers and puts in dummy byte or data byte ? Dummy byte are usually "0" so there must be another register or something that puts into these register this "0" dummy byte. And I know that dummy byte doesn't have to be "0" or "1" it can be any random data.

It's hard to imagine this clear phase with simple picture (I've checked some more complex pictures but It was to complicated).

PS.
I came up with another thing : how it does that the Slave doesn't read the dummy bytes, how he ignores them (I know that R/W bite can be a solution but !), there was one example where I had to use Write bite to send dummy bytes so how does the device know that it is a dummy byte and not an overwrite data when it says (send dummy bytes 5-8) ? If I send 6 is it enough ? How does it know?
 
Last edited:
Hello Dora !
Which 4th byte?
This doesn't make sense. It's like saying: I want to ship a 10 kg package and receive
a 20 kg package by mail. What happen to the next 10 kg? Or I want to send a 1MB image
file and my friend will send me a 2 MB file. What happens to the 4th MB?
If the transaction is finished, then you don't have to send any byte. There is no 4th
byte.

What I meant by 4th byte was that if : the SPI was 16 bit format, but we requested only 3 bytes which is in total 24 bits which is not a multiple of 16. Then there would be a problem. You would say why ? Imagine that we have a data 00000001 00000010 00000011. First 16 bits will be stored like that : 00000001 00000010 1st byte is the first data, second byte is the second data, now how will be transported 3rd byte ? It would be stored like that : 00000010 00000011 only shifted 8 times but it is in 16 bit format sending ot 8 bit. So the third byte will be read as 00000010 and not 00000011. Because there is an algorytm how it reads data from Master registers and it sees its irregular placement if it's 16 bit format sending and not regular 8 bit.

Conclusion from the previous user : If it's 16 bit format then data must be sent and received 16 bits. If it's in 8 bit format it would work like in your picture I guess.

1699550588712.png


Like here Master is 16 bit register and Slave is 16 bit register as well. So I imagined it that first byte of a master is the data M0-M7 and the second byte is a dummy byte the whole 16 bits are reserved, same goes with slave but opposite.

That's why I came up with these anwears for myself and I looked for approvement (like points 1 is ok points 2 is quite ok) :
- Is it also device dependant how the SPI with 16 bit registers interprets its data ? It works in 8 bit format so my 1st proposition to how it could work is that first 8 bits are for transfer only and next 8 bits of the register is for receive only and that's how it works for 8 bit format. Not a bad conclusion?

- If the SPI with 16 bit register works as 16 bit format and not 8 bit format, means that is must send 16 bits and receive 16 bit ? If so then Slave register must also have 16 bit to work in 16 bit format. That's what I thought of.

- If SPI works in 16 bit format then if Slave is in 8 bit format (want to receive 1 byte or 3 byte) it wouldn't work. So Slave must be also in 16 bit format.

- The size of registers can tell how maximally can be the format of SPI.

Other issue: STM32 indeed allows to setup a SPI engine with differnt bit value. I don't understand for what reason they did that, but they did. A very good way to be incompatible with everything else.
Here is a screenshot of CubeMX. You can configure any data width between 4 and 16. On the right, you
can see partly a drop down menu, 4, 5,6, ... 11 bits, but it goes up to 16.

I think it is like that because the register is max 16 bit so you can set it to 16 bit format like I was trying to say. That instead of 8 bit format that you send 8 bits and receive 8 bits, it works then as sending 16 bits and receive 16 bits.

So the 16 bit register must have an algorythm how to manage the 16 bit register to work in 8 bit format. I've tried to give some of my conclusion above :>

Thank you so much Dora, have a nice day :>
 
Hello!

I want to a quick question about SPI.

Just thinking you might have long questions in the future scares me.

And I've seen some videos and info that SPI usually have 16 bit registers and not 8 bit.

Be careful with what you see on a random video on the net, be it technical, news or
whatever else. What was the context? "Usually"? How frequently?
I would say that usually if you design silicium, you don't setup more registers than
necessary. And usually SPI sensors, memory chips, etc, work in 8 bit SPI.

So the 16 bit register must have an algorythm how to manage the 16 bit register to work
in 8 bit format. I've tried to give some of my conclusion above :>

STM32 has obviously at least 16 bit registers because you can setup 16 bit
SPI. What does it change? If the SPI setup is 8 bit, then you will use (i.e. transmit
or receive) only the 8 first bits of this register, be it lsb or msb. I don't know any other
processor working with up to 16 bit SPI. And I don't understand why they did it.
But that's only a physical register in which you can put whatever you want.

Just imagine you have a company shipping goods, be it water mellons, water guns or
water pumps. You have a parking area with 32 trucks. For some order, you need
8 trucks. Will you move all your 32 trucks or just use 8 of them?

So this will be the last time before I give up: if you need to send a byte, you just
send a byte. If you need to send 3 bytes, you send 3 bytes, not 4.

What I meant by 4th byte was that if : the SPI was 16 bit format

If the SPI is in 16 bit mode, it means that YOU set it that way. We're not
responsible of your choices. In this case, obviously, you will have to send and
receive 2 16-bit words and ignore half of the second one.
If you want to be compatible with existing hardware, configure it in 8 bit mode even
if you need only 4 bits.

Second question is that whenever Master or Slave want's to transmit information the
other side automatically fulls it's register with dummy byte ?

It doesn't have to. Dummy bytes are just ignored.
Have you ever boarded a cable car? That's exactly what SPI does. On both sides you have
a departure and an arrival platforms. Early in the morning, the descending car is
empty. Do you think the guys at the top station fill the descending car with
absent people? Do you think the guys at the base station will spend time to NOT control
the tickets of the absent people of the empty seats?

how it does that the Slave doesn't read the dummy bytes, how he ignores them

The slave does the same way as the clerk at the base station to NOT control
the empty seats' absent people tickets. It simply ignores the dummy value, in other
words, it does as if the dummy value didn't even exist.

how does the device know that it is a dummy byte

It doesn't know anything. YOU know it. It's designed that way, YOU read the documentation
and YOU design the software to be compliant with the SPI device YOU have chosen.
Example: In a SPI memory context, you send an opcode and an address.

C = opcode byte
D = dummy
A = address
V = value

You read this in the datasheet that reading a byte is done as follows : CAAAD
So this is a memory containing between 128k and 16M of memory (17 to 24 bit, therefore
3 bytes address).

Therefore in the MISO, buffer you will receive DDDDV and you can retrieve the value
by val = misobuf[4]. (i.e. you don't even look at the dummy bytes). Note that it's a
5-byte buffer, for which you have to exchange 5 bytes, not 6, not 8.

Once you have sent the opcode, the memory knows you want to read.
Once you have sent the address, the memory knows you want the value at address AAA
and immediately sets it to the output buffer.
Then the master dummy byte will be exchanged with the value that was just fetched from address
AAA.
-> at this point, the address is usually automatically incremented, so that if you
send CAAADVVVV, it uses 4 consecutive address bytes to write an integer or whatever else
fitting in 4 bytes.

OK, as I said earlier, It's my last mail on this issue.
I'm not sure exactly how you are trying to learn about SPI. It looks like you are reading
a book and trying to figure out what happens.
What I would advice is that you find a cheap device which is programmable, SPI
capable, etc. Arduino or anything else. You find a cheap oscilloscope. For SPI, even a
cheap device will work. a few 100 dollars.
I would advice a cheap scope but digital, with a SPI decoder so that you don't spend
too much time counting edges. And play with SPI. Modify your program, verify
that you can send your 3 bytes without caring about the 4th. Etc.
Good luck!


Dora
 
Just thinking you might have long questions in the future scares me.

Yea I thought it would be a quick question. Ended up with a long one. My bad here.
STM32 has obviously at least 16 bit registers because you can setup 16 bit
SPI. What does it change? If the SPI setup is 8 bit, then you will use (i.e. transmit
or receive) only the 8 first bits of this register, be it lsb or msb. I don't know any other
processor working with up to 16 bit SPI. And I don't understand why they did it.
But that's only a physical register in which you can put whatever you want.

I've imagined it differently because the whole register works no matter what you do if it's 16 bit register the whole register shifts.
so first 8 bits transmit only and maybe next 8 bits receive only. Would then make sense Like hmmm imagine you want to send a command 00000001 to the slave so in the register it will be putted like that : 00000001 00000000 the slave receives the 00000001 and master will receive something like dummy byte so master now looks like that : 00000000 00000000. Now master want's to receive data like 00000010 so slave pushes it into master and the end result is 00000000 00000010. That's all, my own conclusion how I imagined it executed.
The slave does the same way as the clerk at the base station to NOT control
the empty seats' absent people tickets. It simply ignores the dummy value, in other
words, it does as if the dummy value didn't even exist.

Understandable, probably the program just know that he has to send data and not read what he received.
Just an analogy I came up, but I understand what've tried to say.
It doesn't know anything. YOU know it. It's designed that way, YOU read the documentation
and YOU design the software to be compliant with the SPI device YOU have chosen.
Example: In a SPI memory context, you send an opcode and an address.

Oh you've went pretty far, I pretty much understood now the concept of dummy bytes and how it works a bit.


OK, as I said earlier, It's my last mail on this issue.
I'm not sure exactly how you are trying to learn about SPI. It looks like you are reading
a book and trying to figure out what happens.
What I would advice is that you find a cheap device which is programmable, SPI
capable, etc. Arduino or anything else. You find a cheap oscilloscope. For SPI, even a
cheap device will work. a few 100 dollars.
I would advice a cheap scope but digital, with a SPI decoder so that you don't spend
too much time counting edges. And play with SPI. Modify your program, verify
that you can send your 3 bytes without caring about the 4th. Etc.
Good luck!

Partly yes and partly no ?
I just learned that there is something like SPI, I only knew before about UART. But okey, I went back to SPI read that it shifts 8 bit data and the registers were as well 8 bit, so it was easy to understand and anything. Then there was 16 bit register and the 8 bit format which was weird for me now I kind of understand how it works a bit.
Now why am I trying to understand it ? I've lost a bit the track why I asked this question but perhaps oh random received data with weird content inside and the answear of why it happens lies in the SPI registers and how it works as a hardware.

I'm grasping how it works so I'll try to come up with something.
Still thank you for help.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top