Example of how to read QSPI NOR Flash Device ID

Hi, can someone provide an example of reading the device ID from an QSPI flash (NOR)?

I'm trying to get it using my NRF52840 using the nrf sdk17.1 with the flash IC AT25FF081A but not getting correct values, just zeros.

For the AT25FF081A, the read device id cmd is 0x90 and we need to send the cmd byte first on the SI pin, then 3 dummy address bytes on the SI pin then receive the 2 data bytes on the SO pin.

Here is my code:

#define CMD_READ_MANUFACTURER_DEVICE_ID  0x90 // spi mode (not quad)
void read_device_id(void)
{
    uint8_t manufacturer_id, device_id;
    nrfx_err_t err_code;

    // Prepare command
    uint8_t command = CMD_READ_MANUFACTURER_DEVICE_ID;

    // Initialize QSPI peripheral
    uint8_t dummy_addr_bytes[4] = {0};
    uint8_t read_bytes[4] = {0};
    // Configure QSPI command
    nrf_qspi_cinstr_conf_t cinstr_cfg = {
        .opcode    = CMD_READ_MANUFACTURER_DEVICE_ID,
        .length    = sizeof(dummy_addr_bytes),
        .io2_level = true,
        .io3_level = true,
        .wipwait   = true,
        .wren      = false
    };
    


    // Send command with dummy bytes
    err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, &dummy_addr_bytes, read_bytes);

    
    // Output results
    if(NRFX_SUCCESS != err_code)
    {
        NRF_LOG_ERROR("nrfx_qspi_cinstr_xfer err: %d\n", err_code);
    }

    NRF_LOG_ERROR("Manufacturer ID: 0x%X\n", read_bytes[0]);
    NRF_LOG_ERROR("Device ID: 0x%X\n", read_bytes[1]);
    NRF_LOG_ERROR("last: 0x%X\n", read_bytes[2]);
}

Here is our qspi config

rfx_qspi_config_t nrfx_qspi_config = {                                                                       
        .xip_offset  = NRFX_QSPI_CONFIG_XIP_OFFSET,                         
        .pins = {                                                           
            .sck_pin     = 7,//16,                                
            .csn_pin     = 34,//15,                                
            .io0_pin     = 8, //14,   mosi                            
            .io1_pin     = 6, //29,   miso                           
            .io2_pin     = 10, //22,                                
            .io3_pin     = 9, //23,                                
        },                                                                  
        .prot_if = {                                                        
            .readoc     = (nrf_qspi_readoc_t)  NRFX_QSPI_CONFIG_READOC,       
            .writeoc    = (nrf_qspi_writeoc_t) NRFX_QSPI_CONFIG_WRITEOC,     
            .addrmode   = (nrf_qspi_addrmode_t)NRFX_QSPI_CONFIG_ADDRMODE,   
            .dpmconfig  = false,                                            
        },                                                                  
        .phy_if = {                                                         
            .sck_delay  = (uint8_t)NRFX_QSPI_CONFIG_SCK_DELAY,              
            .dpmen      = false,                                            
            .spi_mode   = (nrf_qspi_spi_mode_t)NRFX_QSPI_CONFIG_MODE,       
            .sck_freq   = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY, 
        },                                                                  
        .irq_priority   = (uint8_t)NRFX_QSPI_CONFIG_IRQ_PRIORITY
    };

Related