Simple READ/WRITE EEPROM is driving me nuts! pls help


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default Simple READ/WRITE EEPROM is driving me nuts! pls help

    This is a stripped down part of a larger program. Eventually I need to collect several temperatures over a period of time, and read them back later, after power-cycling the pic. I simply can't figure out what is going wrong. I have commented the listing at several points to explain what I am doing in this very simple routine. I have used extensive serout2 commands to see exactly what is going on - but they do not help my simple mind at this point. As I have commented in the listing, I can write, and then read back immediately to the on-board EEPROM, and everything works in two identical routines. However, trying the same code another time does not work. I'm sure there are probably postings here that will help, I just have not been able to find any yet. I noticed on this listing that the first read of TempF shows TEMPF as all caps , however that is not the way the actual listing is.

    I am using PBP version 2.6a, and a 18f2520. The defines, etc are required for the complete program.

    any and all comments will be most appreciated

    Ken

    Code:
    '****************************************************************
    '*  Name    : RD / WRT TEST.BAS                                 *
    '*  Author  : KRS                                               *
    '*  Date    : 7/27/2012                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :  USING PBP VERSION 2.60A    PIC IS 18F2520        *
    '*          :   I AM USING WEB4ROBOTS SERIAL KEYPAD AND LCD     *
    '*          :  REQUIRES DIFFERENT SEROUT2 COMMANDS              *
    '****************************************************************
      
    '
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50 
    
    OSCTUNE.6 = 1 
     define OSC 4
     OSCCON = %01101110         
    ADCON1 = %10001011          ' RIGHT JUSTIFY, PORTB ALL DIGITAL
    
    TRISC =  %10111000
    TRISA =  %11111111
    TRISB =  %00000011
                  
                             
    MXSO            VAR  PORTC.0    ' SERIAL IN
    MXCS            VAR  PORTC.1    ' CHIP SELECT
    MXSCLK          VAR  PORTC.2    ' CLOCK                              
      
    INT             VAR  PORTC.5     'Keyboard INT used to signal a key entry 
    TX              var  PORTC.6
    Rx              var  PORTC.7 
    
      
     'Allocate MAX6875 Variables
    MXTemp      var     word    'raw data from 6675/type K sensor
    TempF       var     word       'Actual Farenheit  temp
    TempC       var     word
    
    Y           VAR     BYTE
    x           var byte 
    Z   VAR BYTE
    TEMPF1      VAR     WORD
    TEMPF2      VAR WORD
    
    
    '***************************************************************
    '       web4robots must be set-up first ! ! ! 
    '****************************************************************
    serout2 TX,84,[$FE,$02,3]       'SET BAUD RATE AT 9600
    PAUSE   50
    SEROUT2 TX,84, [$FE, $0A]   'Ensures that the display is on
    pause   150                 'Eliminate double key entry
    SEROUT2 TX, 84, [$FE, $14]    'Ensures that the screen is cleared
    PAUSE 100
    SEROUT2 TX, 84, [$FE, $03, 20] 'Sets the brightness (0-250)  
    PAUSE 100
    SEROUT2 TX, 84, [$FE, $04, 10]  'sets contrast (Low number = Hi Contrast)
    PAUSE   100
    serout2 TX,84,[$FE,$14] 'clear the screen 
    '
    '******************************************************* 
    
    START:
        PAUSE  2000     
        Y = 0  
        for x = 1 to 5
     
    WRITE_temp:      'READ THE THERMOCOUPLE AND SAVE IT
           MXCS = 0  'Chip select low
           shiftin MXSO, MXSCLK, 0, [MXTemp\16]   'read the data to MXTemp
           MXCS = 1    'Chip select high 
           TempC = MXtemp >> 5    
           TempF = (TempC*18)/10+32
           pause   30    
        '      READ THIS TEMPERATURE
           SEROUT2 TX,84,[$FE,$0C,0,0,"TEMP= ",dec TEMPF]
           PAUSE 3000
           SEROUT2 TX,84,[$FE,$14] ' clears the display
           PAUSE 50
    '
    '       NOW WRITE IT TO EEPROM LOCATION IN VARIABLE Y
             
           WRITE Y,WORD TEMPF
    '
    '   IMMEDIATELY READ IT BACK  - - THIS VALUE IS READ CORRECTLY ALL 5 TIMES
    '
           READ Y, WORD TEMPF1 
           SEROUT2 TX,84,[$FE,$0C,1,0,"READ TEMP= ",DEC TEMPF]       
           PAUSE   30       
           PAUSE 3000
           SEROUT2 TX,84,[$FE,$14] ' clears the display
           PAUSE    3
    '******************************    
    '    NOW READ IT BACK AND WRITE TO A DIFFERENT VARIABLE ( TEMPF1)
    '   THIS READ ALSO WORKS CORRECTLY ALL 5 TIMES
    '*****************************  
           READ Y, WORD TEMPF1
           PAUSE 50 
           SEROUT2 TX,84,[$FE,$0C,0,0,"READ1 TEMPF1= ",DEC TEMPF1]
           PAUSE 30
           SEROUT2 TX,84,[$FE,$0C,1,0,"X = ",dec x]
           PAUSE    20
           SEROUT2 TX,84,[$FE,$0C,2,0,"Y = ",dec Y]
           PAUSE 3000
           SEROUT2 TX,84,[$FE,$14] ' clears the display
           pause 30       
           Y = Y + 1
           next x       
           
           PAUSE   3000
    
    '**********************************
    ' NOW TRY TO READ IT AGAIN, USING ANY VARIABLE DOES NOT MATTER , TEMPF1, ETC
    '    THE ONLY CORRECT READ HERE IS THE LAST ONE, (Y = 4) 
    'ALL OTHERS ARE INCORRECT - - VERY HIGH VALUES - - 23375, 22860, ETC
    '*****************************************************************
           Y = 0         'RESET THE EEPROM ADDRESS POINTER TO 0
           FOR X = 1 TO 5 
           READ Y, WORD TEMPF2  ' USING VARIABLE TEMPF2 HERE, ANY OTHER VARIABLES 
                                ' DO NOT WORK EITHER
           PAUSE 50 
           SEROUT2 TX,84,[$FE,$0C,0,0,"READ2 TEMPF2= ",DEC TEMPF2]
           PAUSE 30
           SEROUT2 TX,84,[$FE,$0C,1,0,"X = ",dec x]
           PAUSE    30
           SEROUT2 TX,84,[$FE,$0C,2,0,"Y = ",dec Y]
           PAUSE 2000
           SEROUT2 TX,84,[$FE,$14] ' clears the display
           pause 30         
           Y = Y + 1
           next x      
                 
     DONE:
          SEROUT2 TX,84,[$FE,$14] ' clears the display
          PAUSE 50
          SEROUT2 TX,84,[$FE,$0C,2,0,"DONE"]
          pause   1000    
          GOTO   DONE

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    At a quick scan I see you are writing a word to the eeprom which = 2 bytes, yet you are only increasing your pointer by 1, I think you need to change it to y=y+2

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    Thanks for looking Aerostar, but that does not seem to be the problem.
    First I write 5 temperature values from the thermocouple in succession, and read each back immediately after it is written.
    Next, I use the for next loop, incrementing one at a time, and that works.

    It is the last for next loop, identical to the previous one, that does not work.

    Still have not figured it out

    Ken

    ps I did try incrementing by two to no avail

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    Ken,
    Make sure you change BOTH of the "Y=Y+1" statements to "Y=Y+2"

    I have verified your code works if you change both. Here is my version of your code. I've trimmed it down, modified the output methods, and generated the temps without the ADC. But your will notice all the WRITE and READ statements are the same. I output the values in hex, which allowed be to then read the EEPROM as an additional way to verify the data.

    Code:
    TEMPF   VAR WORD
    TEMPC   VAR WORD
    Y       VAR BYTE
    X       VAR BYTE
    Z       VAR BYTE
    TEMPF1  VAR WORD
    TEMPF2  VAR WORD
    
    
    START:
        PAUSE  2000     
        Y = 0  
        for x = 1 to 5
     
    WRITE_temp:      'READ THE THERMOCOUPLE AND SAVE IT
           TempC = 1 << Y
           TempF = (TempC*18)/10+32
           LCDOUT $FE, $80, HEX4 TempF
           pause   30    
        '      READ THIS TEMPERATURE
           HSEROUT ["TEMP= ",HEX4 TEMPF, 13]
    '
    '       NOW WRITE IT TO EEPROM LOCATION IN VARIABLE Y
           WRITE Y,WORD TEMPF
    '
    '   IMMEDIATELY READ IT BACK  - - THIS VALUE IS READ CORRECTLY ALL 5 TIMES
    '
           READ Y, WORD TEMPF1 
           HSEROUT ["READ TEMP= ",HEX4 TEMPF, 13]       
    '******************************    
    '    NOW READ IT BACK AND WRITE TO A DIFFERENT VARIABLE ( TEMPF1)
    '   THIS READ ALSO WORKS CORRECTLY ALL 5 TIMES
    '*****************************  
           READ Y, WORD TEMPF1
           HSEROUT ["READ1 TEMPF1= ",HEX4 TEMPF1, 13]
           
           LCDOUT $FE, $C0,"X = ",dec x
           LCDOUT " Y = ",dec Y
          
           Y = Y + 2
           next x       
           
           PAUSE   3000
           HSEROUT ["-----------------------------", 13]
    
    '**********************************
    ' NOW TRY TO READ IT AGAIN, USING ANY VARIABLE DOES NOT MATTER , TEMPF1, ETC
    '    THE ONLY CORRECT READ HERE IS THE LAST ONE, (Y = 4) 
    'ALL OTHERS ARE INCORRECT - - VERY HIGH VALUES - - 23375, 22860, ETC
    '*****************************************************************
           Y = 0         'RESET THE EEPROM ADDRESS POINTER TO 0
           FOR X = 1 TO 5 
           READ Y, WORD TEMPF2  ' USING VARIABLE TEMPF2 HERE, ANY OTHER VARIABLES 
                                ' DO NOT WORK EITHER
           HSEROUT ["READ2 TEMPF2= ",HEX4 TEMPF2,13]
           Y = Y + 2
           next x      
                 
           HSEROUT ["Done", 13]
    DONE:
         
          pause   1000    
          GOTO   DONE
    
        
    END

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    Forgot to post the output:

    Code:
    TEMP= 0021
    READ TEMP= 0021
    READ1 TEMPF1= 0021
    TEMP= 0027
    READ TEMP= 0027
    READ1 TEMPF1= 0027
    TEMP= 003C
    READ TEMP= 003C
    READ1 TEMPF1= 003C
    TEMP= 0093
    READ TEMP= 0093
    READ1 TEMPF1= 0093
    TEMP= 01EC
    READ TEMP= 01EC
    READ1 TEMPF1= 01EC
    -----------------------------
    READ2 TEMPF2= 0021
    READ2 TEMPF2= 0027
    READ2 TEMPF2= 003C
    READ2 TEMPF2= 0093
    READ2 TEMPF2= 01EC
    Done

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Simple READ/WRITE EEPROM is driving me nuts! pls help

    SreveB

    Thanks so much. That was my problem. Actually, I thought that I should add 2 each time, but for some reason stuck with only one. You are correct, when I tried adding 2 originally , it was only to one of the sections. Sometimes I guess I should stay in bed longer.

    Thanks again

    Ken

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts