QSPI wrong data

tatulea
Posts: 18
Joined: Wed Feb 06, 2019 12:39 pm

QSPI wrong data

Postby tatulea » Wed Feb 20, 2019 11:45 am

I am using an ESP32-Wrover-Kit. I am trying to read a flash memory on QSPI. The problem is that the returned data is wrong sometimes. I am expecting to get numbers from 0 to 19, but I am getting even a lot of 255 values.

Code: Select all


#define MISO_PIN 12
#define MOSI_PIN 13
#define SCLK_PIN 14
#define CS_PIN   15
#define WP_PIN   2
#define HD_PIN   4

void app_main()
{
    esp_err_t ret;

    spi_bus_config_t spi_bus_cfg = {
        .mosi_io_num=MOSI_PIN,
        .miso_io_num=MISO_PIN,
        .sclk_io_num=SCLK_PIN,
        .quadwp_io_num=WP_PIN,
        .quadhd_io_num=HD_PIN,
        .max_transfer_sz=SPI_MAX_TRANSFER_SIZE,
        .flags=SPICOMMON_BUSFLAG_NATIVE_PINS
    };

    spi_device_interface_config_t spi_device_cfg = {
        .command_bits=8,
        .mode=0,
        .clock_speed_hz=1000000,
        .spics_io_num=CS_PIN,
        .queue_size=1,
        .flags=SPI_DEVICE_HALFDUPLEX
    };

    ret = spi_bus_initialize(HSPI_HOST, &spi_bus_cfg, 1);
    ESP_ERROR_CHECK(ret);

    ret = spi_bus_add_device(HSPI_HOST, &spi_device_cfg, &spi);
    ESP_ERROR_CHECK(ret);

    spi_transaction_ext_t t_ext = {
        .base = {
            .cmd = 0x6B,
            .addr = 0x000000,
            .length = 0,
            .rxlength = 20*8,
            .rx_buffer=yy,
            .flags = SPI_TRANS_VARIABLE_ADDR | SPI_TRANS_MODE_QIO
        },
        .command_bits = 8,
        .address_bits = 24
    };

    ret = spi_device_transmit(spi, &t_ext);
    for(int i = 0; i < 20; i++)
    {
        printf("%d\r\n", yy[i]);
    }
}
### Expected Behavior
0
1
2
...
19

### Actual Behavior
0
1
2
0
4
5
0
3
255
255
255
255
255
255
255
255
255
255
255
255

I was trying before with those pin configurations:

Code: Select all

#define MISO_PIN 25
#define MOSI_PIN 23
#define SCLK_PIN 19
#define CS_PIN   22
#define WP_PIN   2
#define HD_PIN   4
and it was working a little bit better, but I also got some wrong values. With the second pin configurations (which is not native SPI pins) I get the good answer if I am using SPI_TRANS_MODE_DIO instead of SPI_TRANS_MODE_QIO.

What should I do?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: QSPI wrong data

Postby ESP_Sprite » Thu Feb 21, 2019 9:02 am

What flash chip are you trying to interface with?

Who is online

Users browsing this forum: Bing [Bot] and 158 guests