STM32 USART Lecture 4 – USART Driver API: USART Init

 

USART Driver API: USART Init

 

 

Now let’s implement USART_Init API.

Steps:

1. Download the file attached in the resource section, and the file name is USART_Init.c (Figure 1).

USART Init
Figure 1. USART_Init.c file.

 

2. Copy the function in Figure 1 into the driver.c file and resolve all the TODOs. You can see TODO is mentioned at many places (Figure 2), and it is an indication for you to replace that with the actual code.

USART Driver API: USART Init.
Figure 2. TODOs to be replaced.

 

For example, in Figure 2, you have to replace the first TODO with the code to enable the clock for a given USART peripheral. If you don’t remove it, then the compiler will issue an error. Therefore, you have to remove that TODO, and instead of that, you have to write the actual code. Try to resolve all the TODOs, and that will complete the USART_Init() function. 

There are several comments in the attached file. Read the comment, understand it and then try to code according to that.

 

3. At the end, you have to configure the baud rate (Figure 3). This part will be coded after discussing the baud rate generation.

USART Driver API: USART Init.
Figure 3. Baud rate configuration section.

In the following article, let’s see USART Driver API: Tx and Rx assignment.

 

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.