2023-09-13 03:52 PM
Seeing issue while brining-up Winbond W25X20L FLASH with STM32, Write and read a byte in a loop does not work.
Tried to see the signal's using the scope and seems like clock has some issue, appreciate any help. Please let mw know if more information is needed here.
CubeMx Settings and code I am using is provided below
STM32CubeMX Settings for SPI1 after going through blog post like this Getting Started with STM32 - How to Use SPI (digikey.com)
Basically updated.
1. data_size from 4 to 8, 2. baud_rate to 1.5Mbps using 64 as Prescaler, 3. Disabled NSSP Mode
Here is the Code i am using to read/write a byte in a loop
static void MX_SPI1_Init(void) {
/* 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_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 0x0;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK) {
Error_Handler();
}
}
Solved! Go to Solution.
2023-09-28 10:30 AM
Finally, it is working for me, tried to put up reference and instructions in the attached .pdf file.
2023-09-15 02:10 PM
Simplified the program to just read the Manufacturer ID instead of write/read using 0x92 command
Code to Read the ID
while(1) {
HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_RESET); // CS LOW
// Write command 0x92 followed by 3 zeros
masterToSlave = HAL_SPI_Transmit(&hspi1, (uint8_t *)&EEPROM_MRID, 1, 100);
masterToSlave = HAL_SPI_Transmit(&hspi1, (uint8_t *)&zero, 1, 100);
masterToSlave = HAL_SPI_Transmit(&hspi1, (uint8_t *)&zero, 1, 100);
masterToSlave = HAL_SPI_Transmit(&hspi1, (uint8_t *)&zero, 1, 100);
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) // wait for HAL Active
// read ID
slaveToMaster = HAL_SPI_Receive(&hspi1, (uint8_t *)&manufactureID, 1, 100);
slaveToMaster = HAL_SPI_Receive(&hspi1, (uint8_t *)&deviceId, 1, 100);
HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_SET); // CS HIGH
printf("mID: 0x%x %x\r\n",manufactureID, deviceId); // print ids
HAL_Delay(10);
}
0x64 and 0xF0 is read back as manufactureID and deviceID
Here is what I see on the Scope.
Please let me know if there is anything, I am missing.
2023-09-15 03:33 PM
Use the HAL_SPI_TransmitReceive(), Identify traces, don't be using DUAL mode for single bit SPI, would explain the wrong levels on the Purple trace as both ST and WINBOND are trying to drive the same pin.
Use the 0x9F command (JEDEC ID). send 0x9F, then recover responses to sending 3 zeros.
Bus is symmetrical, the write clocks, data goes out on one edge, read back on the other.
2023-09-16 11:18 AM
Thanks! I tried
Still having issue reading back Status Register and Write/Read command, really appreciate the response, here is the code I am using
2023-09-16 11:43 AM
I would make sure the SPI register has been sent before raising SPI1_CS
I would raise SPI1_CS after sending WREN command is sent. With some delay between it going high before going low again.
Print the two SR1 / SR2 values with separation or %02X %02X forms. When writing check for completion. WREN bit should reflect in SR1.WEL
2023-09-16 12:20 PM
I will update it as below and try it on Monday, Hope this will work,
Please let me know if you see some issue here
2023-09-16 12:39 PM
I would suggest using subroutines. Pass and decompose the address into the command bytes buffer.
You should spin after the WRITE (0x02) command, reading SR1 until SR1.BUSY goes back to zero, then do the READ (0x03).
2023-09-28 10:30 AM