View previous topic :: View next topic |
Author |
Message |
theteaman
Joined: 04 Aug 2006 Posts: 98
|
Missing interrupts (18F4550) |
Posted: Sun Dec 18, 2011 6:20 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sun Dec 18, 2011 6:44 am |
|
|
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'.... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 18, 2011 3:08 pm |
|
|
What i2c slave chip is your PIC talking to ? Post the Manufacturer and
part number of the slave chip. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Sun Dec 18, 2011 3:20 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Sun Dec 18, 2011 5:25 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sun Dec 18, 2011 7:00 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: Missing interrupts (18F4550) |
Posted: Sun Dec 18, 2011 7:59 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sun Dec 18, 2011 9:29 pm |
|
|
What value are the I2C pullups and what is the clock of the 4550 ? |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Dec 19, 2011 12:17 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
|