eeprom.read conflicts with rxUart
askpoly
Posts: 11
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
}
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
· 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
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
· 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
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
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