Briefly describe how to write programs using Harmony's dynamic drivers and state machines

Microchip Curiosity PIC32MZEF Learning Tutorial: Using Harmony's Dynamic Drivers and State Machines to Write Programs The previous article introduced the UART transmit and receive data operations, which are based on peripheral libraries, rather than Harmony's dynamic drivers, and no state machine mechanisms. This article will introduce how to use Harmony's dynamic drivers and state machines to write programs. In fact, the state machine is quite simple, that is, define which states may occur in advance, and then perform different processing according to different states in the main loop. This is also a commonly used method in the project.

Note that the Dynamic driver object needs to have an Open action to create a Handle. All subsequent operations use Handle to represent this driver object. All dynamically driven interrupts are used in the form of a registration callback function. They do not need to be added to system_init, and there is no need to clear the interrupt flag by itself. The driver has already completed itself.

Another point to note is that the serial port enters the interrupt after receiving one byte. If you do not use Read to receive it, then you will not be able to enter the interrupt anymore, and there will be only one interruption. Therefore, do not interrupt it. Time-consuming operation to avoid not receiving data in time, resulting in incomplete data.

It is also convenient to use the structure in the app.h file to define the relevant variable structure to be used by the state machine and the UART.

1

After writing the application in app.c, including the header file, the initialization function is written. The initialization here is not the underlying initialization, but the initialization of the UART variables and the creation of the handle. The first step is to initialize (open a client), and then judge the created client is valid, if it is valid, create an interrupt callback function, the contents of the interrupt program can be written directly in the callback function.

2

Write the interrupt callback function content program, receive a data and store it in the data buffer, and set the receive completion flag.

3

Send data function, send in query mode

4

Write the Uart_Task() function, where the state is processed here, initialized when the state is initialized, then enters the receive data state, receives the data and sends back the data, and displays the number of bytes received on the OLED.

5

Uart_Task() is called cyclically in APP_Tasks() to process the received data.

6

Compile, download the program to the development board, open the serial port software test

7

OLED display effect

092736phxohksn4x4kxd44

0.50mm Board To Board Connector

0.50Mm Board To Board Connector,0.5Mm Vertical Board To Board Connector,0.5Mm Single Row Smt Connector,Dual Row 0.50Mm Vertical Type Connector

Shenzhen CGE Electronic Co.,Ltd , https://www.cgeconnector.com

This entry was posted in on