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

28c256 infinite loop while erasing #9

Open
Cubzer opened this issue Feb 13, 2020 · 1 comment
Open

28c256 infinite loop while erasing #9

Cubzer opened this issue Feb 13, 2020 · 1 comment

Comments

@Cubzer
Copy link

Cubzer commented Feb 13, 2020

I modified the code so that it would overwrite the whole chip with 0xea. Turns out when i change the break condition in the erase loop to 32767 to match the size of the eeprom it goes into a seemingly infinite loop. My guess is that the 16 bit signed INT of the arduino overflows so that the break condition of the erase loop will never be met. Changing this to an unsigned INT solved the problem for me. But because of my inexperience with arduinos i could also be wrong.

@GregEakin
Copy link

Yes. The int variable address is a signed 16-bit variable. That means it'll never be larger than 32,767. Instead, it'll wrap around to -32,768 and start over again. We can change the address variable to a long type:

  // Erase entire EEPROM
  Serial.print("Erasing EEPROM");
  for (long address = 0L; address <= 0x7FFFL; address += 1L) {
    writeEEPROM((int)address, 0xff);

    if (address % 64 == 0) {
      Serial.print(".");
    }
  }
  Serial.println(" done");

As long as we don't send the writeEEPROM(int address, byte data) method an address with more than 15 bits.

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

No branches or pull requests

2 participants