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,

CodePudding user response:

reference 1st floor forget345 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,

Floating empty that I know, but check the push-pull I feel is not like our teaching materials in such a configuration,,,
Then, the USART configuration code is as follows:
USART_InitTypeDef USART_InitStructure;
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;
USART_Init (USART1, & amp; USART_InitStructure);
USART_Cmd (USART1, ENABLE);
USART_SENDBYTE (USART1, 100);
To send data function definition code is as follows:
Void USART_SENDBYTE (USART_TypeDef * pUSARTX, uint8_t data)
{USART_SendData (USART1, data);
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);
}
Baud rate which I have set up is the same as the serial assistants, feel very strange

CodePudding user response:

GPIO_OType_PP is push-pull, see the PP will probably know, how much you can see the value is GPIO_OType_PP do manual and see if it is the value of the push-pull
Code looks fine, in addition to * pUSARTX useless, have the oscilloscope or logical analysis directly on MCU PA9 see, turn USB series chip is broken it is also possible,

CodePudding user response:

Function IO reuse ah, must be set GPIO_PinAFConfig, that every single chip is different, even if the same model of different packaging is different, completely depends on the specification,
  • Related