"I've seen some video" without a link to the video makes a discussion useless.And I've seen some videos and info that SPI usually have 16 bit registers and not 8 bit.
If you want to transmit 1 byte, then send 1 byte,If I want to transmit 1 byte and receive 2 bytes then in total the whole transaction is 3 byte.
"I've seen some video" without a link to the video makes a discussion useless.
* the video may give wrong informations
* the video may give informations that does not fit to your slave
* the video may give informations that does not fit to your master
* you may have misunderstood some informations
* something else
We can not know what happens. Thus:
--> Post a link to video.
If you want to transmit 1 byte, then send 1 byte,
if you want to receive 2 bytes, then you have to send 2 bytes.
I haven't understood the second points. Isn't MOSI and MISO aren't in series ? I mean the registers shifting in series to the other registers.Some rules:
* SPI is designed for 8 bit wide access. If you want 16 bit, then use 2x 8bit. ( some massters/ slaves may support special modes)
* Sending out via MOSI is always in parallel with receiving via MISO
* if you don't need to receive, then simply dismiss the received byte
* if you want to receive 8 bits, you always need to send 8 bits (a so called dummy byte) to create the 8x SCK cycles
Slave:
How sending and recieving is handled (which bytes containes invalid / valid data ... and their meaning ... tells the slave's datasheet.
--> Thus for a meaningful communication example it's urgent to tell which slave you want to communicate with. Link to datasheet!
The master's software needs to be adjusted to the slave.
Master:
* Each master is expected to support 8 bits.
* There may be masters that additionally support 16 bit or even 32 bit access (to optimize processing time), then the master's datasheet tells you how to handle this. --> Link to datasheet
There is no general R/W bit in SPI.
If you have a slave that supports an R/W bit, then it's function is explained in the according datasheet.
--> So do yourself a favour and give specific informations.
I've already answered this. Generally.Of course but I was wondering if master and slave are 16 bits then they must send all 16 bits to works properly ? Asking it generally because I know for 8 bit they must send the whole 8 bits.
In some masters / slaves maybe. I've already explained: It depends.Isn't MOSI and MISO aren't in series ?
So you know RW is something slave_specific ... then it makes no sense to refuse to tell which "specific" device you are talking about.R/W bits aren't SPI specifically, I just gave an example of how the Slave device know when he Sends data and when he Receives.
I didn't understand it that's why I asked the question again.I've already answered this. Generally.
In some masters / slaves maybe. I've already explained: It depends.
I asked for clear informations about master and slave. I still miss.
So you know RW is something slave_specific ... then it makes no sense to refuse to tell which "specific" device you are talking about.
It just makes helping unnecessary difficult.
So I thought correctly about dummy bytes.A "dummy byte" usually is just 8 bits, where the values of the bits have no meaning. It does not matter whether it's 0x00, 0xFF or any other value inbetween.
You are probably right I was just wondering how they do this.With SPI, there is not much "defined generally".
Most of your questions and ideas are "specific to some devices". It is impossible to discuss them in general.
STM32 NucleoL073RZ.Hi,
"STM32" is not specific, I don't want to investigate which microcontroller is used with your Nucleo board, nor do I do the search for the microcontroller datasheet.
--> It's your job.
SPI transfer size is a multiple of 8 bits. Full stop. A general purpose SPI master is required to support it, and any STM32 processor surely does. STM32 additionally supports 16-bit frame format, you can use it if it fits your application.
Hi,
A last try:
You want to bake a cake. It needs 16 eggs.
But the eggs are only sold in 8 piece packages.
Can you solve the problem?
Klaus
how often do we need to say that general SPI data format is 8 bits.
STM32 can work with 8 bit format. Why not use this standard format?
Just because it additionally is able to work with non standard 16 bit format, does not mean you need to use it.
You don't understand that 8, 24 are very regular ammount of eggs. It's standard. It's easy to transmit 1 packet, 3 packets of 8 eggs each.That's why I was wondering how it could work with 16 bit packet size when I need non regular ammount of eggs like 8, 24 etc.
Hello !
I want to a quick question about SPI.
Why using non standard .. where is no need to ... then expecting problems (that not existed before) .... then looking for non standard solutions for self made problems.
* There may be masters that additionally support 16 bit or even 32 bit access (to optimize processing time), then the master's datasheet tells you how to handle this. --> Link to datasheet
I don't even see a benefit in using 16 bit packet size on an STM32 at all. Do you see a benefit?
If there is no benefit ... why does one even consider it?
Don't get me wrong. I'm happy to find a solution for a real problem.
But I don't want to spend my time on "how to generate unnecessary problems".
Well it somehow works I guess, then correct me if I'm wrong, for 8 bit format in 16 bit register in Master the first 8 bits are the transmit bits and the last 8 bits are the received bits always, the opposite is then for slave. It would make sense in a way of receiving/sending 8 bit formats.
* There may be masters that additionally support 16 bit or even 32 bit access (to optimize processing time), then the master's datasheet tells you how to handle this. --> Link to datasheet
My imagination of SPI was locked with 8 bit format with 8 bit registers but since I've seen the video that the registors have 16 bit registors and not 8 bit then I got really confused on how these SPI works. The placement of bytes and how it reads it (like the situation with the 3rd byte placed in the place where the 4th byte would be placed or if we read only 1st byte then it is placed also in the place of 2nd byte so every odd number of bytes makes it confusing).
You don't understand that 8, 24 are very regular ammount of eggs. It's standard. It's easy to transmit 1 packet, 3 packets of 8 eggs each.
But your 16 bit packet size is non standard. You make it difficult. Unnecessary difficult.
You can optimize only where it is possible to do so.Maybe for optimazing the proccesing time like you've said here :
let's say I want to make SPI from the ground
*****At least if not with 16 bit format tell me if my thinking for 8 bit format is correct ?I´ve already told you. Now repeated:It´s not a question of correct thinking, it´s a question on how the slave treats it. You need to read the slave´s datasheet.(Capitals not meant as shouting but to emphasize)THEN ask a question REFERRING to the slaves communication specification.
If a customer wants 8 eggs, give him a single box with 8 eggs (SPI: 8 bits = 1x 8 bits = 1 byte, 8 SCK cycles)Something about 16 bit format. Like writing 1 byte but it sends 2 bytes or just changing the pack size etc.
So it is used, and wanted to know what if ...
If a customer wants 8 eggs, give him a single box with 8 eggs (SPI: 8 bits = 1x 8 bits = 1 byte, 8 SCK cycles)
If a customer wants 16 eggs, give him two boxes with 8 eggs (SPI: 16 bits = 2x 8 bits = 2 byte, 16 SCK cycles)
If a customer wants 24 eggs, give him three boxes with 8 eggs (SPI: 24 bits = 3x 8 bits = 3 byte, 24 SCK cycles)
I don´t know what´s the problem
Are you sure we still are talking about SPI?
* SPI are a couple of signals: SS, MOSI, MISO, SCK
* sending 2 x 8 bits over SPI results in:
--> 16 SCK cycles, 16 bits transferred on MOSI, 16 bits transferred on MISO
* sending 1 x 16 bits over SPI results in:
--> 16 SCK cycles, 16 bits transferred on MOSI, 16 bits transferred on MISO
For the SPI there is no difference whether you (STM32 internally) transfer 2x 8 bits or 1 x 16 bits. The slave will never know.
BUT: you have to follow the sequence described in the slave´s datasheet. Read it, read it, read it. Refer to it.
And again, it´s the same as with the eggs. If you have standard 8 bit boxes you can serve every customer that wants 8, 16, 24, 23 eggs.
But you have a problem if you change to 16 egg boxes and a customer asks for 8 or 24 eggs.
So it all leads to the slave, whether the slave is compatible with master or not.Are you sure we still are talking about SPI?
* SPI are a couple of signals: SS, MOSI, MISO, SCK
* sending 2 x 8 bits over SPI results in:
--> 16 SCK cycles, 16 bits transferred on MOSI, 16 bits transferred on MISO
* sending 1 x 16 bits over SPI results in:
--> 16 SCK cycles, 16 bits transferred on MOSI, 16 bits transferred on MISO
For the SPI there is no difference whether you (STM32 internally) transfer 2x 8 bits or 1 x 16 bits. The slave will never know.
BUT: you have to follow the sequence described in the slave´s datasheet. Read it, read it, read it. Refer to it.
I´ve already told you. Now repeated:It´s not a question of correct thinking, it´s a question on how the slave treats it. You need to read the slave´s datasheet.(Capitals not meant as shouting but to emphasize)THEN ask a question REFERRING to the slaves communication specification.
No, not understood. Read postAha, so as far as I understood
If the master sends 1x 16 bits and slave sends 1x8bits then there might be a problem. If master sends 1x16 and slave as well 1x16 bits then it is all fine.
No. If you - in the meaning of the microcontroller program - is keeping on SPI standards then EVERY SPI slave will be compatible.So it all leads to the slave, whether the slave is compatible with master or not.
And slave only wants 8 bits that's how I understood it was a problem.But you have a problem if you change to 16 egg boxes and a customer asks for 8 or 24 eggs.
Again, again, again... read the slave´s datasheet about the meaning of the bits. No one can tell without reading the datasheet of the slave.
It seems you want to play a game.
Not reading the documents. Not keeping on standards, not giving meaningful examples by referring to datasheets.
I´m fine you optimize to 16 bit packets when ALL of your slaves can work with 16 bit packets or multiples.
But you asked how to handle 8 bit access.
And again, it´s the same as with the eggs. If you have standard 8 bit boxes you can serve every customer that wants 8, 16, 24, 23 eggs.
But you have a problem if you change to 16 egg boxes and a customer asks for 8 or 24 eggs.
Understandable, although I have a feeling no one will answear to my weird questions.Don´t get me wrong, we don´t get a step forward. And I´m not patient enough.
So I leave it to others to answer your questions.
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 ?
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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?