金牌会员
 
- 积分
- 1276
- 金钱
- 1276
- 注册时间
- 2016-5-31
- 在线时间
- 499 小时
|
发表于 2017-9-26 21:51:02
|
显示全部楼层
请看:
#define GPIOx GPIOD
#define RCC_APB2Periph_GPIOx RCC_APB2Periph_GPIOD
#define GPIO_RTSPin GPIO_Pin_4
#define GPIO_CTSPin GPIO_Pin_3
#define GPIO_TxPin GPIO_Pin_5
#define GPIO_RxPin GPIO_Pin_6
void RCC_Configuration(void)
{
/* Enable GPIOx and AFIO clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOx | RCC_APB2Periph_AFIO, ENABLE);
/* Enable USART2 clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the USART2 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
/* Configure USART2 RTS and USART2 Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_RTSPin | GPIO_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOx, &GPIO_InitStructure);
/* Configure USART2 CTS and USART2 Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_CTSPin | GPIO_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOx, &GPIO_InitStructure);
}
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* USART2 configuration -----------------------------------------------*/
/* USART2 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control enabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_RTS_CTS;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE);
//***************
//***************
//***************
while(1){
//***************
//***************
}
}
|
|