224. Blinky does not blink, what now?
Blinking a LED is always the first program in the realm of microcontrollers, whether it is a novice project, or even when a seasoned professional brings up a new hardware. Rather than printing a message, blinky is the "Hello, world!" program of microcontrollers.
It requires to:
- have the microcontroller powered and running
- have means to program ("flash") - and optimally, on-chip debug - the microcontroller
- know the principial clock frequency and use it in a rough manner in a loop-delay
- perform whatever it takes to have one pin (the one to which the LED is connected) set up as output
- in an infinite loop, set the pin to output 0, call the delay, set the pin to output 1, call the delay
But what to do if the LED does not blink? The following steps should be tried:
- reduce unknowns: start with a "known good" hardware such as a Nucleo or a Disco board
- there is also a chance, that for such board, there are working examples available - they may be not in the required style, but at least may provide a starting point. If a binary is also available, that may also make sure that the chosen programming ("flashing") method works properly.
- make sure the LED is properly connected to the selected pin; make sure that you are using the pin to which the LED is connected;
make sure there is no other on-board resource, which could interfere, connected to the same pin
- if on-chip debugging is active, try to stop execution and toggle the pin by directly writing to relevant registers (GPIO_ODR) in debugger
- make sure the delay is not too long or too short - change the number of loops in powers of 10
- make sure there is a delay both after setting the pin to 1 and after setting it to 0