1
Overview
For STM32, the ST official documentation and application notes mention this. Below, I will briefly explain the hardware automatic baud rate detection content based on the documentation.
2
STM32 Hardware Automatic Baud Rate Detection
1. Applications of ABR
-
When the communication speed of the system is unknown in advance.
-
When the system is using a relatively low-accuracy clock source, this mechanism allows for obtaining the correct baud rate without measuring clock deviations.
In STM32, only certain series support hardware automatic baud rate detection; earlier series do not support it (such as F1 F4), while later series, including the latest STM32H7 and G0 series, do support this function.
Of course, for STM32 series devices with built-in ABR, not all instantiated USART interfaces support automatic baud rate detection.
3. Automatic Baud Rate Detection Mode
The automatic baud rate detection function on STM32 products has various modes based on different character patterns:
-
Mode 0: Any character starting with a “1” bit
-
Mode 1: Any character starting with 10xx pattern
-
Mode 2: 0x7F
-
Mode 3: 0x55
Note:
1. In all ABR modes, the baud rate will be detected multiple times during synchronous data reception, and each detection value will be compared with the previous one.
4. Code Configuration
The relevant code is provided by the official based on the (Standard Peripheral Library, HAL Library) reference examples, such as F0 Standard Peripheral Library reference code:
static void AutoBauRate_StartBitMethod(void){ /* USART enable */ USART_Cmd(EVAL_COM1, ENABLE);
/* Configure the AutoBaudRate method */ USART_AutoBaudRateConfig(EVAL_COM1, USART_AutoBaudRate_StartBit);
/* Enable AutoBaudRate feature */ USART_AutoBaudRateCmd(EVAL_COM1, ENABLE);
/* Wait until Receive enable acknowledge flag is set */ while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_REACK) == RESET) {}
/* Wait until Transmit enable acknowledge flag is set */ while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TEACK) == RESET) {}
/* Loop until the end of Autobaudrate phase */ while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_ABRF) == RESET) {}
/* If AutoBaudBate error occurred */ if (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_ABRE) != RESET) { /* Turn on LED3 */ STM_EVAL_LEDOn(LED3); } else { /* Turn on LED2 */ STM_EVAL_LEDOn(LED2);
/* Wait until RXNE flag is set */ while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_RXNE) == RESET) {}
/* Wait until TXE flag is set */ while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET) {}
/* Send received character */ USART_SendData(EVAL_COM1, USART_ReceiveData(EVAL_COM1));
/* clear the TE bit (if a transmission is on going or a data is in the TDR, it will be sent before efectivelly disabling the transmission) */ USART_DirectionModeCmd(EVAL_COM1, USART_Mode_Tx, DISABLE);
/* Check the Transfer Complete Flag */ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) {} }
/* USART Disable */ USART_Cmd(EVAL_COM1, DISABLE);}
5. ABR Error Calculation
The frequency of the USART clock source must be compatible with the expected communication rate:
-
At 16 times oversampling, the baud rate ranges from fCK/65535 to fCK/16.
-
At 8 times oversampling, the baud rate ranges from fCK/65535 to fCK/8.
The baud rate error depends on the USART clock source, oversampling method, and ABR mode.
Where:
-
The expected baud rate depends on the sending device;
-
The actual baud rate is the baud rate determined by the USART receiver using the automatic baud rate detection operation.
6. Error
The following figure is from official test data, based on: error calculation of ABR at fCK = 72 MHz, with an expected baud rate of 115200 bits/s.
However, since the error between the expected baud rate and the actual baud rate is less than 1%, the results of all modes are normal.
END
Source: Embedded Column
→ Follow to avoid getting lost ←
Leave a Comment
Your email address will not be published. Required fields are marked *