cancel
Showing results for 
Search instead for 
Did you mean: 

SPI - slave response is on MOSI

MKhel.1
Associate II

Hi,

I am currently using the STM32L4 SPI generated from the CubeMX.

I am receiving the slave data on MOSI line (instead MISO) everytime the read function is called.

I selected the direction to 2 lines.

hspi2.Init.Direction = SPI_DIRECTION_2LINES

All 0x00 in the side of MISO. Is this a normal behavior?

Thanks for your reply

6 REPLIES 6

Is STM32 Master or Slave?

How did you connect Master and Slave? Did you connect MISO to MISO and MOSI to MOSI?

JW

MKhel.1
Associate II

The STM32 is the Master. MCU's MOSI pin is connected to Slave MOSI.

The configurations:

hspi2.Instance = SPI2;

 hspi2.Init.Mode = SPI_MODE_MASTER;

 hspi2.Init.Direction = SPI_DIRECTION_2LINES;

 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi2.Init.NSS = SPI_NSS_SOFT;

 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;

 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi2.Init.CRCPolynomial = 7;

 hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

 hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

  GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

TDK
Guru

Why do you think that's the slave's response as opposed to what the master is sending? If the slave really is driving that line, recheck your connections.

If you want a specific pattern on MOSI, use TransmitReceive instead of Receive.

The unspecified slave should be controlling MISO here, so it's hard to know if 0x00 is correct or not.

If you feel a post has answered your question, please click "Accept as Solution".
MKhel.1
Associate II

The test in the attached photo is achieved using the send and then receive.

I was expecting to have the slave data on the second bus MISO and not on MOSI.

The TransmitReceive function doesnt work for me since i have 3 bytes address and i have to send all the spi header first to get the answer from the slave.

I am still not sure why i have the two signals on the same bus.

The connections look fine though:

(MISO - MISO,

MOSI - MOSI,

CLK - CLK,

CS - CS)

TDK
Guru

> The TransmitReceive function doesnt work for me since i have 3 bytes address and i have to send all the spi header first to get the answer from the slave.

The Receive function is a subset of the functionality of the TransmitReceive function in 4-wire mode.

If you feel a post has answered your question, please click "Accept as Solution".
Petr Sladecek
ST Employee

Hello, if I understand well, your STM32 master operates with a slave which uses single data line for both data transmission and reception. Then you need either to configure the slave into full duplex mode (to force its transmission on MISO line) or handle your master at half duplex bidirectional mode to respect the slave interface.

Best regards,

Petr, the IP owner, STMicroelectronics