中文English
stm32芯片引脚图ichaiyang 2024-05-10 3:48 36
GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE ; \/\/ ENABLE clock...

How to define the pin reuse of STM32UART1?

GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); \/\/ ENABLE clock of GPIOA RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); \/\/ Enable clock of GPIoa. \/\/ Enable USART clock \/* USART1 port configuration *\/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); \/\/ Configure PA9 into the second function pin TX GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); \/\/ Configure PA10 as the second function pin RX GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, & GPIO_InitStructure); \/* Basic configuration of USART1 *\/ USART_InitStructure.USART_BaudRate = 115200; \/\/ baud rate 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; USART_Init(USART1, & USART_InitStructure); USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); \/\/ ENABLE the receiving interrupt USART_Cmd(USART1, ENABLE); \/\/ Enable NVIC interrupt configuration of USART1 \/* USART1 *\/ NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 0x02; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(& NVIC_InitStruct);