cancel
Showing results for 
Search instead for 
Did you mean: 

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

NZahr.1
Associate

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 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5

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

Measure NSS pin by oscilloscope.

S.Ma
Principal

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.

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

It was a wiring problem after all!

Thank you for the help