cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412kb does not set RXNE bit in register interfacing with W5500

TSche.8
Associate

Hi all, for some reason I have massive trouble making an SPI write function for a w5500 chip. I followed various threads to make this code which I also did for the solution of my problem. Sadly it hasnt helped yet. Thats why I am making my own post now.

Firstly I have configured the SPI1 interface via the mx editor like so:

 

static void MX_SPI1_Init(void)
{

  /* USER CODE BEGIN SPI1_Init 0 */

  /* USER CODE END SPI1_Init 0 */

  /* USER CODE BEGIN SPI1_Init 1 */

  /* USER CODE END SPI1_Init 1 */
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI1_Init 2 */

  /* USER CODE END SPI1_Init 2 */

}

 

 

The readwrite funciton I made is:

 

uint8_t SPIReadWrite(uint8_t data)
{
	SPI1->CR2 |= SPI_CR2_FRXTH;
	while((SPI1->SR&SPI_FLAG_TXE)==0);   //??????
	SPI1->DR=data;

	while((SPI1->SR&SPI_FLAG_RXNE)==0); //???????byte
	uint8_t x = SPI1->DR;
	printf("value x %d", x);

	return 0;
}

 

The code reliably gets stuck on line 7. Also, the TXE registervalue always stays one. 

I connected the lines on my stm32 as follows to the w5500:
MISO -> SDC

MOSI -> SDI

SCK -> SDCK

Yet nothing is working, I never get out of the while loop and I never receive anything. Is there someone who could help me with this?

 

0 REPLIES 0