打印

香主---uart4,5问题

[复制链接]
1821|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hg595914664|  楼主 | 2010-11-9 17:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32F103RC的串口4和5,进不了中断。
我是通过软件调试的??
沙发
btiger2000| | 2010-11-9 22:04 | 只看该作者
如何设置的?

使用特权

评论回复
板凳
hg595914664|  楼主 | 2010-11-10 08:48 | 只看该作者
void USART_Configuration(void)
{
  USART_InitTypeDef USART_InitStructure;
  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);
  /* Configure USART3 */
//  USART_Init(USART3, &USART_InitStructure);
  /* Configure UART4 */
  USART_Init(UART4, &USART_InitStructure);
  /* Configure UART5 */
  USART_Init(UART5, &USART_InitStructure);

  /* Enable the USART Transmoit interrupt: this interrupt is generated when the
  USART1 transmit data register is empty */
//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
//  USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
  USART_ITConfig(UART4, USART_IT_TXE, ENABLE);
   
  /* Enable the USART Receive interrupt: this interrupt is generated when the
  USART1 receive data register is not empty */
//  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
//  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
  USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);


//   USART_Cmd(USART2, ENABLE);
//    USART_Cmd(USART3, ENABLE);
  USART_Cmd(UART4, ENABLE);
  USART_Cmd(UART5, ENABLE);
  }

中断
        NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;   
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;   
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;   
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   
        NVIC_Init(&NVIC_InitStructure);
        
        NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;   
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;   
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;   
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   
        NVIC_Init(&NVIC_InitStructure);

时钟
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|
                         RCC_APB1Periph_UART4|RCC_APB1Periph_UART5, ENABLE);

使用特权

评论回复
地板
hg595914664|  楼主 | 2010-11-10 08:49 | 只看该作者
void UART4_IRQHandler(void)
{
    uart4();     
}

void UART5_IRQHandler(void)
{
    uart5();
}

使用特权

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

本版积分规则

0

主题

3

帖子

1

粉丝