新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2014-6-5
- 在线时间
- 1 小时
|
5金钱
请问是否有人调试过官方开发板子的串口,我现在是怎么调都没反应;
void Usart_init_for(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
// USART_DeInit(USART2);
GPIO_PinAFConfig(GPIOD,GPIO_Pin_5,GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD,GPIO_Pin_6,GPIO_AF_USART2);
/*USART2 GPIO config*/
/* Configure USART2 Tx (PD.05) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure USART2 Rx (PD.06) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/*USART2 mode config*/
USART_InitStructure.USART_BaudRate = 9600;
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(USART2, &USART_InitStructure);
USART_Cmd(USART2,ENABLE);
}
再main函数里面做循环发送数据和亮灯的操作:
while (1)
{
STM_EVAL_LEDOn(LED3);
delay_ms(1000);
USART_SendData(USART2,19);
STM_EVAL_LEDOff(LED3);
delay_ms(1000);
USART_SendData(USART2,0);
}
|
|