Will Interrupts affect on chip eeprom writing?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Will Interrupts affect on chip eeprom writing?

    No, that's not what it means at all...

    You cannot use the WRITE command in an ASM type interrupt, because it's a PBP statement.

    When you use DEFINE WRITE_INT, GIE is turned back on during the WRITE command.
    If you have a WRITE command inside a PBP type ISR, GIE is turned on in the middle of the ISR, the stack hasn't been popped by a retfie, and the chip immediately interrupts again, quickly overflowing the stack.

    If you are using DEFINE WRITE_INT, you should never have a WRITE command inside the ISR.
    If you are using WRITE in your ISR, you should not use DEFINE WRITE_INT.

    Since interrupts cannot be interrupted (except low priority on 18F's), interrupts don't need to be disabled during a WRITE in the ISR anyhow.

    If you only have WRITE statements in your your main program, it's best to use DEFINE WRITE_INT, not wrap it with GIE=0/GIE=1.
    DT

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Will Interrupts affect on chip eeprom writing?

    Thank you for the information Darrel.

    Here is a sample code for me to understand it better.

    Code:
    CLEAR    
    
    @ __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF & _CP_ON & _WRT_OFF
    
    DEFINE OSC 20
    
    Number1Adr data word 0
    
    'DEFINE WRITE_INT 1
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 64  ' 19200 Baud @ 20MHz, 0,16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    CMCON = 7   ' Disable Comps.
    PAUSEUS 10
    CVRCON = 0  ' Turn off VRCON.
    PAUSEUS 10
    
    ADCON0 = 0
    ADCON1 = %00001111     ' All digital.
    
    TRISA = 0
    TRISB = 0
    TRISC = %10000000      ' RC7 RS232 RX pin.
     
    PORTA = 0
    PORTB = 0
    PORTC = 0
    
    RXLED var PORTC.4
    
    ' ========= RS232 RX ===========
    Header1     var byte
    Header2     var byte
    Komut       var byte
    Kimlik      var byte
    DataInLow   var byte
    DataInHigh  var byte
    WriteFlag   var byte
    OldNumber   var word
    Number      var word
    
    INCLUDE "DT_INTS-14_F873A.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,  _RS232RX,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    Pause 10
    
    Begin:
        header1     = 254
        header2     = 252 
        WriteFlag   = 0
    
    @   INT_ENABLE   RX_INT     ; enable external (INT) interrupts    
    
    Start:
       
        
        if writeflag > 0 then 
    ; disable interrupts    
    @   INT_DISABLE RX_INT   
    @   BCF INTCON, GIE
    
             read Number1Adr, word oldnumber    ' Read old value first.
             if oldnumber <> number then write Number1Adr,word number     
             ' If the incoming value changed, then write. Otherwise, do not write.
    
    ; enable interrupts    
    @   BSF INTCON, GIE            
    @   INT_ENABLE   RX_INT     
    
            writeflag =  0        ' Clear write flag.     
        
        endif 
        
    
    
        goto start
        
    
    RS232RX:
        rxled = 1
        hserin 50,Jump,[WAIT(header1,header2),komut,datainLow,DatainHigh]
            
            if komut = 100 then 
                WriteFlag = 1 
                number.lowbyte  = datainlow
                number.highbyte = datainhigh
            endif
           
    
    
    Jump:
    
      RXLED = 0
    @ INT_RETURN       
    
        
    END

    If I remove GIE, and use WRITE_INT, eeprom does not write right.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Will Interrupts affect on chip eeprom writing?

    Sayzer,

    I'm running your program here on a 16F873 @20Mhz in a LAB-X2 (I don't have an 873A).
    And I cannot make it write incorrect values due to interrupts during a WRITE.

    The only way to generate an interrupt during the write in that program is to send more serial data after the 254,252,100,xx,xx command.
    I can send any amount of data after it without any problems, as long as it's not another 254,252,100,xx,xx command.

    If I do send two commands in a row without giving it time to finish the first WRITE, then the datainLow,DatainHigh variables are overwritten in the middle of the write, and you get the lowbyte from the first command and the highbyte from the second command.

    I'm using the Serial Communicator in MicroCode Studio with the following data ...

    This works fine ...
    Code:
    #254#252#100$12$34,Mary had a little lamb, it's fleece was white as snow.


    This writes bad data...
    Code:
    #254#252#100$12$34#254#252#100$56$78,Mary had a little lamb, it's fleece was white as snow.


    So it seems to be the way the received data is being handled, instead of a problem with WRITE_INT.
    When you do GIE = 0 before the write, it will not service the interrupt during the entire write, which protects it from being improperly overwritten in the ISR. But then that causes missed interrupts, and the second command is never received.

    I also added a 10Khz interrupt from Timer1 ... No problems writing to EEPROM.
    Last edited by Darrel Taylor; - 21st March 2012 at 22:17.
    DT

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Will Interrupts affect on chip eeprom writing?

    Thank you Darrel.

    Playing with the TX side, each packet has 30ms pause at its end now.
    I removed GIE, and now using WRITE_INT.

    All seems ok.

    Thanks again.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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