cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Cs periodically while using Dma

Squidward
Associate II

Good Day

I am using Spi with Dma. When using the Hal-function "HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)", I want to receive 1000 times Data , which I can set in the size-area. The Problem is that my Spi-peripheral needs constantly Cs-pin to get set and reset to give out Data, else i receive after one usable data just zeros. My question is following: Is there a way to tell the Spi to set and reset the cs when data gets received, and if so, how, or where can this be configured? I am currently using the function in a for loop to receive my Data with the size set to 1. But this is way to slow. Thanks for Helping.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Squidward
Associate II

So I could solve the Problem. It is simple as that. I am using the NSSP mode wit 2 cycles in Master Inter Data Idleness

View solution in original post

6 REPLIES 6
TDK
Guru

The typical way is to handle CS as a GPIO pin, set it low prior to starting the call and set it high in the RxComplete callback. Or if you're using blocking functions, immediately after HAL_SPI_Receive.

Some series like the STM32H7 have the capability to do this natively.

Why do 1000x loops of 1 byte instead of a single call with 1000 bytes?

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

First of all, thank you TDK,

The Problem is that I have to redo the function in a for, or while loop is that my SPI-Peripheral needs for every data to be send a CS high and low, or else the ADC does not get the information for giving out data. Thats why I want to find out if threr is a way to set CS high and low every time a value gets transmitted, when getting 1000 Bytes by calling this function only once.

 

still no info, what cpu you use ...

ie on H563 u could use TI mode : (if this is, what you want)

AScha3_0-1697446359637.png

SS = CS output

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

What is the problem with setting CS low before HAL_SPI_Receive and high afterwards? I don't see how being in a loop is relevant here. Surely controlling a CS pin works as well inside of a loop as it does outside.

 

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

Hi, the Problem is that when I set Cs high and low that only one data is transmitted because the Peripheral is build so. Thats the reason i am asking if there exist a way to configure the stm32h723zg in that way, that if a value gets received the cs gets automatically gets set high and low, so the ADC can give out the next value. If I set the CS low than expect lets say 1000 values and set cs high again, I only get one value and 999 times zeros. So thats why I am using the receive-function in a while loop to receive enough values. So is there a way to set cs automatically while this function is ongoing? Thanks in regards

 

Squidward
Associate II

So I could solve the Problem. It is simple as that. I am using the NSSP mode wit 2 cycles in Master Inter Data Idleness