打印
[STM32F1]

STM32F107VCT6的串口3问题

[复制链接]
1123|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xxmmi|  楼主 | 2018-8-27 20:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我要使用STM32F107VCT6的串口3,引脚是B10和B11。我按串口1设置的顺序(时钟,引脚,中断管理,中断处理)设置,可是串口3一点反应都没有,不知与串口1的设置有啥不同,谢谢!
沙发
llljh| | 2018-8-27 20:25 | 只看该作者

可以尝试下排除硬件问题

使用特权

评论回复
板凳
xxmmi|  楼主 | 2018-8-27 20:27 | 只看该作者
两个板子都是没反应呢

使用特权

评论回复
地板
xxmmi|  楼主 | 2018-8-27 20:29 | 只看该作者

两个板子都是没反应呢

使用特权

评论回复
5
houcs| | 2018-8-27 20:30 | 只看该作者
还要设置AFIO时钟,和引脚的;

使用特权

评论回复
6
xxmmi|  楼主 | 2018-8-27 20:32 | 只看该作者

测试了还是不行,把源码贴上:
int main(void)
{
  
      
  /* System Clocks Configuration */
   SystemInit();
  /* Configure the GPIO ports */
  GPIO_Configuration();
  TIM2_Configuration();
  UTRA3_Configuration();
  /* NVIC configuration */
  NVIC_Configuration();
  Uart_InterruptsendY(USART3,ddd1,3);///wwwwwwwwwwwwwwwwwwwwwwwwwww
  while (1)
  {
  }
}

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);

  /* Configure USARTx_Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//10
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure USARTx_Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//11
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
}

void UTRA3_Configuration(void)
{
/* USARTy and USARTz configuration ------------------------------------------------------*/
  /* 9600  8  n  1
  */
  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;
  /* Configure USARTy */
  USART_Init(USART3, &USART_InitStructure);
  /* Configure USARTz */
  /* Enable USARTy Receive and Transmit interrupts */
  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);//使能中断 这里先不使能  在后面中断发送之前发送
  USART_Cmd(USART3, ENABLE);   
}

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  
  /* Enable the USARTy Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void Uart_InterruptsendY(USART_TypeDef *USARTx,vu8* Uart0_sended,u8 NbOfBytes )
{   
      Uart_send_counter=NbOfBytes;
      Uart_send_pointer=Uart0_sended;
     USART_SendData(USARTx, *Uart_send_pointer++);
     USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);
       //UART_ITConfig(UARTx,UART_IT_TxEmpty, ENABLE);
}

使用特权

评论回复
7
Bruing| | 2018-8-28 19:53 | 只看该作者
百度搜索一下串口3的例程还是很多的。

使用特权

评论回复
8
ousj| | 2018-8-29 08:22 | 只看该作者
UART3 这个外设的时钟未使能

使用特权

评论回复
9
chuxh| | 2018-8-29 08:24 | 只看该作者
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_AFIO, ENABLE);这么明显的问题

使用特权

评论回复
10
xxmmi|  楼主 | 2018-8-29 08:25 | 只看该作者

哦,那我就知道怎么回事了,多谢大家,结贴了哈

使用特权

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

本版积分规则

369

主题

4278

帖子

2

粉丝