cancel
Showing results for 
Search instead for 
Did you mean: 

SPI3 does not function for STM32H753VIT6

TPanc.1
Associate II

Hi there,

Here are the two lines which I am using for SPI communication.

while(HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY);

HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)& ADC_write, (uint8_t *)&ADC_read, 4, 100);

The drier derived from CubeMX is noted below. I have checked the SCK line with an oscilloscope as well. I could not even catch the clock pulses. The SPI source clock is 96 MHz. After prescaling, it reaches to 768kHz. Please help me, as I am not moving ahead with this.

void MX_SPI3_Init(void)

{

 /* USER CODE BEGIN SPI3_Init 0 */

 /* USER CODE END SPI3_Init 0 */

 /* USER CODE BEGIN SPI3_Init 1 */

 /* USER CODE END SPI3_Init 1 */

 hspi3.Instance = SPI3;

 hspi3.Init.Mode = SPI_MODE_MASTER;

 hspi3.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;

 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi3.Init.NSS = SPI_NSS_SOFT;

 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi3.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi3.Init.CRCPolynomial = 0x0;

 hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

 hspi3.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;

 hspi3.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;

 hspi3.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi3.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi3.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;

 hspi3.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;

 hspi3.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;

 hspi3.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;

 hspi3.Init.IOSwap = SPI_IO_SWAP_DISABLE;

 if (HAL_SPI_Init(&hspi3) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN SPI3_Init 2 */

 /* USER CODE END SPI3_Init 2 */

}

3 REPLIES 3
TDK
Guru

>  hspi3.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;

> HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)& ADC_write, (uint8_t *)&ADC_read, 4, 100);

If it's defined as RX only, you can't transmit on it. Most likely you want SPI_DIRECTION_2LINES instead.

> hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

> The SPI source clock is 96 MHz. After prescaling, it reaches to 768kHz.

These don't agree with each other.

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

Yes, you are right. I changed the function to receive only.

while(HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY);

HAL_SPI_Receive(&hspi3, (uint8_t *)&ADC_read, 4, 100);

Also, you are right about the clock. After dividing the 96MHz with only 2, it was running at 48 MHz, and SPI did not work. I tried again and found that the maximum clock rate which can be supported with this SPI is 24 MHz. It means, with this clock rate at least I can detect the clocks on an oscilloscope. Do you have any idea for getting faster SPI even with a 96MHz clock rate?

TDK
Guru

> Do you have any idea for getting faster SPI even with a 96MHz clock rate?

A lower prescaler and/or faster clock will increase the clock rate.

If your scope doesn't have the bandwidth to detect it, that's not really something you can change on the STM32.

The max SPI speeds need to be respected, but they're generally 100+ MHz in master mode.

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