打印

请教高手,为什么我用STM32F4 串口发送数据,管脚无波形,仿真时看到DR一直无数据,发送标志位一直为0,跪求高手解释!!配置如下:

[复制链接]
255|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
丑帅丑帅的|  楼主 | 2018-8-1 18:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void USART2_Parameter_Configuration(u16 baudrate,u16 USART_StopBits,u16 USART_Parity)
{
u16 temp_wordlength;
    USART_InitTypeDef   USART_InitStructure;
    USART_ClockInitTypeDef  USART_ClockInitStructure;
  NVIC_InitTypeDef   NVIC_InitStructure;
GPIO_InitTypeDef   GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
   
   GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_USART2);  //复合管脚  
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_USART2);  //复合管脚
//USART2 CAM_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP ;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

//USART2 CAM_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;   //设置输入
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;   //上拉
GPIO_Init(GPIOA, &GPIO_InitStructure);   
if(USART_Parity)
{
  temp_wordlength=USART_WordLength_9b;
}
else
{
  temp_wordlength=USART_WordLength_8b;
}
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = temp_wordlength;
USART_InitStructure.USART_StopBits =USART_StopBits;
USART_InitStructure.USART_Parity =USART_Parity;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USART2 */   
USART_Init(USART2,&USART_InitStructure);
//    USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
//    USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
//    USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
//    USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
    USART_ClockStructInit(&USART_ClockInitStructure);
    USART_ClockInit(USART2,&USART_ClockInitStructure);   

//中断
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
   NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;  
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

  /* Enable USART3 Receive and Transmit interrupts */
  //USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  //USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
   
    /* Enable the USART2 */
    USART_Cmd(USART2, ENABLE);

}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

741

主题

742

帖子

0

粉丝