文档详情

stm32学习笔记之USART_Printf.pdf

发布:2017-05-27约3.46千字共3页下载文档
文本预览下载声明
2012 4 月20 号 STM32F107 学习笔记 stm32 学习笔记之USART_Printf (作者:logokfu 邮箱:g535343589@) 这个程序就是简单的串口打印输出。也是固件库里面串口部分最简单的一个例子,其他 的例子请自行研究。 由于是直接修改的官方的例子,因此为了和官方的风格保持一致,里面的注释大多数还是采 用原来例子里面的英文注释,保持原汁原味,翻译成中文可能会变味。 #include stm32f10x.h #include stdio.h #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) void GPIO_Configuration(); void USART1_Configuration(); int main(void) { GPIO_Configuration(); USART1_Configuration(); /* Output a message on Hyperterminal using printf function */ printf(USART Printf Example: retarget the C library printf function to the USART1\n\r); while (1) { } } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO,AFIO,UART clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA| RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1, ENABLE); /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, GPIO_InitStructure); /* Configure USART Rx as input floating */ 第 1 页 共 3 页 2012 4 月20 号 STM32F107 学习笔记 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_ 10; GPIO_Init(GPIOA, GPIO_InitStructure); } void USART1_Configuration(void) { USART_InitTypeDef USART_InitStructure; / * USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit
显示全部
相似文档