UART Transmitter
The heart of the transmitter is transmit shift register, where parallel data is converted to serial data sequences.
The shift register obtains its data from the transmit data register or TDR (Figure 1). The TDR is loaded with data by the software. The data is not loaded to the shift register until the stop bit has been transmitted from the previous load. As soon as the stop bit is transmitted, the shift register is loaded with new data from the data register.
Steps to set-up the UART transmission:
The steps of setting up the UART transmission are the same for all microcontrollers. The only thing is if you have a different microcontroller, then register names and bit details will vary. The procedure to do UART transmission is as follows:
1.Program the M bit in the USART_CR1 register to define the word length. You have options for 8 bits and 9 bits, which is a word length of useful data.
2. Program the number of stop bits in the USART_CR2 register.
3. Select the desired baud rate using the USART_BRR register. Before baud rate selection, you have to visit the table shown in Figure 2, and you must know the peripheral clock frequency because the peripheral frequency puts a limit on the maximum baud rate that can be generated.
4. Set the TE bit in the USART_CR1 to enable the transmit block.
5. Enable the USART by writing the UE bit in USART_CR1 register to 1, where UE stands for USART Enable.
6. Now, if the TXE flag is set, then write the data byte to send in the USART_DR register. Repeat this for each data to be transmitted.
7. After writing the last data into the USART_DR register, wait until the TC flag is set to 1 (TC=1), which indicates that the transmission of the last frame is complete.
8. Remember, after data transmission, if software wants to disable USART or UART peripheral, then it has to do it after TC bit is set, where TC stands for transmission complete flag.
In the following article, let’s see UART Receiver.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1