uint8_t QSPI_Configuration(void) {
QSPI_CommandTypeDef sCommand = { 0 };
uint8_t sr1 = 0x00; // Status Register 1
uint8_t sr2 = 0x00; // Status Register 2
HAL_StatusTypeDef ret;
// Read Status Register 1 and Status Register 2 (SR1 and SR2)
sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction = READ_STATUS_REG1_CMD; // Read SR1
sCommand.AddressMode = QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode = QSPI_DATA_1_LINE;
sCommand.DummyCycles = 0;
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE;
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData = 1;
// Read SR1
if ((ret = HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
if ((ret = HAL_QSPI_Receive(&hqspi, &sr1, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
// Read SR2
sCommand.Instruction = READ_STATUS_REG2_CMD; // Read SR2
if ((ret = HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
if ((ret = HAL_QSPI_Receive(&hqspi, &sr2, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
// Enable Volatile Write operations (for both SR1 and SR2)
sCommand.DataMode = QSPI_DATA_NONE;
sCommand.Instruction = VOLATILE_SR_WRITE_ENABLE;
if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return ret;
}
// Set the QE bit in SR2 (bit 1) and write to SR2
sr2 |= 0x02; // Set QE bit in SR2
sCommand.DataMode = QSPI_DATA_1_LINE;
sCommand.Instruction = WRITE_STATUS_REG2_CMD; // Write SR2
sCommand.NbData = 1; // Write 1 byte (SR2)
if ((ret = HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
if ((ret = HAL_QSPI_Transmit(&hqspi, &sr2, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
// Write to SR1 (you can modify SR1 as needed)
sCommand.Instruction = WRITE_STATUS_REG1_CMD; // Write SR1
if ((ret = HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
if ((ret = HAL_QSPI_Transmit(&hqspi, &sr1, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
HAL_Delay(1); // Small delay for stability
/* Step 4: Read Status Register 3 */
uint8_t sr3;
sCommand.Instruction = READ_STATUS_REG3_CMD;
sCommand.NbData = 1;
if ((ret = HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
if ((ret = HAL_QSPI_Receive(&hqspi, &sr3, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)) != HAL_OK) {
return ret;
}
/* Step 5: Modify SR3 (DRV1:2 = 00) */
sr3 &= 0x9F; // Clear DRV1:2 bits
sCommand.Instruction = WRITE_STATUS_REG3_CMD;
if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return ret;
}
if (HAL_QSPI_Transmit(&hqspi, &sr3, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return ret;
}
HAL_Delay(1); // Ensure register write stability
return HAL_OK;
}
As per the your instruction i have changed the code to read both the SR1 and SR2 and still it doesnt work I have attached the code above for your reference also the schematic connection attached along with this reply, Kindly refer those and assist me in solving this communication issue also provide detailed information about the SR1 and SR2 reading for this W25Q16J.