苏浅叶 发表于 2015-6-8 09:22:10

关于STM32F030C8T6串口1TXRX引脚复用问题

            关于STM32F030C8T6串口1TXRX引脚复用问题,下面的程序对吗?            voidusart1_init(unsignedintBaudRate)GPIO_InitTypeDefGPIO_InitStructure;USART_InitTypeDefUSART_InitStructure;RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOAENABLE);//打开GPIOA时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1//打开usart时钟//GPIO_DeInit(GPIOA);GPIO_PinAFConfig(GPIOAGPIO_PinSource9GPIO_AF_1);GPIO_PinSource10ConfigurepinspushpullGPIO_InitStructure.GPIO_PinGPIO_Pin_9GPIO_Pin_10GPIO_InitStructure.GPIO_ModeGPIO_Mode_AF;GPIO_InitStructure.GPIO_SpeedGPIO_Speed_50MHz;GPIO_InitStructure.GPIO_OTypeGPIO_OType_PP;GPIO_InitStructure.GPIO_PuPdGPIO_PuPd_NOPULL;GPIO_Init(GPIOA&GPIO_InitStructure);//USART_DeInit(USART1);USART_InitStructure.USART_BaudRateBaudRate;USART_InitStructure.USART_WordLengthUSART_WordLength_8b;USART_InitStructure.USART_StopBitsUSART_StopBits_1;USART_InitStructure.USART_ParityUSART_Parity_No;USART_InitStructure.USART_HardwareFlowControlUSART_HardwareFlowControl_None;USART_InitStructure.USART_ModeUSART_Mode_RxUSART_Mode_Tx;//使能接收和发送USART_Init(USART1&USART_InitStructure);USART_ITConfig(USART1USART_IT_RXNE//使能接收中断USART_Cmd(USART1USART_ClearFlag(USART1USART_FLAG_TC);

问题的网址如下:https://www.stmcu.org.cn/faq/index/detail/id-70548
   

lvyunhua 发表于 2015-6-8 09:47:45

代码很乱,看不清楚。

jiaswang 发表于 2015-6-8 10:32:14

太乱了,不行楼主放文件里发附件吧

lkl0305 发表于 2015-6-8 12:18:13

格式化代码一下,楼主:D

jacobfeng 发表于 2015-6-8 12:54:03

本帖最后由 jacobfeng 于 2015-6-8 12:57 编辑

复用时钟没有开启RCC_APB2Periph_AFIO :lol
我放keil里面把格式调了一下,代码还是很乱。
void usart1_init(unsignedintBaudRate)
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//打开GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1//打开usart时钟
//GPIO_DeInit(GPIOA);
GPIO_PinAFConfig(GPIOAGPIO_PinSource9GPIO_AF_1);
GPIO_PinSource10Configurepinspushpull;
GPIO_InitStructure.GPIO_PinGPIO_Pin_9 | GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_ModeGPIO_Mode_AF;
GPIO_InitStructure.GPIO_SpeedGPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OTypeGPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPdGPIO_PuPd_NOPULL;
GPIO_Init(GPIOA&GPIO_InitStructure);
//USART_DeInit(USART1);
USART_InitStructure.USART_BaudRateBaudRate;
USART_InitStructure.USART_WordLengthUSART_WordLength_8b;
USART_InitStructure.USART_StopBitsUSART_StopBits_1;
USART_InitStructure.USART_ParityUSART_Parity_No;
USART_InitStructure.USART_HardwareFlowControlUSART_HardwareFlowControl_None;
USART_InitStructure.USART_ModeUSART_Mode_RxUSART_Mode_Tx;//使能接收和发送
USART_Init(USART1&USART_InitStructure);
USART_ITConfig(USART1USART_IT_RXNE//使能接收中断
USART_Cmd(USART1USART_ClearFlag(USART1USART_FLAG_TC);

为什么是EEFOCUS小白 发表于 2015-6-8 16:10:42

好乱               

为什么是EEFOCUS小白 发表于 2015-6-10 17:32:56

用空格隔开吧
页: [1]
查看完整版本: 关于STM32F030C8T6串口1TXRX引脚复用问题