Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
stm32:peripherals:usart [2016/03/07 07:50] feurstm32:peripherals:usart [2022/12/28 08:39] (current) ruan
Line 1: Line 1:
-====== Universal (Synchronous/AsynchronousReceiver Transmitter ======+====== Universal Asynchronous Receiver Transmitter ======
  
-The USART offers a very flexible, full-duplex, industrial standard, serial receiver / transmitter. \\+The UART offers a very flexible, full-duplex, industrial standard, serial receiver / transmitter. \\
 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 "reg_stm32f4xx.h" 
- 
-RCC->AHBENR[0] |= (0x1 << 0u);       /* Enable GPIOA clock */ 
- 
-/* Configure GPIO pin A.0 and A.1 in alternate function mode. */ 
-GPIOA->MODER &= ~(0xf << 0u);        /* Clear existing mode bits 0 to 3. */ 
-GPIOA->MODER |= (0xa << 0u);         /* Set pin 0..1 to alternate function mode. */ 
- 
-GPIOA->OSPEEDR &= ~(0xff << 0u);     /* Clear existing output speed bits 0 to 3. */ 
-GPIOA->OSPEEDR |= (0xff << 0u);      /* Set pin 0..1 to high speed (100MHz) mode. */ 
- 
-GPIOA->AFR[0] &= ~(0xff << 0u);      /* Clear existing af bits 0 to 7. */ 
-GPIOA->AFR[0] |= (0x88 << 0u);       /* Set pin 0..1 to AF8 (UART4). */ 
-</code> 
-\\ 
- 
-==== Transmitting Data ==== 
- 
-<code c> 
-#include "reg_stm32f4xx.h" 
- 
-RCC->APBENR[0] |= (0x1 << 19u);      /* Enable UART4 clock */ 
- 
-UART4->CR1 |= (0x1 << 13u);          /* Enable UART */ 
-UART4->BRR |= (42000000u / 115200u); /* Set baudrate to 115'200 */ 
- 
-UART4->CR1 |= (0x1 << 3u);           /* Enable transmission */ 
-UART4->DR = data_send;               /* Send first data */ 
-while(!(UART4->SR & (0x1 << 7u)));   /* Wait til TXE flag is set */ 
-UART4->DR = data_send;               /* Send last data */ 
-while(!(UART4->SR & (0x1 << 6u)));   /* Wait til TC flag is set */ 
-</code> 
-\\ 
- 
-==== Receiving Data ==== 
- 
-<code c> 
-#include "reg_stm32f4xx.h" 
- 
-RCC->APBENR[0] |= (0x1 << 19u);      /* Enable UART4 clock */ 
- 
-UART4->CR1 |= (0x1 << 13u);          /* Enable UART */ 
-UART4->BRR |= (42000000u / 115200u); /* Set baudrate to 115'200 */ 
- 
-UART4->CR1 |= (0x1 << 2u);           /* Enable receiver */ 
-while(!(UART4->SR & (0x1 << 5u)));   /* Wait til RXNE flag is set */ 
-data_received = UART4->DR            /* Read data */ 
-</code> 
 \\ \\
  
 ===== 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 "reg_stm32f4xx.h" 
 + 
 +RCC->AHBENR[0] |= (0x1 << 0u);       /* Enable GPIOA clock */ 
 + 
 +/* Configure GPIO pin A.0 and A.1 in alternate function mode. */ 
 +GPIOA->MODER &= ~(0xf << 0u);        /* Clear existing mode bits 0 to 3. */ 
 +GPIOA->MODER |= (0xa << 0u);         /* Set pin 0..1 to alternate function mode. */ 
 + 
 +GPIOA->OSPEEDR &= ~(0xff << 0u);     /* Clear existing output speed bits 0 to 3. */ 
 +GPIOA->OSPEEDR |= (0xff << 0u);      /* Set pin 0..1 to high speed (100MHz) mode. */ 
 + 
 +GPIOA->AFR[0] &= ~(0xff << 0u);      /* Clear existing af bits 0 to 7. */ 
 +GPIOA->AFR[0] |= (0x88 << 0u);       /* Set pin 0..1 to AF8 (UART4). */ 
 +</code> 
 +\\ 
 + 
 +==== Transmitting Data ==== 
 + 
 +<code c> 
 +#include "reg_stm32f4xx.h" 
 + 
 +RCC->APBENR[0] |= (0x1 << 19u);      /* Enable UART4 clock */ 
 + 
 +UART4->CR1 |= (0x1 << 13u);          /* Enable UART */ 
 +UART4->BRR |= (42000000 / 115200);   /* Set baudrate to 115'200 */ 
 + 
 +UART4->CR1 |= (0x1 << 3u);           /* Enable transmission */ 
 +UART4->DR = data_send[0];            /* Send first data */ 
 +while(!(UART4->SR & (0x1 << 7u)));   /* Wait til TXE flag is set */ 
 +UART4->DR = data_send[1];            /* Send first data */ 
 +while(!(UART4->SR & (0x1 << 7u)));   /* Wait til TXE flag is set */ 
 +UART4->DR = data_send[2];            /* Send last data */ 
 +while(!(UART4->SR & (0x1 << 6u)));   /* Wait til TC flag is set */ 
 +</code> 
 +\\ 
 + 
 +==== Receiving Data ==== 
 + 
 +<code c> 
 +#include "reg_stm32f4xx.h" 
 + 
 +RCC->APBENR[0] |= (0x1 << 19u);      /* Enable UART4 clock */ 
 + 
 +UART4->CR1 |= (0x1 << 13u);          /* Enable UART */ 
 +UART4->BRR |= (42000000 / 115200);   /* Set baudrate to 115'200 */ 
 + 
 +UART4->CR1 |= (0x1 << 2u);           /* Enable receiver */ 
 +while(!(UART4->SR & (0x1 << 5u)));   /* Wait til RXNE flag is set */ 
 +data_received = UART4->DR            /* Read data */ 
 +</code> 
 +\\
  • stm32/peripherals/usart.1457337049.txt.gz
  • Last modified: 2016/03/07 07:50
  • by feur