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

Wrong status read from device and subsequent pageRead failure #14

Open
rogierschouten opened this issue Apr 19, 2014 · 3 comments
Open
Assignees
Labels

Comments

@rogierschouten
Copy link

I'm using a Teensy 3.1 and a AT45DB161D. For some reason, the very first status code read from the chip always returns 0. This causes the dataflash library to misinitialize its member variables and subsequently, most functions don't work as expected. I've narrowed it down to the SPI mode: with SPI mode 0, it works. With SPI mode 3, the first status code is 0 and subsequent status codes are good.

Therefore two suggestions for dataflash:

  1. maybe change to SPI mode 0
  2. prevent buffer overrun in Dataflash::setup() due to deviceIndex out-of-range (e.g. choose a default chip type)

Below is a small example program to reproduce (only shows the first status code):

include <SPI.h>

define MY_SCS 10

uint8_t st;

void setup() {
Serial.begin(9600);

// initialize SPI
pinMode(MY_SCS, OUTPUT);
digitalWrite(MY_SCS, HIGH);
SPI.begin();
SPI.setDataMode(SPI_MODE3); // NO
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2);

// enable chip
digitalWrite(MY_SCS, LOW);

// status
SPI.transfer(0xd7);
st = SPI.transfer(0);

// disable chip
digitalWrite(MY_SCS, HIGH);

}

void loop() {
Serial.println(st, HEX);
delay(1000);
}

@BlockoS
Copy link
Owner

BlockoS commented Apr 19, 2014

Thanks for report.
I checked the datasheet. The device density bits are provided for backward compatibility.
Maybe it will be safer to use the first byte of the device Id. But that won't solve the problem.
A test may be to do something like:
status = SPI.transfer(0xff)

Unfortunately I won't be able to test it before Monday.

@rogierschouten
Copy link
Author

Thank you, and don't rush. In the
  meantime, I made this workaround: I added a digitalWrite to SCK
  after setting Mode 3, and I prevented buffer overflow:... in DataFlash::setup() ...    SPI.setDataMode(SPI_MODE3);        SPI.setBitOrder(MSBFIRST);    SPI.setClockDivider(SPI_CLOCK_DIV2);        // DIGITAL WRITE HERE TO ALLOW DETECTION OF MODE 3    digitalWrite(SCK, HIGH);    ... code omitted ...        /* Bit 3 of status register is ignored as it's always
    1. Note that it is     * equal to 0 on the obsolete chip with density
    higher than 64 MB. */    uint8_t deviceIndex = ((stat & 0x38) >> 3)
    - 1;     if (deviceIndex >= 7) deviceIndex = 4; // DEFAULT
    TO AT45DB161D in case of faulty status code    m_bufferSize = m_infos.bufferSize[deviceIndex];    m_pageSize   = m_infos.pageSize[deviceIndex];      m_sectorSize = m_infos.sectorSize[deviceIndex];
  BlockoS schreef op 19-4-2014 22:33:

  Thanks for report.
    I checked the datasheet. The device density bits are provided
    for backward compatibility. 
    Maybe it will be safer to use the first byte of the device Id.
    But that won't solve the problem.
    A test may be to do something like:
    status = SPI.transfer(0xff)
  Unfortunately I won't be able to test it before Monday.
  —
    Reply to this email directly or view
      it on GitHub.

@BlockoS BlockoS added the bug label May 3, 2016
@tshivamiitk7
Copy link

tshivamiitk7 commented Jun 8, 2018

I am trying to write on AT45DB041D using Arduino uno. But at present i am not able to read the device ID & manufacturer ID using your page test program.
Can you suggest me what can be the possible settings or issues i am missing. @BlockoS @rogierschouten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants