打印
[STM32F3]

STM32F103R8T6 串口3 能发送 但不能进行中断接收 是什么问题?

[复制链接]
2478|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xclfang|  楼主 | 2015-4-3 11:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题:
主程序如下
int main(void)
{
#ifdef DEBUG
        debug();
#endif
        /* System Clocks Configuration */
        RCC_Configuration();
        GPIO_Configuration();
        NVIC_Configuration();
        USART3_Configuration();
        TIM_Configuration();
        TIM1_Configuration();
        GPIO_Deint();
        TXD_EXTENSION_ADDRESS = READ_adderss();
        GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET); //LED1  LIGHT
        RX_485;
        while(1)
        {
                //Send_DATA_RS485();
        }
}

中断程序如下
void USART3_IRQHandler(void)
{
        if(USART_GetITStatus(USART3, USART_IT_RXNE) == SET)
        {       
          USART_ClearITPendingBit(USART3,USART_IT_RXNE);
                                        GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET); //LED1  LIGHT
          RXDBUFFER[RxBufferSize_connter] = USART_ReceiveData(USART3);
          RxBufferSize_connter = RxBufferSize_connter + 1;
          if(RxBufferSize_connter == 26)
                                        RxBufferSize_connter = 0;
          if((RXDBUFFER[5] == 0XFF) && (RXDBUFFER[6] == 0X55) && (RXDBUFFER[7] == 0X5A)
             && (RXDBUFFER[8] == 0XA5) && (RXDBUFFER[9] == 0XAA) && (RXDBUFFER[11] == 0X90))
            {
               RXD_FLAG = 1;
                                                         GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_SET); //LED1  LIGHT
            }
        }
}


usart3配置如下
        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;       

        /* Configure the USARTx */
        USART_Init(USART3, &USART_InitStructure);         

        /* Enable the USART Receive interrupt: this interrupt is generated when the USARTx receive data register is not empty */
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);                 

        /* Enable USARTx */
        USART_Cmd(USART3, ENABLE);       


nvic 如下
        NVIC_InitTypeDef NVIC_InitStructure;
#ifdef  VECT_TAB_RAM
        /* Set the Vector Table base location at 0x20000000 */
        NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
        /* Set the Vector Table base location at 0x08000000 */
        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif

        /* Configure the NVIC Preemption Priority Bits */  

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

        NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//USART3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel;//TIM1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;//TIM2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;      

        NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;//TIM3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel;//TIM4_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

rcc 如下
        ErrorStatus HSEStartUpStatus;

        /* RCC system reset(for debug purpose) */
        RCC_DeInit();

        /* Enable HSE */
        RCC_HSEConfig(RCC_HSE_ON);
        /* Wait till HSE is ready */
        HSEStartUpStatus = RCC_WaitForHSEStartUp();

        if(HSEStartUpStatus == SUCCESS)
        {
        /* HCLK = SYSCLK */
        RCC_HCLKConfig(RCC_SYSCLK_Div1);

        /* PCLK2 = HCLK */
        RCC_PCLK2Config(RCC_HCLK_Div1);

        /* PCLK1 = HCLK/2 */
        RCC_PCLK1Config(RCC_HCLK_Div2);

        /* Flash 2 wait state */
        FLASH_SetLatency(FLASH_Latency_2);
        /* Enable Prefetch Buffer */
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

        /* PLLCLK = 8MHz * 9 = 72 MHz */
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

        /* Enable PLL */
        RCC_PLLCmd(ENABLE);

        /* Wait till PLL is ready */
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
        {
        }

        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        /* Wait till PLL is used as system clock source */
        while(RCC_GetSYSCLKSource() != 0x08)
        {
        }
        }

        /*Enble GPIOA、GPIOB、GPIOC、GPIOD*/
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
                                                        | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
                                                        | RCC_APB2Periph_TIM1,
                                                        ENABLE);

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3
                                                        | RCC_APB1Periph_TIM4 | RCC_APB1Periph_USART3,
                                                        ENABLE);

gpio配置如下
        /*Configure PB10  as output for  USART3_TXD; RS485_TXD*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        /*Configure PB11  as input for  USART3_RXD; RS485_RXD*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        /*Configure PB12  as output for  USART3_DIR; RS485_DIR*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

请高手指点!!  
沙发
xclfang|  楼主 | 2015-4-3 11:28 | 只看该作者
在线等待!!

使用特权

评论回复
板凳
复仇之矛| | 2015-4-3 11:49 | 只看该作者
你把GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET); //LED1  LIGHT,这句话注释了再试试。

使用特权

评论回复
地板
xclfang|  楼主 | 2015-4-3 12:01 | 只看该作者
一样的, 与这个没关系吧!!

使用特权

评论回复
5
xclfang|  楼主 | 2015-4-3 12:01 | 只看该作者
复仇之矛 发表于 2015-4-3 11:49
你把GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET); //LED1  LIGHT,这句话注释了再试试。

与这个没关系吧!!

使用特权

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

本版积分规则

19

主题

122

帖子

0

粉丝