cancel
Showing results for 
Search instead for 
Did you mean: 

How to establish communication between 93LC66B and NUCLEO-G474RE ?

TJeru.1
Associate

According to 93LC66 communication the 93LC66B variant is a rotated variant. How to establish communication between NUCLEO-G474RE and this EEPROM using SPI ? I've tried many approaches but none worked, always get 0 from EEPROM but it should be FF, I think. Is there need to add delays or change Nucleo clock ? I set prescaler to 256 but still no communication. I bring CS line hig when want to communicate with EEPROM and low when done but I always read 0.

Here's the code (while loop and SPI settings generated by STM32CubeIDE:

  /* USER CODE BEGIN WHILE */
  while (1)
  {
	high_byte = 0b00001100;
	low_byte = 0;
	printf("Instruction sent: %d\n", high_byte);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
	HAL_SPI_Transmit(&hspi2, (uint8_t*)&high_byte, 1, HAL_MAX_DELAY);
	HAL_SPI_Transmit(&hspi2, (uint8_t*)&low_byte, 1, HAL_MAX_DELAY);
 
	uint8_t received_byte = 1;
	//if (HAL_SPI_DeInit(&hspi2) != HAL_OK)
	//{
	//	printf("SPI CLKPOL change failed\n");
//	}
	//hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
	//if(HAL_SPI_Init(&hspi2) != HAL_OK)
//	{
	//	printf("Failed to change CLKPOL\n");
	//}
	//HAL_Delay(16);
	switch(HAL_SPI_Receive(&hspi2, &received_byte, 1, HAL_MAX_DELAY))
	{
		case HAL_OK:
			printf("SPI HAL OK\n");
			break;
		case HAL_ERROR:
			printf("SPI HAL ERROR\n");
			break;
		case HAL_TIMEOUT:
			printf("SPI HAL TIMEOUT\n");
			break;
	}
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
	printf("Received data: 0x%x\n", received_byte);
	//if (HAL_SPI_DeInit(&hspi2) != HAL_OK)
	//{
	//	printf("SPI CLKPOL change failed\n");
	//}
	//hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
	//if(HAL_SPI_Init(&hspi2) != HAL_OK)
	//{
	//	printf("Failed to change CLKPOL\n");
	//}
 
	HAL_Delay(500);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
 
  /* USER CODE END SPI2_Init 1 */
  /* SPI2 parameter configuration*/
  hspi2.Instance = SPI2;
  hspi2.Init.Mode = SPI_MODE_MASTER;
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi2.Init.NSS = SPI_NSS_SOFT;
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi2.Init.CRCPolynomial = 7;
  hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  if (HAL_SPI_Init(&hspi2) != HAL_OK)
  {
    Error_Handler();
  }
1 REPLY 1