Home > other > Want to be consulted in the STM32L152 PC serial port communication experiments about GPIO serial por
Want to be consulted in the STM32L152 PC serial port communication experiments about GPIO serial por
Time:09-23
I checked the teacher gave the courseware as well as the relevant code on the net is TX pins should be configured to check push-pull output, then the RX to be floated input pin, but the teacher gave us a GPIO header file does not define GPIO_Mode_AF_PP and GPIO_Mode_IN_FLOATING and then, the book to the code I would more look not to understand, is as follows: (PA9 TX, PA10 RX) GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9; GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure. GPIO_OType=GPIO_OType_PP; GPIO_InitStructure. GPIO_Speed=GPIO_Speed_40MHz; GPIO_Init (GPIOA, & amp; GPIO_InitStructure); GPIO_PinAFConfig (GPIOA, GPIO_PinSource9 GPIO_AF_USART1); GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init (GPIOA, & amp; GPIO_InitStructure); GPIO_PinAFConfig (GPIOA, GPIO_PinSource10 GPIO_AF_USART1); After that, I use this configuration and use USART_SendData posted a 100, a serial port assistant display as follows, and no matter what will be sent in the start and end with a FE
But the GPIO_PinAFConfig (GPIOA, GPIO_PinSource9 GPIO_AF_USART1); After remove this saying, only display 00 serial assistants, and no matter whether I send data as long as according to the board reset button will appear 00, and only after remove the GPIO_PinAFConfig this, turn the USB serial port on the RXD, TXD corresponding LED light is on,
CodePudding user response:
1, GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_NOPULL; This is empty, this code is not the same, should be a different set of chip and the reasons of different repository, =0 2100 x64, 60, is also not show you may baud rate is wrong, also want to check digits and check, there is no specific code I don't know. 3, 00 after reset is normal, is commonly caused by hardware circuit, temporarily forget,