2

Currently working on msp430fr5969. I have multiple interrupt like SPI, I2C, Timer and the requirement is the SPI protocol is the highest priority. However, according the datasheet, the priority of I2C(eUSCI_B0) higher than SPI(eUSCI_A1) and cant change the interrupt priority.

Link: http://mikrokontroler.pl/wp-content/uploads/pliki/msp430fr5969.pdf (page 21).

How I can get into SPI interrupt as fast as possible while I2C process?

I got stuck while I2C's reading and It has a data sent from another MCU. the MCU notify a timeout in that case. Its rarely but I want to fix it.

Note: use SPI to communicate with another MCU so its importance data. Use I2C for readding information from sensor.

thanhSon
  • 21
  • 4

2 Answers2

2

The interrupt priorities matter only if two interrupt flags are set before the CPU is able to handle one of them, and the CPU has to decide which one to handle first. In practice, this almost never happens.

When an interrupt handler executes, all other interrupts are blocked (GIE is cleared by default), regardless of priority. This means that when the I²C interrupt handler is currently executing and the SPI interrupt happens, the SPI handler begins execution only after the I²C handler has finished.

To execute the SPI handler with a high priority, you have to ensure that all other interrupts do not block it, at least not for a long time. This is typically done by those interrupt handlers just setting a flag that indicates that the device needs attention, and then handling these conditions in the main loop of your application.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • The problem is we can NOT modify the priority of interrupt in msp430fr5969. So I just hope on reading and writing I2C algorithm. It maybe reduce the priority. – thanhSon Oct 07 '18 at 10:30
  • 1
    As I have just said, the interrupt priorities do not matter for your problem. For how to solve this, see the last paragraph of the answer. – CL. Oct 07 '18 at 12:37
0

You could technically reenable gie withing other interrupts to enable interrupt nesting. This way you can manage interrupts execution order by adding some logic as preamble to interrupts. Personally I'd rather avoid it and keep it as last resort. Try to keep other interrupts code short, manage logic outside interrupts, and if it is not enough try to disable other interrupts while you expect the critical interrupt to come (if it is possible).

Damiano
  • 698
  • 7
  • 19