This post was last edited by jinglixixi on 2021-1-13 23:10
I participated in a MicroLab evaluation activity some time ago. After some efforts, I finally obtained the permanent use authorization. By combining it with the STM32L452 development board, it can easily form a distributed application system. Compared with using LABVIEW, it is still very convenient to use and occupies very little space. The only drawback is that it cannot generate an exe file that can be run independently, otherwise it would be perfect.
Taking the creation of an interface with a progress ball, a digital tube and a thermometer as an example, it is only necessary to drag and drop the three display components into the component canvas, and then adjust the size and placement of the components. The effect is shown in Figure 1.
Figure 1 Component interface design
During operation, it can use the serial port monitoring function of MicroLab to receive protocol data packets sent by the lower computer, that is, the STM32L452 development board, and then drive the status update of the component. The effect is shown in Figure 2 and Figure 3.
Figure 2 Operation effect
Figure 3 Serial port monitoring receiving data
For the STM32L452 development board, there are two main contents involved in the realization of functions. One is naturally the serial communication function, which must be able to send out control data; the other is to transplant the function of generating protocol data packets.
For the first point, UART4 is used here, and the pin occupied is PC.10 of CN7 to send data. Since the data sent is byte data, a suitable array needs to be defined to temporarily store the data.
The corresponding serial port initialization is defined as:
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
The program segment that calls the relevant protocol function to send driver data is:
while (1)
{
//进度球
updateCanvas(WATERLEVER, 0, (char *)&x, sizeof(float));
HAL_Delay(500);
//数码管
updateCanvas(LCDNUMBER, 0, (char *)&x, sizeof(float));
HAL_Delay(500);
//温度计
updateCanvas(TEMPMETER, 0, (char *)&x, sizeof(float));
HAL_Delay(500);
x += 3;
x++;
y += 3;
if(x>=100)
{
x = 0;
}
if(y>=100)
{
y = 0;
}
}
Taking the updateCanvas() function as an example, the content of sending data using the serial port is as follows:
void updateCanvas(COMPONENT_TYPE componenttype, unsigned short componentnumber, char * data, unsigned short datalen)
{
static char tbuffer[TBUFFERSIZE];
static short size;
packProtocol(ORGANIZATION, SECTION, DATAPOINT, componenttype, componentnumber, NONE_MSG, data, datalen, tbuffer, &size);
HAL_UART_Transmit(&UartHandle, (uint8_t*)tbuffer, size, 5000);
}
The communication connection of the STM32L452 development board is shown in Figure 4, which is formed by connecting the development board with the USB to TTL module. Before connecting to the MicroLab of the host computer, the test results through the serial port assistant are shown in Figure 5.
Figure 4 Communication connection
Figure 5 Serial communication test
Generally speaking, the STM32L452 development board is a low-power, easy-to-develop and use development board. Due to the product line built over a long period of time and the development habits developed, there is already a sense of familiarity when using ST products. Relatively speaking, in a development process, this can bring development effectiveness, and naturally using the STM32L452 will also produce this efficiency.