2019-07-28 08:48 PM
I'm using STM32L4A6VGx , MT25QL256 NOR Flash connected with SPI. I'm trying to read the ID but didn't get any response except 0.
Here is the code I wrote:
// Select Pin
HAL_GPIO_WritePin(Select_GPIO_Port, Select_Pin, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(Select_GPIO_Port, Select_Pin, GPIO_PIN_RESET);
Dev_ID[0] = 0x09E;
HAL_SPI_Transmit(&hspi2, Dev_ID, 1,10);
HAL_SPI_Receive(&hspi2, &Dev_ID[1], 1,10);
HAL_GPIO_WritePin(Select_GPIO_Port, Select_Pin, GPIO_PIN_SET);
//SPI Configuration
static void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* 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_4;
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();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}
2019-07-28 09:23 PM
Its giving either 0 for: hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
giving 225 for: hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH; hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;