Skip to main content
Visitor II
August 5, 2021
Solved

MOSI data during HAL_SPI_Receive operation

  • August 5, 2021
  • 2 replies
  • 1199 views

I'm using Nucleo-F767 with IAR IDE. I have created project using STM32CubeMx v6.3.0.

I want to send one byte over MOSI and receive 27 bytes of data from SPI slave device on MISO. I noticed that random data is seen on MOSI line from 2nd byte. How to make MOSI data as 0x00 for 27 bytes i.e., during SPI Read operation.

Scope capture attached.

Code:

 HAL_SPI_Transmit(&hspi3, spiTxBuf, 1, 50);

 HAL_SPI_Receive(&hspi3, spiRxBuf3, 27, 50);

Note: MOSI data is required to make 0x00 in order to make slave device functionality working fine as expected.

0693W00000D1cf2QAB.png

    This topic has been closed for replies.
    Best answer by TDK

    > How to make MOSI data as 0x00 for 27 bytes i.e., during SPI Read operation.

    Use HAL_SPI_TransmitReceive and set the outgoing buffer bytes to 0x00.

    Move both calls into a single call to HAL_SPI_TransmitReceive with length 28 and discard the data you don't want.

    2 replies

    TDKAnswer
    Super User
    August 5, 2021

    > How to make MOSI data as 0x00 for 27 bytes i.e., during SPI Read operation.

    Use HAL_SPI_TransmitReceive and set the outgoing buffer bytes to 0x00.

    Move both calls into a single call to HAL_SPI_TransmitReceive with length 28 and discard the data you don't want.

    S.KamathAuthor
    Visitor II
    August 5, 2021

    Thanks, Issue got resolved ..!