STM32 UART Lecture 10 – UART Receiver

  • Post author:
  • Post category:Blog

 

UART Receiver

 

 

During a UART reception, the data shifts in least-significant bit through their RX pin to the receive data register via the shift register, as shown in Figure 1. The heart of the receiver is the receive shift register, where the serial sequence is converted to a parallel word.

UART Receiver
Figure 1. Data shifting through the RX pin.

After sampling the RX pin for the STOP bit, the received data bits in the shift register are transferred to the receive data register or RDR.

 

Steps for UART data reception:

1. Program the M bit in the USART_CR1 to define the word length. Both transmitter and receiver must agree upon this word length.

2. Program the number of STOP bits in the USART_CR2 register.

3. Select the desired baud rate using the USART_BRR register. The baud rate of your transmitter and receiver must be the same.

4. Enable the USART by writing the UE bit in USART_CR1 register to 1.

5. Set the RE bit in the USART_CR1 register, which enables the receiver block of the USART peripheral. Once the receiver block is enabled, it starts searching for the START bit.

6. When the character is received, wait until the RXNE bit is set. If the RXNE bit is set, it indicates that the shift register’s content is transferred to the read data register. In other words, the data has been received and can be read by the software. Instead of polling on the RXNE flag, you can also get an interrupt whenever the RXNE flag is set. For that, you have to enable the RXNEIE control bit in the control register.

7. Clearing the RXNE bit is performed by the software read to the USART data register. The RXNE bit must be cleared by reading the data register before the end of the reception of the next character to avoid an overrun error. 

The timing diagram in Figure 2 shows how typically the reception takes place. When you enable the receiver block of the USART by enabling RE bit in the control register, the receiver engine starts sampling the RX pin to detect the START bit. When it detects the START bit, the reception begins, and when it detects the STOP bit, the reception of one frame completes.

 

UART Receiver
Figure 2. Timing diagram for data reception.

 

After that, the data in the shift register will be loaded to read the data register (Figure 3), and the RXNE flag will be set. When the RXNE flag is set, it is sure that data is ready to read from the data register.

UART Receiver
Figure 3. Loading data into the read data register from the shift register.

 

The software can then read out the data register (Figure 4), which also clears out the RXNE flag that was set.

Reading data from the data register.
Figure 4. Reading data from the data register.

 

Like that, for every complete frame reception, the RXNE flag will be set, and firmware has to read it (Figure 5).

Figure 5. Timing diagram for data reception
Figure 5. Timing diagram for data reception (more than one frame).

When there is no more data, the line will be held high, which is the idle state of the line (Figure 5). The receiver block of the UART peripheral will keep sampling the RX line to detect the next START bit, even if there is no data on the RX line, which surely consumes power. Therefore, after you are done with RXing of data, it’s always better to turn off the receiver block as per your need if you want to save some power.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply