Shop OBEX P1 Docs P2 Docs Learn Events
Values in Hex in EEPROM — Parallax Forums

Values in Hex in EEPROM

sharmaitsharmait Posts: 15
edited 2005-04-21 20:52 in General Discussion
Hi Peter,

I have been using·the program EETest.java to write values to EEPROM and then dump the·memory using·EEdump.java.·Everything is fine but whenever I try to write a·odd number·to the EEPROM (e.g SetEEPROM(4367) or SetEEPROM(5)), I see a rounded up value in HEX when I dump the memory. For example 4367 showed as 10AA (correct value should have been 10AB) and 5 showed as 4. It is always 1 less than the actual number. I had no problem with even numbers.

Can you please help me on this ?

Thanks,
Sharmait.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-21 18:46
    please post your program.

    regards peter
  • sharmaitsharmait Posts: 15
    edited 2005-04-21 19:00
    Here are the two programs that I am using :

    For "stamp.util.text.*" I am using the text format library·from parallax website http://www.parallax.com/javelin/applications.asp#AN012

    EETest Program

    =================================

    import stamp.core.*;

    public class EETest {

    static void setEEProm(int n) {
    EEPROM.write(0,(byte)(n&0xFE));
    EEPROM.write(1,(byte)(n>>8));
    }


    static int getEEProm() {
    int x;
    x=EEPROM.read(1);
    x=(x<<8)+EEPROM.read(0);
    return x;
    }


    public static void main() {
    setEEProm(4267); //This is where I set an ODD value//
    System.out.println("Bytes available in EEPROM:");
    System.out.println(EEPROM.size());
    System.out.println("The value you wrote to EEPROM:");
    System.out.println(getEEProm());
    } // end main
    } // end class

    ==============================

    Memory dump program
    =============================
    import stamp.core.*;
    import stamp.util.text.*;
    /**
    ·* Print the javelin's eeprom
    ·*
    ·* @version 1.0, April 12, 2005
    ·* @author Peter Verkaik (peterverkaik@boselectro.nl)
    ·*/
    public class memdump {
    · /**
    ·· * Print free area of javelin eeprom to the message window.
    ·· */
    · static void printEeprom() {
    ··· int x,y;
    ··· char c;
    ··· for (x=0000;x<EEPROM.size()/16;x++) {
    ····· Format.printf("%04x : ",(x*16));··············· /* Display the address··············· */
    ····· for (y=0;y<16;y++) {····························· /* write the contents in hex······· */
    ······· Format.printf("%02x ",0xFF & EEPROM.readAll((x*16)+y));
    ····· }
    ····· for (y=0;y<16;y++) {······················· /* Display the ASCII-characters······· */
    ······· c = (char) EEPROM.readAll((x*16)+y);
    ······· if ((c>=' ') && (c<=0x7E))
    ········· Format.printf("%c",c);
    ······· else
    ········· Format.printf(".");
    ····· }
    ····· Format.printf("\n");······················· /* New line······················· */
    ··· }
    · }
    · static void main() {
    ····printEeprom();
    ··· while (true);
    · }
    }

    Thanks Very Much !
    Sharmait.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-21 19:58
    In your routine

    static void setEEProm(int n) {
    EEPROM.write(0,(byte)(n&0xFE));
    EEPROM.write(1,(byte)(n>>8));
    }

    you do a bitwise AND with 0xFE (i.e clear bit0)

    so when you read it back any odd number appears to be even.

    You must AND with 0xFF, but you can also

    just use EEPROM.write(0,(byte)n);

    as only the lowest byte is written.

    regards peter
  • sharmaitsharmait Posts: 15
    edited 2005-04-21 20:03
    Thanks very much !!

    Yes I see now where the error is...

    Sharmait.
  • sharmaitsharmait Posts: 15
    edited 2005-04-21 20:20
    Hi,

    Just wanted to mention that the EETest.java program that I am using came with the Parallax Javelin Stamp CD (in examples). So as far as the·bitwise AND with FE(EEPROM.write(0,(byte)(n&0xFE)) is concerned, is it is bug or has been put there for some reason ? Just checking in case we want to update the EEtest.java program in the parallax CD.

    Thanks...
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-21 20:52
    I think it was a typing error.

    regards peter
Sign In or Register to comment.