cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151CBT6 as slave with startup and operational phase

Chrizzly
Associate III

Setup:

  • Master: PLD, SPI Frequency 4MHz
  • Slave: STM32L151CBT6, SysClk 32MHz
  • Using HAL
  • Configured SPI to use DMA

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.

2 REPLIES 2
TDK
Guru

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.

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

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?