Professional Documents
Culture Documents
STM32F10x - UART Port PDF
STM32F10x - UART Port PDF
STM32F10x
2012 101
2012 (4)
UART Port (4)
RTC Control
UART1 Configuration
TIM1 PWM output
1. System Clock confirm
sample code is base on 72MHz to setting GPIO Input
/* #define SYSCLK_FREQ_HSE HSE_VALUE */
UART Port
#define SYSCLK_FREQ_72MHz 72000000
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz;
5. UART Configuration
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*send a idle
frame,cause TXE=1 interupt*/
USART_InitStructure.USART_Clock = USART_Clock_Disable;
USART_InitStructure.USART_CPOL = USART_CPOL_Low;
USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
/* Configure USART1 */
USART_Init(USART1, &USART_InitStructure);
http://stm32f-study.blogspot.com/2012/10/uart-port.html 1/3
1/9/2017 STM32F10x : UART Port
/* Enable the USART Transmoit interrupt: this interrupt is generated when the
USART1 transmit data register is empty */
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
/* Enable the USART Receive interrupt: this interrupt is generated when the
USART1 receive data register is not empty */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
7. Enable UART1
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
9. Printf function
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
add function
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
http://stm32f-study.blogspot.com/2012/10/uart-port.html 2/3
1/9/2017 STM32F10x : UART Port
ys Hung 5:51
...
...
(Atom)
. Blogger.
http://stm32f-study.blogspot.com/2012/10/uart-port.html 3/3