WRITE TO Eeprom


Closed Thread
Results 1 to 11 of 11

Thread: WRITE TO Eeprom

  1. #1
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77

    Cool WRITE TO Eeprom

    Hi all,

    Has anyone any idea why the write command does not want to work inside a hardware interrupt routine. Is it maybe too fast or is it maybe that with MPASM things are different.
    My program uses Darrel's instant interrupts and when in the interrupt it gets a new piece of data and must write it to EEPROM. Before I started with the interrupts and used polling and PM all worked fine, now no data change in eeprom.

    This is the Interrupt routine:
    '==================== DATA RECEIVE ROUTINE ==============================

    GETDATA:
    'serout2 test,baud,["int",10,13]

    IF RCIF=1 THEN 'DATA IS READY TO BE COLLECTED
    'REMOVE BYTE FROM RCIF REGISTER

    VALUE=RCREG
    IF VALUE = $A0 THEN 'CHECK TO SEE IF THE BYTE IS THE START BYTE
    BYTECOUNTER=0
    ENDIF
    'Serout2 test,BAUD,["int",10,13] 'TO SHOW OVERFLOW

    IF BYTECOUNTER < 8 THEN
    BUFFER[BYTECOUNTER] = VALUE 'ADD BYTE TO PACKET
    BYTECOUNTER=BYTECOUNTER+1 'INCREMENT COUNTER
    ENDIF

    '************ CHECK IF OVERRUN HAS OCCURRED *******************************

    IF OERR=1 THEN
    Serout2 test,BAUD,["OERR",10,13] 'TO SHOW OVERFLOW
    PAUSE 1000
    CREN=0 'STOP CONTINUOUS RECEIVE
    CREN=1 'RESTART CONTINUOS RECIEVE & CLEAR THE OVERRUN FLAG
    BYTECOUNTER=0 'RESET COUNTER AS PART OF PACKET HAS BEEN LOST SO START AGAIN
    BUFFER=0
    GOTO GETDATA
    ENDIF

    '************** PACKET MUST START WITH $A0 AND HAVE $AF AS IT'S 7TH BYTE. ******

    IF BYTECOUNTER=7 AND BUFFER[0]=$A0 AND BUFFER[6]=$AF THEN
    GOT=1 'INDICATE THAT THIS IS A NEW PACKET

    ' ****************** PRESET CONTROL **********************************


    IF ID = (BUFFER[1]+1) THEN 'CHECK IF ID IS FOR THIS INSERTADOR &
    'PELCO VALUE STARTS AT 0 SO NEED TO ADD 1

    IF BUFFER[3]=$07 THEN

    preset=buffer[5]

    IF PRESET=0 THEN
    PRESET=1 'Ensure that preset 0 is never used as inputs start at 1
    ENDIF

    IF PRESET=76 THEN
    DATA_OFF=1
    GOTO JUMP
    ENDIF

    if preset < 24 then
    DATA_OFF=0

    write 0,preset '******* HERE IT SHOULD WRITE ******
    else
    read 0,preset 'If preset entered is above 24 read last saved preset
    endif

    JUMP:

    endif

    endif

    ELSE
    GOTO GETDATA 'IF PACKET NOT COMPLETE GO BACK FOR NEXT BYTE
    ENDIF


    ENDIF

    @ INT_RETURN

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I'm fairly sure that you have to shut off ALL interrupts while trying to write to eeprom or flash, not just DISABLE interrupts. You actually have to disable the global interrupt enable flag, then reenable it when the write is done.

  3. #3
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I'm fairly sure that you have to shut off ALL interrupts while trying to write to eeprom or flash, not just DISABLE interrupts. You actually have to disable the global interrupt enable flag, then reenable it when the write is done.

    I Tried moving the WRITE statement to the main program like this but it still does'nt write:

    INTCON = %00000000 'DISABLE GLOBAL & PERIFERAL INTERRUPTS
    WRITE 0, PRESET
    PAUSE 10
    INTCON = %11000000

    Regards

    Chris

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mm, seems the ISR is too long anyways... can you post your whole code and tell which PIC you're using?

    Not sure if it's a good idea to write to a EEPROM in a USART ISR.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Default

    [I am using a 16F877A at 20MHz

    I use timer1 to check the dip switch settings for the device's address and the UASRT one for data in.

    Sorry for using attachment, my code was too long for the forum page
    Attached Files Attached Files

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by crhomberg View Post
    [I am using a 16F877A at 20MHz

    I use timer1 to check the dip switch settings for the device's address and the UASRT one for data in.

    Sorry for using attachment, my code was too long for the forum page
    Isolate the problem...
    Start with a program without any serial input or output, no nothing, just a couple of LEDs and maybe a button or two.
    Write and Read the EEPROM and make the LEDs show you if the write/read works correctly or not, use the buttons to increment the addresses and data to be written.
    Something tells me that something else in your program isn't working right in the first place, making you think that the EEPROM isn't being written correctly...
    Maybe PBP work for you...not the other way around...

  7. #7
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Post read and write

    Hi everyone!

    I can read and write now using the pic16f84a but I can't do that using pic16f877a.
    Is there any lines I have to add inorder to allow reading and writing the eeprom?
    I've read the 16f877a datasheet. It is stated there that I have to disable all interrupts before writing. I've tried that but still won't work.

    A working simple code for reading and writing the internal eeprom of pic16f877a is all I need.

    Please help me...
    Thank you in advance.

  8. #8
    Join Date
    Nov 2007
    Location
    Bohol, Philippines
    Posts
    4


    Did you find this post helpful? Yes | No

    Default This Is My Code In Writing An Internal Eeprom!

    trisb=0
    portb=0
    aa var byte
    bb var byte

    eeprom 2,[0]
    aa=4

    write 2, aa
    read 2, bb

    if bb==4 then
    portb.0=1
    endif

    I tried 16f84a it function, the LED at portb.0 lights up..
    but in 16f877a, the LED did not light...
    what happen to this situation?
    is there a need to disable interrupts?
    with that simple program....

    HELP US PLS....
    thnx....

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    1 - which version of PBP are you using?
    2 - what clock speed are you trying to run with?
    3 - which programmer are you using?

  10. #10
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Default versions

    from kindred:
    picbasic pro compiler version 2.3
    4MHz
    kit128

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ria_river View Post
    from kindred:
    picbasic pro compiler version 2.3
    4MHz
    kit128
    PBP 2.3? Upgrade to 2.50a... $20 says you can't do it!
    877A support isn't in 2.3 according to melabs support page.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 15:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 04:17
  3. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 15:19
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 20:59

Members who have read this thread : 0

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