cancel
Showing results for 
Search instead for 
Did you mean: 

Question about Receive Only Master (SPI_DIRECTION_2LINES_RXONLY)

pass3master
Associate III

NewFile0.png

This is a question about Receive Only Master (SPI_DIRECTION_2LINES_RXONLY).

I was able to output the waveform shown in the attachment using Receive Only Master.

However, no data is being received(tmp). Why is this?

 

The process is performed in the following order:

HAL_SPI_Receive_IT(&hspi2, tmp, data_size);

HAL_SPI_Transmit(&hspi4, g_rx_temp_register, data_size, 1000);

hspi2(Receive Only Master)

hspi4(Transmit Only Slave)

 

About the waveform in the attached image

1ch hspi2 clock

2ch hspi2 MISO

5 REPLIES 5
Andrew Neil
Evangelist III

@pass3master wrote:

The process is performed in the following order:

HAL_SPI_Receive_IT(&hspi2, tmp, data_size);

HAL_SPI_Transmit(&hspi4, g_rx_temp_register, data_size, 1000);


Again, please see the Posting Tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

like this:

HAL_SPI_Receive_IT(&hspi2, tmp, data_size);

HAL_SPI_Transmit(&hspi4, g_rx_temp_register, data_size, 1000);

Why are you doing two transfers?

which one is shown by your scope trace?

Why is the first one non-blocking (interrupt-driven), but the second is blocking?

The HAL_SPI_Receive()  will not have completed when you call HAL_SPI_Transmit() - so the HAL_SPI_Transmit() will be returning an error.

You should always check the return results!

HAL_StatusTypeDef result;

result = HAL_SPI_Receive_IT(&hspi2, tmp, data_size);
if( result != HAL_OK )
{
   Error_Handler();
}

result = HAL_SPI_Transmit(&hspi4, g_rx_temp_register, data_size, 1000);
if( result != HAL_OK )
{
   Error_Handler();
}

 

See this thread about receive-only master:

https://community.st.com/t5/stm32-mcus-embedded-software/hal-spi-receive-it-also-transmits/td-p/737532

Note that HAL does not use the receive-only Master - internally, HAL_SPI_Receive() calls HAL_SPI_TransmitReceive()

I forgot to point that out. Sorry.

The reason for the two transfers is that the customer has requested that the pins used for spi2 and spi4 be separated.

spi2 is the master receiving pin, and spi4 is the slave transmitting pin. Also, the spi2 clk line and the spi4 clk line are connected.

I'm sorry, I'm a beginner. What is a scope trace?

The reason for the distinction between non-blocking and blocking is that we want to perform the spi4 transfer process while the spi2 master's receiving clk is being output.

This is an abstract explanation, but spi4 must transfer using the clk output by the spi2 master. This is a customer request.

I think my settings are probably wrong. I understand that.
What kind of settings are necessary to achieve the above?


@pass3master wrote:

spi2 is the master receiving pin, and spi4 is the slave transmitting pin. Also, the spi2 clk line and the spi4 clk line are connected.


This makes no sense!

Why are you using two SPI peripherals?

Again, show your schematic:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 


@pass3master wrote:

What is a scope trace?


"scope" is short for "oscilloscope" - this is a scope trace:

AndrewNeil_0-1730460156667.png

 


@pass3master wrote:

I'm sorry, I'm a beginner. 


Does your customer know this?

Do you not have supervisors or colleagues to help you?

In the future, these will be connected to separate devices.
The spi2 will be connected to the slave's transmitter device and the spi4 to the master's receiver device. So we are using two SPI peripherals.
↑Is this correct as an answer?

Is that what you meant, this is the scope of hspi2 (receive).
The top is the hspi2_clk pin and the bottom is the hspi2_MISO pin.

This is also for my own study.

Although I have a boss I can consult with, my goal is to find and solve the problem myself.


@pass3master wrote:

Although I have a boss I can consult with, my goal is to find and solve the problem myself.


but you're not answering it yourself - you're asking people here to answer it for you.

But people here have no idea what you have, nor what you're trying to achieve, nor what these strange customer requests actually mean, etc, etc

It would be much easier and more effective to ask someone in person, who knows you and what you are doing!

 


@pass3master wrote:

Is that what you meant, this is the scope of hspi2 (receive).


This is a prime example!

You just posted the screenshot, but we have no idea what it represents