Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
stm32:peripherals:usart [2016/03/07 07:51] – [Transmitting Data] feur | stm32:peripherals:usart [2022/12/28 08:39] (current) – ruan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Universal | + | ====== Universal Asynchronous Receiver Transmitter ====== |
- | The USART offers a very flexible, full-duplex, | + | The UART offers a very flexible, full-duplex, |
Including IrDA and modem operations (CTS/RTS). \\ | Including IrDA and modem operations (CTS/RTS). \\ | ||
Line 12: | Line 12: | ||
* 8- and 9 bit word length. | * 8- and 9 bit word length. | ||
* DMA and interrupt support. | * DMA and interrupt support. | ||
- | \\ | ||
- | |||
- | ===== Programming Example ===== | ||
- | |||
- | ==== Setup GPIO ==== | ||
- | |||
- | <code c> | ||
- | #include " | ||
- | |||
- | RCC-> | ||
- | |||
- | /* Configure GPIO pin A.0 and A.1 in alternate function mode. */ | ||
- | GPIOA-> | ||
- | GPIOA-> | ||
- | |||
- | GPIOA-> | ||
- | GPIOA-> | ||
- | |||
- | GPIOA-> | ||
- | GPIOA-> | ||
- | </ | ||
- | \\ | ||
- | |||
- | ==== Transmitting Data ==== | ||
- | |||
- | <code c> | ||
- | #include " | ||
- | |||
- | RCC-> | ||
- | |||
- | UART4-> | ||
- | UART4-> | ||
- | |||
- | UART4-> | ||
- | UART4-> | ||
- | while(!(UART4-> | ||
- | UART4-> | ||
- | while(!(UART4-> | ||
- | </ | ||
- | \\ | ||
- | |||
- | ==== Receiving Data ==== | ||
- | |||
- | <code c> | ||
- | #include " | ||
- | |||
- | RCC-> | ||
- | |||
- | UART4-> | ||
- | UART4-> | ||
- | |||
- | UART4-> | ||
- | while(!(UART4-> | ||
- | data_received = UART4-> | ||
- | </ | ||
\\ | \\ | ||
===== Configuration Registers ===== | ===== Configuration Registers ===== | ||
- | ==== CRx ==== | + | ==== USART_CR1 - Configuration register 1 ==== |
- | + | ||
- | === CR1 === | + | |
- | + | ||
- | Configuration register 1 | + | |
\\ {{usart_reg_cr1.svg}} \\ \\ | \\ {{usart_reg_cr1.svg}} \\ \\ | ||
Line 96: | Line 37: | ||
\\ | \\ | ||
- | === CR2 === | + | ==== USART_CR2 - Configuration register 2 ==== |
- | + | ||
- | Configuration register 2 | + | |
\\ {{usart_reg_cr2.svg}} \\ \\ | \\ {{usart_reg_cr2.svg}} \\ \\ | ||
Line 109: | Line 48: | ||
\\ | \\ | ||
- | ==== BRR ==== | + | ==== USART_BRR - Baud rate register |
- | + | ||
- | Baud rate register | + | |
\\ {{usart_reg_brr.svg}} \\ \\ | \\ {{usart_reg_brr.svg}} \\ \\ | ||
Line 122: | Line 59: | ||
===== Status Register ===== | ===== Status Register ===== | ||
- | ==== SR ==== | + | ==== USART_SR - Status register |
\\ {{usart_reg_sr.svg}} \\ \\ | \\ {{usart_reg_sr.svg}} \\ \\ | ||
Line 137: | Line 74: | ||
===== Data Register ===== | ===== Data Register ===== | ||
- | ==== DR ==== | + | ==== USART_DR - Data register |
\\ {{usart_reg_dr.svg}} \\ \\ | \\ {{usart_reg_dr.svg}} \\ \\ | ||
Line 145: | Line 82: | ||
\\ | \\ | ||
- | ===== Legend ===== | ||
- | \\ {{legende.svg}} \\ \\ | + | ===== Programming Example ===== |
+ | |||
+ | ==== Setup GPIO ==== | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | RCC-> | ||
+ | |||
+ | /* Configure GPIO pin A.0 and A.1 in alternate function mode. */ | ||
+ | GPIOA-> | ||
+ | GPIOA-> | ||
+ | |||
+ | GPIOA-> | ||
+ | GPIOA-> | ||
+ | |||
+ | GPIOA-> | ||
+ | GPIOA-> | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | ==== Transmitting Data ==== | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | RCC-> | ||
+ | |||
+ | UART4-> | ||
+ | UART4-> | ||
+ | |||
+ | UART4-> | ||
+ | UART4-> | ||
+ | while(!(UART4-> | ||
+ | UART4-> | ||
+ | while(!(UART4-> | ||
+ | UART4-> | ||
+ | while(!(UART4-> | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | ==== Receiving Data ==== | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | RCC-> | ||
+ | |||
+ | UART4-> | ||
+ | UART4-> | ||
+ | |||
+ | UART4-> | ||
+ | while(!(UART4-> | ||
+ | data_received = UART4-> | ||
+ | </ | ||
+ | \\ |