SPIM nrf_drv_spi_transfer() with W25N01GVZEIR SPI Flash Memory

My setup is based on the SPI example program included in the nrfSDK nRF5_SDK_17.1.0_ddde560\examples\peripheral\spi\main.c
I've set up my SPI instance and am sending commands over to the Winbond flash memory.
However, I am only receiving 0x00 when I should be receiving the chip ID.
I've set the transfer and receive length to 5 as per this post:  SPIM nrf_drv_spi_transfer() usage
Since the command is 2 bytes long and I need to receive 3 bytes following.
You can see details of the SPI command on page 28 of the datasheet: https://www.winbond.com/resource-files/W25N01GV%20Rev%20O%20092619.pdf
I am wondering if I have set it up incorrectly or am not properly using the spi transfer function. 
static const nrf_drv_spi_t spi1 = NRF_DRV_SPI_INSTANCE(1);

static uint8_t cmd[5];
static uint8_t mfg_id[5];

void w25n01gv_init(void)
{
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SD_SPI_SS_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    //spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    nrf_drv_spi_init(&spi1, &spi_config, spi_event_handler, NULL);
    NRF_LOG_INFO("SPI Initialized");
}

 
void w25n01gv_read_mfg_id(void)
{
    cmd[0] = 0x9F;
    cmd[1]=0x00; //dummy bit
    spi_xfer_done = false;
    nrf_drv_spi_transfer(&spi1, cmd, 5, mfg_id, 5);
    while(spi_xfer_done){
    }
    NRF_LOG_INFO("Manufacturer ID: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", mfg_id[0], mfg_id[1], mfg_id[2], mfg_id[3], mfg_id[4]);
    NRF_LOG_FLUSH();
}
 

int main(void)
{
    log_init();

    w25n01gv_init();
    w25n01gv_read_mfg_id();
    while(1) {}
}
Parents Reply Children
  • Here's the SPI lines, they're all as I would expect. Would the issue be that I am not printing to the debugger or receiving the data properly using nrf_drv_spi_transfer?

  • Hi ,

    Thanks, for the trace. It clearly shows that the data is sent correctly from the flash so the output from the SPI master should be ok as well. 

    Caleb said:
    Would the issue be that I am not printing to the debugger or receiving the data properly using nrf_drv_spi_transfer?

    I don't think that is the issue, you should be able to use the logger module but maybe there is a problem with how you format the data. Could you set a breakpoint right where you print the data, start the debugger, and set the mfg_id array as watch in debug mode and see if it contains the manufacture and device id? If yes, then we know that the problem is how the data is formatted before you print it out.

    regards

    Jared 

  • I am able to get the data in the debugger when using a W25N01GV chip from the same manufacturers the W25N01KV does not show data on the nrf device, only on the logic analyzer.

Related