ADC-Temperatur,LCD & USART-Connection on STM32L0x3
The internal ADC temperature can be shown by pressing the UP-Button.
Based on the temperature measurements from the STM will print the recalculated temperature in Celsius on the HD44780 display.
Futhermore, the display changes the background-color according to the measured temperature.
Moreover, the STM sends the measured temperature via serial communication (USART) back to PC (USB2.0-Port).
By pressing the DOWN-Button the measurment stops and an ASCII Input can be recieved via USART which will displayed on the LCD.
The temperature is read every 5 seconds via the ACD1 bus using the Basic Timer 6 and returned serially via the USART interface and displayed on the LCD (HD-4780). Depending on the temperature, the backlight of the LCD is adjusted. The user can choose between two modes by pressing the LCD buttons.
- Mode 0, Button UP: Temperature measurement with output on the LCD and via the serial interface.
- Mode 1, Button DOWN: Text received serially and output on LCD By default the temperature measurement is preselected. By pressing the SELECT button the user gets an overview of the available modes for 1.5s. If the user does not change to another mode, the overview disappears and the current mode is used again.
Figure 1 shows the structure of the program. The compiler starts at the blue highlighted starting point. First, the header files are included, the necessary constants are defined, and the global variables and function prototypes are declared. In the last two steps the functions and handlers of the interrupt service routines to be used are initialized and the main is started.
This is followed by an output on the LCD relevant to the user on how to operate the program. This is as follows:
- temp. measurement & serial writing
- Press SELECT to change mode
- press UP for Temp. measurement
- press DOWN for Serial Writing
- temp. measurement set as default
Temperature measurement via ADC starts by setting AD_START bit in the ADC Control Register. After starting the measurement, the infinite while loop starts, where two modes can be selected by pressing the UP, DOWN and SELECT buttons of the HD44780. By default, the temperature measurement mode is selected. In this mode, the measured value is first output serially to the programming device when the ADC ISR is called, and is also displayed on the LCD. The color of the backlight of the LCD is adapted to the measured temperature only in this mode. By pressing the SELECT button, the user is shown the mode selection again. Pressing the DOWN button interrupts the current temperature measurement (ADSTP bit in the ADC Control Register is set) and serial reception of text input is activated. The received text is displayed on the LCD.
The temperature measurement starts as soon as the microcontroller is connected to the PC via the USB interface. First, a sequence of notifications runs through on the LCD, briefly explaining the operation to the user.
The temperature measurement preselected as the standard mode then starts automatically. The actual temperature measurement is preceded by a calibration process and the activation of the ADC. These steps will also be communicated to the user on the LCD, as shown below.
The images below show the serial output and the display of the temperature on the LCD. The ambient air of the microcontroller was strongly warmed up for demonstration purposes, a temperature increase from 21°C to 26°C can be seen. On the LCD, the background color changes from yellow to red when the limit of 25.1°C is exceeded. The temperature thresholds for the color change:
- -15.0 C° to + 5.0 C° blue
- +5.1 C° to +15.0 C° yellow
- +5.1 C° to +25.0 C° orange
- Above +25.1 C° red
By pressing the UP button, the serial reception is aborted and the temperature measurement starts again. On the LCD is signaled that the temperature measurement (mode 0) is activated.
When the temperature measurement is activated for the first time, ADC calibration and ADC activation (re-initialization) are performed and displayed on the LCD. The Re-initialization is only performed when switching from mode 1 to mode 0.
At the end, the temperature is displayed on the LCD as usual and returned serially, and the LCD backlight is adjusted according to the temperature.
Done.
C & Assembly