2021-11-22 04:24 AM
Setup:
What I want: Start-Up Phase and Operational Phase for the slave device
Start-Up Phase:
1) The PLD waits untill the uC complete its start up phase and constantly sends Bytes of 0x09 indicating a waiting status
2) When the uC is ready it is supposed to send one byte as respone with 0x01 indicating that is now ready to receive a 32Byte long configuration message from the PLD
3) The PLD shuts down the clk signal waits like 500us
4) The PLD brings the clk high and sends the 32 Byte long message
5) The PLD shuts down the clk signal after transmission and waits a short time period of 500us
6) The PLD brings the clk high and starts sending continously Bytes of 0x09 indicating a waiting status
7) The uC respons whenever it is ready with a 0x02 indicating that it is now ready for the operational phase
Operational Phase:
1) A continous cycle where a transmission occurs every 700us of 64 Bytes between the uC and the slave (TransmitReceive)
I ask myself how I can implement this behaviour with HAL? I also need CRC?
My 1st take on this was to do something like this during the start up phase:
while(x != 0x09){
HAL_SPI_Receive(x,1,1)
}
x = 0x00
HAL_SPI_Transmit(0x01,1,1)
HAL_SPI_Receive_DMA(ConfigurationParameter, 32)
.. Do Configuration ...
while(x !=0x09){
HAL_SPI_Receive(x,1,1)
}
HAL_SPI_Transmit(0x02,1,1)
Then go over to an operational phase where 64 Bytes are exchanged every 700us.
I just can't wrap my head around it receiving propper values with hal in this scenario. Do I need different SPI setups?
Edit: I am also not sure how I can change to DMA circular with when my application goes into the operational phase.
2021-11-22 06:50 AM
The pseudocode you wrote should work okay for what you want. May need larger timeouts. Make sure you wait for DMA to complete before doing another SPI operation.
2021-11-22 08:22 AM
Okay thank you TDK. I will try it with a delay.
Do you know how to change to circular dma? Can I just set the Circular Mode bit in the DMA_CCRx Register?