Experiments with the STM32F407VGT6 MCU.
Program that, in rotation, turns on and off all the following LEDs on the STM32F4 MCU:
- user LD3: orange LED is a user LED connected to the I/O PD13 of the STM32F407VGT6
- user LD4: green LED is a user LED connected to the I/O PD12 of the STM32F407VGT6
- user LD5: red LED is a user LED connected to the I/O PD14 of the STM32F407VGT6
- user LD6: blue LED is a user LED connected to the I/O PD15 of the STM32F407VGT6
The following examples show how to use interrupts to toggle a LED every time we press the user-programmable blue button, which is connected to the PA0 pin:
- bare-metal programming
- using the ST HAL
- using CubeMX
Prepare a platform with three interrupt sources (I1, I2, I3) each connected to a LED. Write the corresponding interrupt response handlers such that:
- upon detection of an interrupt signal Ix, 1<= x <= 3, a timer is started
- if within a predetermined time period T no other interrupt signal is received the LDx is switched on
- if other interrupts are detected within the predetermined term, all the LEDs corresponding to the interrupts detected will be switched on simultaneously at the end of T
Friends who have studied C should know the standard library functions printf() and scanf(), the former for printing information to the console, and the latter for reading characters from the keyboard to the program. If printf() is called in the program of the microcontroller, where will it be displayed? The answer is unknowable, because the microcontroller does not have a console, but we can use its peripherals to implement printf(), such as LCD or serial port (the serial port is then connected to the computer to display the print information). The serial port is basically the majority of microcontrollers, and the LCD is not necessarily, so we usually use the serial port to print content. So as long as it is a serial port microcontroller, is it possible to print the information by calling printf()?
Two exercises for managing the DMA, in polling and in interrupt.
Application which:
- set up a GP timer and configure CHx to be input captured on every rising edge of the RCC External Clock Source
- read (via DMA) the CCRx register and save it to variable T1 on the first edge, on second edge read CCR1 and save it to T2. And now, the input signal's period is T2 – T1, and therefore, the frequency is easily calculated from 1/period
- configure USART in Async mode and print the calculated frequency to the serial port terminal
Program that acquires data from the built-in temperature sensor using interrupts and:
- if the detected temperature exceeds 28° C activates the red LED
- if the temperature drops below 18° C the blue LED lights up
- for intermediate temperatures the green LED stays on The program also calculates the time taken by the interrupt response routine generated by the ADC circuit.