|
|
API functions used
|
|
|
- HAL_UART_Transmit and
|
|
|
- HAL_UARTEx_ReceiveToIdle_IT
|
|
|
|
|
|
Assumptions
|
|
|
- the transmission is message by message of variable lengths, not a continous data stream
|
|
|
- there is a max. message length such that we can used fixed size global buffers.
|
|
|
|
|
|
|
|
|
Ingredients
|
|
|
===
|
|
|
Board: Nucelo-STM32L432KC
|
|
|
UART1 is used for transmission, sending data.
|
|
|
UART2 is used for receiving the data with an interrupt handler.
|
|
|
Both interfaces could be used on the same board or on two different boards.
|
|
|
When two boards are used, both GND lines must be connected!
|
|
|
- Board: Nucelo-STM32L432KC
|
|
|
- UART1 is used for transmission, sending data.
|
|
|
- UART2 is used for receiving the data with an interrupt handler.
|
|
|
- Both interfaces could be used on the same board or on two different boards.
|
|
|
- When two boards are used, both GND lines must be connected!
|
|
|
|
|
|
UART2 is already connected on the board to the VCP (USB) UART of the ST-LINK.
|
|
|
We use UART2_TX for logging output and route UART2_RX to another available pin:
|
... | ... | @@ -14,6 +23,7 @@ We use UART2_TX for logging output and route UART2_RX to another available pin: |
|
|
PA2 ------> USART2_TX
|
|
|
PA3 ------> USART2_RX
|
|
|
```
|
|
|
For other boards/setups, adjust these settings accordingly.
|
|
|
|
|
|
Create a new STM32CubeMX project
|
|
|
===
|
... | ... | @@ -115,9 +125,8 @@ Trigger the very first receive right above the main while loop: |
|
|
{
|
|
|
```
|
|
|
|
|
|
Connect the UART2_RX pin to the UART1_TX pin and restart the code.
|
|
|
The LD3 LED should start blinking.
|
|
|
It toggles with each reception.
|
|
|
Connect the UART2_RX pin to the UART1_TX pin, rebuild, and restart the code.
|
|
|
The LD3 LED should start blinking, it toggles with each message received.
|
|
|
The logging output should look like:
|
|
|
```
|
|
|
12 -> 12
|
... | ... | |