2021-08-04 06:41 AM
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
2021-08-04 07:24 AM
Is STM32 Master or Slave?
How did you connect Master and Slave? Did you connect MISO to MISO and MOSI to MOSI?
JW
2021-08-04 07:31 AM
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);
2021-08-04 07:47 AM
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.
2021-08-04 11:26 AM
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)
2021-08-04 12:06 PM
> 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.
2021-08-10 03:06 AM
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