cancel
Showing results for 
Search instead for 
Did you mean: 

transfer SPI data from spi4 block defined as SPI MASTER to spi5 block defined as SPI SALVE without success.

VKats.1
Associate II

ia m using STM32h743II MCU and i am trying to transfer SPI data from spi4 block defined as SPI MASTER to spi5 block defined as SPI SALVE without success.

I am using the HAL_SPI_Transmit from the SPI MASTER block (spi4 block) and HAL_SPI_Receive from the SPI SLAVE block (spi5 block).

the HAL_SPI_Transmit() API is working successfully each time (verified by Scope).

but the HAL_SPI_Receive() returned HEL_ERROR and HAL_SPI_GetError() return the specfic error 0 (HAL_SPI_STATE_RESET) and i cannot understand what i did wrong?

I've developed only in ComPolling mode(I2C and UART blocks) so far and everything worked perfectly but not SPI block.

i've attached the following info:

1) my main function

0693W00000JPftNQAT.png2) the MX_SPI4_Init():

0693W00000JPftwQAD.png3) the MX_SPI5_Init():

0693W00000JPfvdQAD.png4) the HAL_SPI_MspInit()

0693W00000JPfqAQAT.png5) HAL_HAL_SPI_MspDeInit():

0693W00000JPfwWQAT.png6) the HAL_SPI_Transmit() call from the master board on the spi4 block:

0693W00000JPfrIQAT.png7) the HAL_SPI_Receive() call from the slave board on the spi5 block:

0693W00000JPfx0QAD.png 

the flow is:

# activate the spi slave (spi5 block) using HAL_SPI_Receive() call and wait for spi transaction

# activate the spi master (spi4 block) using HAL_SPI_Transmit() call and send the payload "aabbccdd" (this transaction is working and verified by scope)

# spi Clk, CC, MISO and MOSI pins from spi4 block header are connected respectively to the spi Clk, CC, MISO and MOSI pins on spi5 block.

I would love to get some guidance and understanding of what I am doing wrong

8 REPLIES 8
MM..1
Chief II

Your idea using blocking call do perfectly what you write.

HAL_SPI_Receive() call and wait for spi transaction

But in timeout nobody send data and result is nothing received.

After this master transmit work what is normal.

Your test only work with non blocking call to HAL_SPI_ReceiveIT() or DMA

TDK
Guru

> HAL_SPI_STATE_RESET

This means the peripheral has not been initialized and is still in the reset state. It could also be that you're passing an incorrect pointer to HAL_SPI_Receive.

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

First of all, thank you very much for the quick reply.

Secondly, I probably forgot to mention that I work with threads:

# my HAL_SPI_Transmit() and HAL_SPI_Receive() are running using thread - so my slave is actuall "waiting" using the thread to spi transaction from spi master.

meanwhile, nothing received on the slave block but once the spi master sent some transaction successfully(again verified by scope) nothing is Received on the slave block

Hi, thank you for your input - after debugging a little bit more what I'm actually receive is:

from HAL_SPI_Receive()  -> HEL_ERROR returned

from HAL_SPI_GetError()  -> 0 value return which mean HAL_SPI_ERROR_NONE

which means that this behavior is ok while the salve is waiting - but once the master sent a successful spi transaction, it should be changed.

maybe me MX_SPI5_Init() and MX_SPI4_Init() are not correct?

MM..1
Chief II

Last parameter in both call is timeout 1000, then you need sync threads with some semaphore, and too your OS need continue and handle interrupts on both threads...

hi,

thank you - I've added a semaphore but still  HAL_SPI_Transmit() is sent successfully while HAL_SPI_Receive() returns HEL_ERROR.

VKats.1
Associate II

I can't find any example of SPI Com Polling that used the HAL_SPI_Transmit() and HAL_SPI_Receive()  separately - all the examples I've seen are using HAL_SPI_TransmitReceive.

can anyone refer to some examples using the HAL_SPI_Transmit() and HAL_SPI_Receive()  separately?

MM..1
Chief II

I dont mean examples with RTOS and your config exist. Try use two boards or as i write HAL_SPI_ReceiveIT()