CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Command "write_eeprom" collides with incoming I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
koesterk



Joined: 15 Apr 2008
Posts: 3

View user's profile Send private message

Command "write_eeprom" collides with incoming I2C
PostPosted: Tue Apr 15, 2008 9:21 am     Reply with quote

Hi guys,
following problem occurs: PIC16F677 works as an I2C slave in an embedded system. The I2C handler is interrupt based and similar to the compiler's examples. Additionally, the software has to save frequently status bytes to the internal EEPROM. Now it might happen that the I2C stream occurs while command "eeprom_write" has just been started. In this case on electrical side the PIC confirms the identified device address, but following bytes are all NAK'ed. The next -and all following- incoming I2C commands are directly NAK'ed at the device address. I need to reset the device to get I2C back on track.

I guess that the global interrupt is disabled while waiting for the EEPROM's write confirmation. Thus, the Interrupt Service Routine can't move the incoming bytes away.

Two questions: Anybody out there with such (or similar) experiences? Does it make sense to write my own EEPROM write command in assembler with disabled GIE only around the atomic sequence 0x55 - 0xAA?

Second question: What happens to the I2C peripheral when SSP interrupt is not able to handle incoming bytes? Any chance to re-activate I2C functionality from software? Resetting the PIC no option for me.

Thanks a lot and best regards
Klaus
Matro
Guest







PostPosted: Tue Apr 15, 2008 9:30 am     Reply with quote

3 things to do :
- First is to make the EEPROM write asynchronous
Code:

#device(write_eeprom=ASYNC)


- Second is to improve interrupt clear in the i2c isr
Code:

#int_SSP NOCLEAR
void  SSP_isr(void)
{
  clear_interrupt(int_SSP);
  //code continue
}


- Third and last is to clear the SSPOV flag in the main endless loop
Code:

#BIT SSPOV = 0x14.6
//...
SSPOV = 0; //added in the main()


The 2 last tips will not avoid NAK but will allow I²C to recover.
The first will avoid bugs if the EEPROM saving is done less than every 5ms (roughly).

Matro.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group