2020-09-01 05:29 AM
Hello Team,
I want to use STM32L432KC with W25Q16. I have generated the code through CubeMx.
I have tried to ready ID from W25Q16, and I getting 0xFF.
When i have tried with the Arduino UNO board, it is working perfectly.
/* 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 = 10;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/ /main code
void manufacturerID(void)
{
uint8_t ID[4];
int i=0;
uint8_t cmd[4] = {READ_ID_CMD,0x00,0x00,0x00};
HAL_GPIO_WritePin(SPI_SEL2_GPIO_Port,SPI_SEL2_Pin,0);
HAL_SPI_TransmitReceive(&_W25QXX_SPI,&cmd[0],&ID[0],4,10);
HAL_GPIO_WritePin(SPI_SEL2_GPIO_Port,SPI_SEL2_Pin,1);
if((ID[0] != 0xEF) | (ID[1] != 0x17))
{
Error_Handler();
}
else
{
printf("W25Qxxx ID is : ");
for(i=0;i<2;i++)
{
printf("0x%02X ",ID[i]);
}
printf("\r\n\r\n");
}
}
Please suggest me if any changes is required.