This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Blocking interrupts

Genius 5910 points

I have a piece of memory that I share with an interrupt function.

 When My functions read that part of memory I need to block the interrupt so the interrupt doesn't interrupt my read action (atomic read)

  I only need to block the interrupt for a really short time and no interrupt may be lost in this process.

 What is the best way to to this?

 Can I block it, by disabling  the PIE IER bit?

Of is the only more drastic way INTM=1? 

Thanks.

  • If you need to block interrupts only for very short intervals the simplest and safest way is to use the INTM bit.  You could mask the core interrupt with IER if you want to keep other (innocuous) interrupts active while you do the read. 

    You could do it by manipulating the PIEIERx registers, but there is a strict procedure which needs to be followed (see the PIE chapter in the User's Guide for your device).

    Regards,

    Richard

  • Richard Poley said:

    If you need to block interrupts only for very short intervals the simplest and safest way is to use the INTM bit.  You could mask the core interrupt with IER if you want to keep other (innocuous) interrupts active while you do the read. 

    You could do it by manipulating the PIEIERx registers, but there is a strict procedure which needs to be followed (see the PIE chapter in the User's Guide for your device).

    Regards,

    Richard

    Disable PIEIERx registers also involve disabling INTM and I think that is a bad idea in a realtime system.

    So this is a save way to do it?

    IER &= (~intNumber);

    Do  memory read

    IER |= intNumber;

    Thanks!

  • Yes, you can manipulate the IER register to block selected interrupts during your memory read.

    Regards,

    Richard