Why Are Interrupts Better Than Polling?
In embedded systems, peripherals constantly generate events. A UART receives a byte. A timer expires. A GPIO pin changes state. An ADC conversion completes. The processor needs to respond to these events. There are two common approaches: Polling Interrupts At first, polling looks simple. But interrupts usually provide a more efficient way for the CPU to respond to asynchronous events. What Is Polling? In polling, the CPU repeatedly checks whether an event has occurred. For example: while (1) { if (UART_RX_READY) { read_uart_data(); } } The processor keeps asking the UART: "Did data arrive?" If no data has arrived, the CPU checks again. And again. And again. Imagine UART data arrives only once every 100 ms. During those 100 ms, the CPU may check the same status flag thousands of times even though nothing has happened. That CPU time could have been used for something else. What Changes With Interrupts? With interrupt...