Skip to main content
NZahr.1
Associate
August 26, 2022
Solved

Why is my GPIO used as NSS toggles randomly during SPI data transfer

  • August 26, 2022
  • 4 replies
  • 3028 views

Hello I'm using SPI to interface my STM32F7 with the SX1262 radio.

I got a weird behavior, I'm using a GPIO to toggle the NSS pin. But sometimes it toggles randomly during the data transfer. You can see on the following screenshot of my logic analyzer:

0693W00000StrykQAB.pngHere's the code for it:

void WriteBuffer(SPI_HandleTypeDef hspiX)
{
	while(HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_13) == 1)
	{
 
	}
 
	uint16_t 	WriteBufferSize = 6;
	uint8_t 	WriteBufferCmd[] = {0x0E, 0x00, 0x33, 0x65, 0x67, 0x67}; // !ACC
	//uint8_t 	WriteBufferAnswer[6];
 
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
	HAL_SPI_Transmit(&hspiX,(uint8_t *)WriteBufferCmd,WriteBufferSize,100);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
 
 
}

Here's the SPI setup:

0693W00000StrxwQAB.png 

This topic has been closed for replies.
Best answer by waclawek.jan

If you have flying wires or a long ribbon cable, this may be result of inadequate ground/return arrangement and/or crostallk.

If this is the case, the remedy is short cables and individual ground/return for each signal. You can try to work around this by increasing the NSS pin's drive by its GPIO_OSPEEDR setting, and decrease other pins' drive.

LA may not be the most adequate tool for this kind of problems.

JW

4 replies

waclawek.jan
waclawek.janBest answer
Super User
August 26, 2022

If you have flying wires or a long ribbon cable, this may be result of inadequate ground/return arrangement and/or crostallk.

If this is the case, the remedy is short cables and individual ground/return for each signal. You can try to work around this by increasing the NSS pin's drive by its GPIO_OSPEEDR setting, and decrease other pins' drive.

LA may not be the most adequate tool for this kind of problems.

JW

NZ.2
Visitor II
August 28, 2022

It was a wiring problem after all!

Thank you for the help

Michal Dudka
Lead
August 27, 2022

Measure NSS pin by oscilloscope.

S.Ma
Principal
August 27, 2022

I suspect other code write other pin of same port, or memory pointer wrong writing. Try the debug watchpoint on the gpio out and bssr or moder register.

Tesla DeLorean
Guru
August 27, 2022

HAL_SPI_Transmit() is supposed to make sure the transmit completes, ie Tx FIFO empty, not busy, RX FIFO empty.

Not sure why this pin would glitch,would have to be a direct connection with something else or some other code. Anything in an interrupt or callback?

Any error or status returned by the commands?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..