Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with W25Q80DVUXIE TR using ESP32 #235

Open
AdamMarciniak opened this issue May 25, 2022 · 1 comment
Open

Not working with W25Q80DVUXIE TR using ESP32 #235

AdamMarciniak opened this issue May 25, 2022 · 1 comment
Assignees
Labels
possible bug Possibly a bug. Needs verification before moving to *bug* status.

Comments

@AdamMarciniak
Copy link

AdamMarciniak commented May 25, 2022

I'm using the ESP32's HSPI ports for communication. When I run the example test code, the device isn't found and the JEDEC ID just shows up as zeros.

I know my wiring is correct and all since I am able to manually send SPI commands to the chip and have it correctly send back the JEDEC ID like so:

Any ideas?

#include <SPI.h>
#define JEDECID  0x9F
#define WB_READ_STATUS_REG_1  0x05

static const int spiClk = 1000000; // 1 MHz

SPIClass SPI1(HSPI);

void setup() {
  Serial.begin(115200);
  SPI1.begin();
  SPI1.setDataMode(0);
  SPI1.setBitOrder(MSBFIRST);
  pinMode(15, OUTPUT); //HSPI SS
}

// the loop function runs over and over again until power down or reset
void loop() {
  byte b1, b2, b3;
  char buf[128];
  digitalWrite(15, HIGH);
  digitalWrite(15, LOW);
  SPI1.transfer(JEDECID);
  b1 = SPI1.transfer(0); // manufacturer id
  b2 = SPI1.transfer(0); // memory type
  b3 = SPI1.transfer(0); // capacity
  digitalWrite(15, HIGH);
  digitalWrite(15, HIGH);  
  digitalWrite(15, LOW);
  SPI1.transfer(WB_READ_STATUS_REG_1);       
  while (SPI1.transfer(0) & 1) {}; 
  digitalWrite(15, HIGH);  
  sprintf(buf, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3);
  Serial.println(buf);
  Serial.println("Ready");

  delay(1000);
}
@AdamMarciniak AdamMarciniak added the possible bug Possibly a bug. Needs verification before moving to *bug* status. label May 25, 2022
@AdamMarciniak
Copy link
Author

Here's the culprit:

SPIFlash::SPIFlash(uint8_t cs, SPIClass *spiinterface) {
  _spi = spiinterface;  //Sets SPI interface - if no user selection is made, this defaults to SPI
  if (_spi == &SPI) {
    _SPIInUse = STDSPI;
 }
  else {
    _SPIInUse = ALTSPI;
  }
  csPin = cs;
  pinMode(csPin, OUTPUT);
  CHIP_DESELECT
}

When using HSPI, it causes _SPIInUse to be ALTSPI.
When I modify the code to use STDSPI, it works!

I'm not sure what the difference is much or how best to modify this but there it is :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Possibly a bug. Needs verification before moving to *bug* status.
Projects
None yet
Development

No branches or pull requests

2 participants