Searching \ for 'Nested Interrupts on PIC16C74?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ints.htm?key=interrupt
Search entire site for: 'Nested Interrupts on PIC16C74?'.

Truncated match.
PICList Thread
'Nested Interrupts on PIC16C74?'
1995\10\19@182658 by John Loch

flavicon
face
Hello,

I am writing a I2C master transmit routine where I need to disable
interrupts for approximately 1 ms every 10 ms.  I am also incrementing a
counter for every state change on a port B pin with an interrupt service
routine.  If the port B pin changes state twice (3, 4, 5 times?) while the
interrupts are disabled during the 1 ms transmit, will the interrupts
become nested??  I can't afford to miss one of these port B interrupts.

Also if anyone has a better scheme to implement I2C master transmit, please
let me know.  Here is my pseudo-code algorithm:

on periodic-interrupt (once every 10 ms)
if I2C bus not busy
  disable-all-interrupts         /* so as not to screw up the timing of my
software delay loops */
  send start
  for each byte in queue
     send-byte-with-arbitration-check
  end for loop
  send stop
  enable-interrupts
end if

to send-byte-with-arbitration-check
  for each bit in byte (MSB first)
     clear-bit TRISC<3>                  /* pull the SCLK line low */
     if bit=1
        set-bit TRISC<4>                  /* set SDA line high */
        set arbitration-flag = 1        /* flag indicating arbitration
must be checked */
     else
        clear-bit TRISC<4>              /* set SDA line low */
        set arbitration-flag = 0        /* no need to check for
arbitration on this bit */
     end if
     delay-instructions                 /* do nothing instructions to
implement 5 us delay */

     set-bit TRISC<3>                   /* set SCLK line high (data valid) */
     if arbitration-flag = 1            /* check for bus contention */
        if PORTB<4> = 0                 /* another device has priority,
abort send */
           abort-send                      /* abort transmission and try
again later */
        end if
     end if
     delay-instructions               /* do nothing instructions to
implement 5 us delay */
  end for loop
  /* make sure slave acknowledges byte */
  set-bit TRISC<4>                     /* set SDA line high (tri-state) */
  clear-bit TRISC<3>                 /* pull the SCLK line low */
  delay-instructions                  /* do nothing instructions to
implement 5 us delay */
  set-bit TRISC<3>                   /* set SCLK line high */
  if PORTB<4> = 1                      /* slave didn't acknowledge */
     abort-send                            /* abort transmission and try
again later */
  end if
  delay-instructions                  /* do nothing instructions to
implement 5 us delay */
end send-byte-with-arbitration-check

Note: 5 us delay to implement 100 kbits/second I2C data rate

- John Loch
spam_OUTjohnlochTakeThisOuTspammtt.com
The Source for Renewable Energy -
http://www.mtt.com/theSource/renewableEnergy

1995\10\20@011507 by Andrew Warren

face
flavicon
face
John Loch <.....johnlochKILLspamspam@spam@MTT.COM> wrote:

>I am writing a I2C master transmit routine where I need to disable
>interrupts for approximately 1 ms every 10 ms.  I am also incrementing a
>counter for every state change on a port B pin with an interrupt service
>routine.  If the port B pin changes state twice (3, 4, 5 times?) while the
>interrupts are disabled during the 1 ms transmit, will the interrupts
>become nested??  I can't afford to miss one of these port B interrupts.
>
>Also if anyone has a better scheme to implement I2C master transmit, please
>let me know.

John:

The PIC will set the interrupt flag on the FIRST change-on-portB interrupt
that happens while interrupts are disabled, but it won't tell you if any
more occurred.  With the change-on-portb interrupts, you could store the
state of the portb pins at each interrupt, then compare the value stored at
the last interrupt to the value of the pins during the current interrupt,
thereby making it possible to tell whether TWO interrupts had occurred, but
there's no way you'll ever be able to tell when three or more happened.

Unless you really need the fastest possible I2C transmit rate, why not leave
interrupts enabled?  The 5-microsecond delays are the MINIMUM allowable; if
you stretch them out (to hours, even), nothing bad will happen.

-Andy

--
Andrew Warren - fastfwdspamKILLspamix.netcom.com
Fast Forward Engineering, Vista, California

More... (looser matching)
- Last day of these posts
- In 1995 , 1996 only
- Today
- New search...