EEPARAM is in bank2? You don't have to enable interrupts since the interrupts flags are set regardless of the interrupt state (on/off). BTW what PIC are we talking about? MIRCEA CHIRICIUC EMCO INVEST ----- Original Message ----- From: "Pic Dude" To: Sent: Friday, June 07, 2002 7:29 AM Subject: [PIC]: EEPROM write woes > This is why I'm bald... been ripping my hair out trying > to figure out this problem. At first, I was not waiting > for EEIF to be set and noticed that data was not getting > written to the EEPROM. Then, I added the 3 lines to wait > on EEIF set and get an odd result -- when the routine > gets called, it works some times and other times it hangs > -- the code just freezes. (No WDT btw). > > I've checked (prior to waiting on EEIF) with the simulator > and it works there. Also verified that it's getting the > right values for the data and location. The way I see it, > no matter what is passed in, this routine should work, > right? It should not hang. And most of the routine is > from the datasheet. > > I do have TMR0 interrupts occuring, but that should not > hang this routine, should it? Yes, I do save and restore > W & STATUS in the ISR. > > Anyone have clues as to what may be happening? > > Cheers, > -Neil. > > > ;------------------------------------------------------ > ; Write data (in EEPARAM) to EEPROM location (in W) > ;------------------------------------------------------ > SetEEData: > bsf STATUS,RP1 ; Bank 2 > bcf STATUS,RP0 ; Bank 2 > > movwf EEADR > movf EEPARAM,W ; Data to be stored > movwf EEDATA > bsf STATUS,RP0 ; Bank 3 > bcf EECON1,EEPGD ; Point to data memory > bsf EECON1,WREN ; Enable writes > bcf INTCON,GIE ; Disable interrupts (if enabled) > movlw H'55' ; Special seq > movwf EECON2 ; ... > movlw H'AA' ; ... > movwf EECON2 ; ... > bsf EECON1,WR ; Start write operation > bsf INTCON,GIE ; Enable interrupts (only if being used) > bcf EECON1,WREN ; Disable writes > > bcf STATUS,RP1 ; Reset to bank 0 > bcf STATUS,RP0 ; > > WaitEEWriteComplete: > btfss PIR2,EEIF > goto WaitEEWriteComplete > > return > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics