What needs to be aware of when operating a register at an interrupt handler?

Post Reply
a_ziliu
Posts: 116
Joined: 20 Mar 2017, 10:52

27 Mar 2017, 14:56

Before and after entering an interrupt handler, if you have to operate the same register, there will be problems regarding the sequence of operating the register.

For example, when operating the register GPIOA_OUT:
The different bits of GPIOA_OUt control different pin outputs, e.g. GPIOA_OUT [0] controls the output of PA.0 and GPIOA_OUT [1] controls the output of PA.1. If the main function writes 0x1 to GPIOA_OUT to control PA.0 output high level, an interrupt is entered. At the interrupt handler, write 0x2 to GPIOA_OUT, and control PA.1 to output high level; at this time, GPIOA_OUT = 0x2. When exiting the interrupt handler and returning to the main function, the action of writing 0x1 to GPIOA_OUT will be completed so that GPIOA_OUT = 0x1, causing the PA.1 to output high level to be overwritten at the interrupt handler, resulting in the problem regarding the operation sequence of the register.

To avoid the problem that the interrupt handler and the program operating a register at the same time, you can set a flag in the interrupt handler and determine the flag in the main function first before operating the register.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest