cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-h563zi board spi2 not working

Hueiyi
Associate II

I am currently using the NUCLEO-H563ZI board to test SPI functionality.

I configured SPI1 as a master and was able to successfully transmit and receive data using HAL_SPI_TransmitReceive(). However, when I switched to SPI2, I found that the clock signal does not toggle at all, no matter what I try.

Is there anything specific that needs to be configured additionally for SPI2?

image.png

 

Below is my code; the rest was automatically generated by MX.

uint8_t spi_TransmitReceive(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin,
		const uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
{
	HAL_StatusTypeDef status;
	HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET);
	status = HAL_SPI_TransmitReceive(&hspi2, pTxData, pRxData, Size, Timeout);
	HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET);

	return status;
}

void example_spi_transmitreceive()
{
	printf("\r\nExample SPI Transmit and Receive.\r\n");
	uint8_t txbuf[1024];
	uint8_t rxbuf[1024] = {0};

	for(int i = 0; i < 1024; i++) {
		txbuf[i] = i & 0xff;
	}

	spi_TransmitReceive(GPIOB, GPIO_PIN_6, &txbuf, &rxbuf, 1024, 10);

	printf("\r\nRx Received data:\r\n");
	for(int i = 0; i < 1024; i++) {
		printf("0x%02x, ", rxbuf[i]);
		if ((i+1) % 16 == 0) {
			printf("\r\n");
		}
	}
}

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Do functions return HAL_OK? If so, probably the pin you are monitoring is not connected to the clock where you’re measuring. Check the board schematic.

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

View solution in original post

4 REPLIES 4
TDK
Super User

Do functions return HAL_OK? If so, probably the pin you are monitoring is not connected to the clock where you’re measuring. Check the board schematic.

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

It does return HAL_OK.

I am using PA12 as the SPI2 clock pin, and I am confident that I connected to the correct pin since the board silkscreen clearly labels it as PA12.

Below are the pins I am using:
PC2   ------> SPI2_MISO
PC3   ------> SPI2_MOSI
PA12 ------> SPI2_SCK
PB6  ------>  SS

TDK
Super User

PA12 is not connected to the headers by default. You need to close some solder bridges. It is connected to USB. See the user manual or the schematic.

If it returns HAL_OK, the clock is working.

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

Hi TDK,

Thank you very much for your help. I had never considered that an EVB might have DNF pin headers.

I really appreciate your patience in explaining this to a beginner like me. Thanks again!