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 CCS Technical Support

Missing interrupts (18F4550)

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



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

Missing interrupts (18F4550)
PostPosted: Sun Dec 18, 2011 6:20 am     Reply with quote

Hi

I have a interrupt handler (INT_EXT2) listening to a pin on an IC. When the IC is "ready" it sends the pin high, starting my interrupt handler. Then, I need to read I2C data from the IC.

My interrupt handler does nothing except set a flag to "true" indicating there is data to be read. Then in the main function there is a while loop that polls for this variable (amongst other things) and if it is set true, it reads the i2c data. After this there is code to process the messages that were received. So the pseudocode is like this:

Code:

#int_ext2
void isr(void)
{
   data_ready = true;
}


and in main():

while(1)
{
   if(data_ready)
   {
      readDataWithI2C() //adds data to a queue
      disable_interrupts(INT_EXT2);
      data_ready = false
      enable_interrupts(INT_EXT2);
   }

   if queue not empty
      process next item in queue
}


The problem is my program is not catching all the interrupts from the IC. It catches _most_ of them, but every once in a while I notice a mistake (which causes a loss of synchronization in my program).

Should I be performing the I2C reads inside the interrupt handler?

Any help appreciated, thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 6:44 am     Reply with quote

quick comments..
Since it catches most but not all, then there's a probably 'timing' issue.
Could be PIC is busy handling another interrupt ?
Are the I2C resistors the correct values for Vcc,distance,board layout,etc.
Why not use an real I2C handler ?
Without seeing the real code, PIC type,compiler version it's hard to nail down why this happens.

It could be some EMI from nearby PC, cell phone, wireless device, welder,microwave...endless list.

Hardware issues....bad solder joint,breadboard slot gimpy,bad ground,pcb/wire length between PIC and 'your unknown IC'(type would help).Maybe the 'IC' has 'issues', have you scoped it out to verify correct levels and timings?

Sorry but without more information, my crystal ball is 'fuzzy'....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 3:08 pm     Reply with quote

What i2c slave chip is your PIC talking to ? Post the Manufacturer and
part number of the slave chip.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 3:20 pm     Reply with quote

It appears he has an I2C master device, and is using the PIC as a slave, but an interrupt to trigger the PIC to go and fetch the data.

Why not use the I2C interrupt?.
Have you got your PIC setup to use clock stretching - probably necessary?.

Best Wishes
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 5:25 pm     Reply with quote

I am using the PIC as the master, the IC is the slave. I think this means I cannot use #INT_SSP as the PIC is the master and initiates the communication. Also I think it means I cannot do clock stretching?

I cannot post the details of the datasheet because I am not allowed, sorry.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 7:00 pm     Reply with quote

Sounds like the I2C 'IC' is NOT a regular I2C device but some other kind of micro emulating I2C protocol.
If it was a 'regular' I2C device we could help but it sounds like you're using something 'special' that we can't see the specs, confirm it conforms to I2C specs, etc.
Perhaps the manufacturer of this 'IC' will help you out?
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Missing interrupts (18F4550)
PostPosted: Sun Dec 18, 2011 7:59 pm     Reply with quote

theteaman wrote:
Hi

I have a interrupt handler (INT_EXT2) listening to a pin on an IC. When the IC is "ready" it sends the pin high, starting my interrupt handler. Then, I need to read I2C data from the IC.

My interrupt handler does nothing except set a flag to "true" indicating there is data to be read. Then in the main function there is a while loop that polls for this variable (amongst other things) and if it is set true, it reads the i2c data. After this there is code to process the messages that were received. So the pseudocode is like this:

Code:

#int_ext2
void isr(void)
{
   data_ready = true;
}


and in main():

while(1)
{
   if(data_ready)
   {
      readDataWithI2C() //adds data to a queue
      disable_interrupts(INT_EXT2);
      data_ready = false
      enable_interrupts(INT_EXT2);
   }

   if queue not empty
      process next item in queue
}


The problem is my program is not catching all the interrupts from the IC. It catches _most_ of them, but every once in a while I notice a mistake (which causes a loss of synchronization in my program).

Should I be performing the I2C reads inside the interrupt handler?

Any help appreciated, thanks.


You do not need to disable and re-enable interrupts in the main line as the clearing the boolean value it a single instruction operation.

Could you be "missing" an interrupt because you are spending too much time in the "process next item in queue" logic?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 9:29 pm     Reply with quote

What value are the I2C pullups and what is the clock of the 4550 ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 19, 2011 12:17 am     Reply with quote

Are you using level sensitive interrupts? Does the interrupt source hold the request until it is serviced? How can you miss interrupts in this case?
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