Shop OBEX P1 Docs P2 Docs Learn Events
eeprom.read conflicts with rxUart — Parallax Forums

eeprom.read conflicts with rxUart

askpolyaskpoly Posts: 11
edited 2010-08-05 01:49 in General Discussion
I have been working to resolve an issue where the results of eeprom.read are not correct and seem almost random.

I am using some example code for testing as follows. If you run it, the eeprom.read does not always return the correct results.· If, you comment out the rxUart or stop the rxUart.stop(), then after the eeprom.read restart it, rxUart.start() it works fine.

Does anyone else know of this bug? Is there any other way around it?

Thanks
George




// Program Listing 9.5 - EEPROM Test
import stamp.core.*;

public class EETest {
· final static int GENERATOR···· = CPU.pin7;· //Generator
·// static PWM genPWM = new PWM(GENERATOR);
·// static DAC absDAC = new DAC(CPU.pin12);
· final static int SERIAL_TX_PIN = CPU.pin10; //port pin 2
· final static int SERIAL_RX_PIN = CPU.pin11; //port pin 3
· static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert, Uart.speed19200, Uart.stop1);
· static Uart rxUart = new Uart(Uart.dirReceive,· SERIAL_RX_PIN, Uart.dontInvert, Uart.speed19200, Uart.stop1);

· static void setEEProm(int n) {
··· // have to chop n into bytes
··· 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(2300);
····· //genPWM.update(11406, 115);
····· // absDAC.update(128);
··· System.out.println("Bytes available in EEPROM:");
··· System.out.println(EEPROM.size());
······· while(true){
··· System.out.print("The value you wrote to EEPROM: ");
··· System.out.println(getEEProm());
··· }
· }················································· // end main
}

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-04-12 14:08
    Your write routine

    · static void setEEProm(int n) {
    ··· // have to chop n into bytes
    ··· EEPROM.write(0,(byte)(n&0xFE));
    ··· EEPROM.write(1,(byte)(n>>8));
    · }

    has an error.
    Please change the first line into
    ··· EEPROM.write(0,(byte)(n&0xFF));


    regards peter
  • askpolyaskpoly Posts: 11
    edited 2010-04-12 14:27
    I noticed that error, but that is not the cause of the problem. Since I am writing only once, and I am writing 2300, it doesn't cause a problem.

    The problem is when reading. It will not consistently return the same value. The value returns may be 2301 or -4 or anything in between.

    thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-04-12 14:35
    To be sure there is no sign extend

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

    Also try another address above 0x10.
    Perhaps eeprom address·0 is weared out.

    regards peter
  • askpolyaskpoly Posts: 11
    edited 2010-04-12 15:21
    Making the suggested changes and changing the memory location from 0x10 to 0x43 results in similar results (see below copied from the message window)

    We see this same problem as part of our application where we are using a javelin as an interface between an x-ray machine and a pc. This problem exist on all units, so across say 30 different javelin chips. I am using the above program just for troubleshooting of the core issue, the eeprom.read seems unreliable unless the rxUart is stopped first. the txUart doesn't seem to make an effect, nor does any of the other VPs. Our application writes to the javelin EEPROM only once, but reads often, like the example program above.

    I am hoping to find a solution without having to stop and restart the rxUart as I am not sure that I can reliably stop and start it without causing the PC comms to get confused.

    As you look at the results below, keep in mind 2300 was written once. I do not understand how eeprom.read can return values that are close and or way off or correct. I also don't understand why stopping the rxUart seems to make eeprom.read return the correct value everytime.




    The value you wrote to EEPROM: 2300
    The value you wrote to EEPROM: 2300
    The value you wrote to EEPROM: -4
    The value you wrote to EEPROM: 2303
    The value you wrote to EEPROM: 2300
    The value you wrote to EEPROM: 2300
    The value you wrote to EEPROM: 2556
    The value you wrote to EEPROM: -1
    The value you wrote to EEPROM: 2300
  • askpolyaskpoly Posts: 11
    edited 2010-04-12 15:49
    I should specify I am running the above test program with the Javelin in the Demo Board and nothing connected to it at all, so the issue doesn't seem to any of the additional circuitry that is part of the normal application.
  • askpolyaskpoly Posts: 11
    edited 2010-04-12 19:00
    Interestingly enough, the key is to make sure the Uart buffer is clear. If I clear the buffer, I can get a correct read everytime. So, I don't need to stop the Uart to improve the eeprom.read, just clear the buffer.
  • markjay5058markjay5058 Posts: 1
    edited 2010-08-05 01:49
    hello...guys !!!
    Making the suggested changes and changing the memory location from 0x10 to 0x43 results in similar results (see below copied from the message window)











    Make Money Online

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    japanese katakana
Sign In or Register to comment.