cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 chip select problem

plate30
Associate II

Hello,

I am having problems with SPI connectivity. My problem seems to be the chip select pin that is controlled using GPIO HAL libraries. Chip select is pulled low for way longer than it is supposed to and therefore I cannot read the sent data properly.

I am aware of the available NSS function, however I cannot use it in my case. The chip select control must be done using GPIO toggling.

Would it be possible in any way to shorten the active time of chip select pin so it would be much more synchronized with the beggining and end of SPI transmission? In other words, can I come closer to the speed that would be provided by NSS pin?

I have attached a photo from my logic analyzer view. My board is NUCLEO-F401RE.0693W00000KbZKKQA3.png 

This is code for sending data via SPI:

void send_data(uint8_t *address)

{

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); // Pull chip select low

HAL_SPI_Transmit(&hspi3, address, 1, 5);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET); // Pull chip select high

}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Slow down clock speed by an order of magnitude and try again. You may be missing clock edges.

Looks like you have a lot of noise on the lines. Shorten lead lengths. What does your setup look like?

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

View solution in original post

6 REPLIES 6
MM..1
Chief II

You missconfigure something, signals on image is little chaos , no real clock,

And send over SPI one byte data isnt very eff...

As first for short try use GPIOD->BSRR and check speed init on this GPIO.

Thank you for your answer.

I have changed the data sent to be longer (10 bytes). I have also changed the code to your suggestion. Do you mean this:

void send_data(uint8_t *address)

{

GPIOD->BSRR |= (1<<18); // Pull chip select low

HAL_SPI_Transmit(&hspi3, address, 10, 5);

GPIOD->BSRR |= (1<<2); // Pull chip select high

}

If so, the signal I am seeing is still wrong:

0693W00000KbZawQAF.pngIn CubeMX, the CS GPIO maximum output speed is set to "Very high".

MM..1
Chief II

You misconfigure analyser , and HAL_SPI_Transmit ofcourse have some init instruction time.

You cant start over HAL quickly, but your words  therefore I cannot read the sent data seems you dont understand how SPI work...

I shall look into it deeper. Thank you again.

TDK
Guru

Slow down clock speed by an order of magnitude and try again. You may be missing clock edges.

Looks like you have a lot of noise on the lines. Shorten lead lengths. What does your setup look like?

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

Slowing down the clock have fixed my problems. Seems like the wires, that are connected to analyzer, are too long, just like you said. Thank you for your help!