Knock

STM32 EXTI Interrupt Handler Exercise

Task

A smart front door has a knock sensor. Knock once and the hall light comes on. Knock again and it goes off. Each knock is a short pulse on PA0. EXTI is the part of the chip that watches pins for a change of level. The given knock_init() makes each pulse raise a request on EXTI's line 0.

The core is the part of the chip that runs your code. An interrupt makes it pause main and run a function called a handler. Flip the hall light on PA5 from an interrupt, once per knock, for as long as the board runs: knock 1 -> light on; knock 2 -> light off; and so on Write line 0's handler, EXTI0_IRQHandler, which calls answer_knock(), and let line 0's requests reach the core. The registers and bit fields are on the Datasheet tab.

Circuit

Circuit: U2, the knock sensor on the door, pulses PA0 of U1 STM32F4 once per knock; PA5 drives R1 330R into D1, the hall light, to ground; a TP1 logic analyzer probe sits on the PA5 wire

Pass condition

Each knock flips PA5 once, and EXTI0_IRQHandler runs as an interrupt once per knock. Calling the handler from main does not count.

Expected trace for three knocks: PA0 pulses at 10, 25 and 45 ms, the core runs EXTI0_IRQHandler once at each knock, and PA5, the hall light, goes high at the first knock, low at the second and high again at the third

Notes

The knock sensor drives PA0 high for 1 ms per knock while your program runs. The given code stays as it is.

Related challenges

Loading the interactive arena.