2022-02-14 01:22 AM
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
2) the MX_SPI4_Init():
3) the MX_SPI5_Init():
4) the HAL_SPI_MspInit()
5) HAL_HAL_SPI_MspDeInit():
6) the HAL_SPI_Transmit() call from the master board on the spi4 block:
7) the HAL_SPI_Receive() call from the slave board on the spi5 block:
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
2022-02-14 03:18 AM
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
2022-02-14 05:06 AM
> 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.
2022-02-14 05:07 AM
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
2022-02-14 05:36 AM
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?
2022-02-14 06:00 AM
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...
2022-02-14 06:39 AM
hi,
thank you - I've added a semaphore but still HAL_SPI_Transmit() is sent successfully while HAL_SPI_Receive() returns HEL_ERROR.
2022-02-14 11:00 PM
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?
2022-02-15 12:53 AM
I dont mean examples with RTOS and your config exist. Try use two boards or as i write HAL_SPI_ReceiveIT()