This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Having issue to read manufacturer ID from SPI flash memory

Hello Nordic Team

I am working on SDK v-17.0.2 SPI example to interface with external flash memory. I have Winbond W25Q128FV and Fudan FM25Q08 flash memory but have same issue to read manufacturer ID. I am getting 0x00 in response.

I attached test code below:

/**
 * @brief SPI user event handler.
 * @param event
 */
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    spi_xfer_done = true;
    NRF_LOG_INFO("Transfer completed.");
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(" Received:");
        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}

int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.mode = NRF_DRV_SPI_MODE_3;
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

    NRF_LOG_INFO("SPI example started.");

    while (1)
    {
        m_tx_buf[0] = 0x90;
        m_tx_buf[1] - 0x00;
        m_tx_buf[2] = 0x00;
        m_tx_buf[3] = 0x00;

        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;

        APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 4, m_rx_buf, 6));

        while (!spi_xfer_done)
        {
            __WFE();
        }

        NRF_LOG_FLUSH();

        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(200);
    }
}

I am stuck here and trying since 2 days but no luck. Any help or right direction on this will be great.

Thanks and Regards

Raj

Parents
  • SPI is a synchronous protocol where the slave (flash memory in this case) doesn't know what to reply with until it has completely received a command byte. m_rx_buf[0] is returned while m_tx_buf[0] ie the command byte 0x90 is being synchronously clocked out and before the flash has decoded the action required, therefore the first received byte from the flash slave with any meaning is actually in m_rx_buf[1], So:

    Change
        if (m_rx_buf[0] != 0)
    to
        if (m_rx_buf[1] != 0)

Reply
  • SPI is a synchronous protocol where the slave (flash memory in this case) doesn't know what to reply with until it has completely received a command byte. m_rx_buf[0] is returned while m_tx_buf[0] ie the command byte 0x90 is being synchronously clocked out and before the flash has decoded the action required, therefore the first received byte from the flash slave with any meaning is actually in m_rx_buf[1], So:

    Change
        if (m_rx_buf[0] != 0)
    to
        if (m_rx_buf[1] != 0)

Children
Related