Created
May 20, 2020 13:06
-
-
Save DurandA/2992dad09b395cfa4491526bf7395ba2 to your computer and use it in GitHub Desktop.
Enable Quad I/O mode on Macronix MX25xxxx35 series serial flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "string.h" | |
#include "driver/spi_master.h" | |
#define PIN_NUM_MISO 19 | |
#define PIN_NUM_MOSI 23 | |
#define PIN_NUM_CLK 18 | |
#define PIN_NUM_CS 12 | |
spi_device_handle_t spi; | |
void app_main(void) | |
{ | |
esp_err_t ret; | |
static spi_bus_config_t buscfg={ | |
.mosi_io_num=PIN_NUM_MOSI, | |
.miso_io_num=PIN_NUM_MISO, | |
.sclk_io_num=PIN_NUM_CLK, | |
.quadwp_io_num=-1, | |
.quadhd_io_num=-1, | |
}; | |
ret=spi_bus_initialize(VSPI_HOST, &buscfg, 1); | |
ESP_ERROR_CHECK(ret); | |
static spi_device_interface_config_t devcfg={}; | |
devcfg.mode=0; | |
devcfg.clock_speed_hz=1000*1000; | |
devcfg.spics_io_num=12; | |
devcfg.queue_size=2; | |
devcfg.command_bits=8; | |
ret=spi_bus_add_device(VSPI_HOST, &devcfg, &spi); | |
ESP_ERROR_CHECK(ret); | |
spi_transaction_t wren; | |
memset(&wren, 0, sizeof(wren)); | |
wren.cmd = 0x06; | |
ret=spi_device_polling_transmit(spi, &wren); | |
ESP_ERROR_CHECK(ret); | |
spi_transaction_t rdsr; | |
memset(&rdsr, 0, sizeof(rdsr)); | |
rdsr.flags = SPI_TRANS_USE_RXDATA; | |
rdsr.length = 8; | |
rdsr.cmd = 0x05; | |
ret=spi_device_polling_transmit(spi, &rdsr); | |
ESP_ERROR_CHECK(ret); | |
printf("SR: 0x%02X\n", rdsr.rx_data[0]); | |
spi_transaction_t wrsr; | |
memset(&wrsr, 0, sizeof(wrsr)); | |
wrsr.flags = SPI_TRANS_USE_TXDATA; | |
wrsr.length = 8; | |
wrsr.cmd = 0x01; | |
wrsr.tx_data[0] = 0x40; | |
wrsr.tx_data[1] = 0; | |
ret=spi_device_polling_transmit(spi, &wrsr); | |
ESP_ERROR_CHECK(ret); | |
ret=spi_device_polling_transmit(spi, &rdsr); | |
ESP_ERROR_CHECK(ret); | |
printf("SR: 0x%02X\n", rdsr.rx_data[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment