打印

STM32F101系列 串口发送中断进不来是为什么

[复制链接]
2259|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jie841010|  楼主 | 2008-12-18 22:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  在IAR环境下,基于STM32F101 Cotex-M3系列芯片开发时,遇到串口发送中断进不来,接收中断是正常的,但发送中断就是进不来,很奇怪,我都配好了,就是在发送一个字节时,进不了中断,不知道为什么,有没有哪个大哥遇到类似情况,给小弟解下困惑。
  
沙发
香水城| | 2008-12-19 09:43 | 只看该作者

你用的是什么中断?是否使能了相应的中断?

使用特权

评论回复
板凳
mwm8412| | 2008-12-19 16:53 | 只看该作者

STM32F101系列 串口发送中断进不来是为什么

void USART1_IRQHandler(void)//串口中断
{
  if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  {   
    /* Write one byte to the transmit data register */
    if(TxCounter1 < NbrOfDataToTransfer1)
    USART_SendData(USART1, TxBuffer1[TxCounter1++]);                    

    /* Clear the USART1 transmit interrupt */
    USART_ClearITPendingBit(USART1, USART_IT_TXE); 

    if(TxCounter1 == NbrOfDataToTransfer1)
    {
      /* Disable the USART1 Transmit interrupt */
      USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
    }    
  }
  else  
  {
    /* Read one byte from the receive data register */
    RxBuffer1[RxCounter1++] = USART_ReceiveData(USART1);      

   /* Clear the USART1 Receive interrupt */
   USART_ClearITPendingBit(USART1, USART_IT_RXNE);

    if(RxCounter1 == NbrOfDataToRead1)
    {
      /* Disable the USART1 Receive interrupt */
      USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
    }
  }
}

//**********串口基本配置***********************************/
  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_InitStructure.USART_Clock = USART_Clock_Disable;
  USART_InitStructure.USART_CPOL = USART_CPOL_Low;
  USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
  USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
  
  /* Configure USART1 */
  USART_Init(USART1, &USART_InitStructure);
  /* Configure USART2 */
  USART_Init(USART2, &USART_InitStructure);
  
  /* Enable USART1 Receive and Transmit interrupt */
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

  /* Enable USART2 Receive and Transmit interrupt */
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  USART_ITConfig(USART2, USART_IT_TXE, ENABLE);

  /* Enable the USART1 */
  USART_Cmd(USART1, ENABLE);
  /* Enable the USART2 */
  USART_Cmd(USART2, ENABLE);


//**********中断配置***********************************/
  /* Enable the USART1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable the USART2 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

使用特权

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

本版积分规则

24

主题

34

帖子

0

粉丝