In the last evaluation, PWM used a lot of CCU functions, which is roughly equivalent to the timer module in other MCUs. This time, let's take a look at the use of the timer and try the use of interrupts. Of course, it would be meaningless to turn on the lights at this time, so the content of serial communication is added. After all, in the absence of a display, the serial port is the most important means of interaction. The main purpose of this evaluation is to achieve the timing of sending strings to the host computer through the serial port. On the one hand, the three apps of timer, interrupt and serial port can be evaluated. At the same time, after adding sensors to this framework in the later stage, it can become a simple serial port measurement module. In the following evaluation, the addition and configuration of the app will not be introduced in detail. The specific process is similar and can be found in the last evaluation. This project mainly includes the following 3 apps.
- UART: responsible for serial communication.
- TIMER: responsible for timing and generating timing events.
- INTERRUPT: Responsible for handling timing events.
First, create a new CE project, and then add the uart app. The default configuration of uart is 19200,8,N,1. You can leave the others unchanged for now. Then assign pins to uart, P1.5/Tx and P1.4/Rx. In the default configuration, transmission is implemented by interruption, and the user code only needs to call the UART_Transmit function. Note that before modifying the user code, remember to generate the code so that the initialization code of the configured peripherals can be completed.
The user code is modified in main.c. In this function, DAVE_Init() is first called to complete the initialization work. After completing the initialization status judgment, the user code can be written. Our preliminary code is very simple, which is to send two strings directly. Call UART_Transmit before entering while(1U). The code and effect are shown in the figure below.
Figure 1 Serial port sending effect diagram Perhaps careful students will ask, why should it be written in the same line? Can't it be divided into two lines? Yes, it is not possible to write two lines directly, and only the first line can be received. I think it is because the first line has not been sent yet, and the following sending request will not be ignored. It is necessary to make a judgment in the middle to determine whether the sending is completed before the next sending can be used. As shown in the figure below, if there is no while(UART_IsTxBusy(&UART_PC)); in the middle, the serial port can only receive the first line of the string.
Figure 2 Waiting for the serial port to complete sending Next, let's look at the timing function. We can directly use the timer app and set its working cycle to 1s (1000000 usec), and check the time interval event in the event settings.
Figure 3 Timer configuration diagram Timer allows the generation of timing events, and you also need to add an interrupt APP to complete event reception and processing. The configuration of this app is very simple, mainly to specify the interrupt processing function name, which we call Time_Interval_Event here.
Figure 4 Interrupt configuration diagram We noticed that there is a warning in the above figure, which means that this interrupt also needs to be configured with the interrupt source, which is done in the HW signal connection. As shown in the figure below
Figure 5 HW signal connection configuration diagram Finally, generate code to get the initialization code of all peripherals. Of course, user functions also need to be implemented through code. Open the main.c file and add the following timer interrupt code at the end to print a string to the serial port every 1s. Through the variable i to control, hello eeworld and hi infineon appear alternately. The timer interrupt processing function is shown in the figure below.
Figure 6 Timer interrupt processing function Summary: In this evaluation, the timer is used in conjunction with the interrupt to implement the function of sending strings to the host computer through the serial port at a fixed time. It can be found that the code development in DAVE uses the UI interface to configure the peripheral properties, which simplifies the initialization process, allowing users to focus on application code development and greatly improve development efficiency.
This content was originally created by EEWORLD forum user johnrey. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source