[STM32-MATLAB] simulink uses serial port for data stream transmission

Simulnk receives, STM32 sends

1. Search for the Serial Configuration module and set the parameters as shown in the figure
insert image description here
2. Search for the Serial Receive module and set the parameters as shown in the figure. Among them, Data size is the number of data bytes. Take 3 bytes as an example, select uint8 for Data Type
insert image description here
3. STM32 set to send three bytes, respectively 250, 1, 100

uint8_t txtemp[3] = {
    
    250,1,100};
HAL_UART_Transmit(&huart4,txtemp,3,100);

4. Experimental results
insert image description here

Simulnk sends, STM32 receives

1. Select 3 constant values, the type is uint8, select MUX, the input is 3port, connect
insert image description here

2. Select the Serial Send module, select the serial port and connect it.
insert image description here
3. Set the receiving buffer array on the STM32 end and download the program

u8 rectemp[3];
HAL_UART_Receive(&huart4,rectemp,3,100);

4. Simulink running program

Guess you like

Origin blog.csdn.net/qq_39587650/article/details/119914187