打印
[应用相关]

USART3进不了中断?不只哪的问题

[复制链接]
1820|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xibei2000|  楼主 | 2009-7-8 14:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "misc.h"

__IO bool Time_Interval_OK;
__IO uint16_t Sec;
__IO uint16_t Min;
__IO uint16_t Hour;

/*  -----------------------------------------------*/
/*************************************************
函数: void RCC_Config(void)
功能: 配置系统时钟 
参数: 无
返回: 无
**************************************************/
void RCC_Configuration(void)
{
    /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
    SystemInit();
    
    /* Enable GPIO clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
    
    /* Enable UART clocks */  
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
}
/*************************************************
函数: void NVIC_Configuration(void)
功能: 切套向量中断控制寄存器 
参数: 无
返回: 无
**************************************************/
void NVIC_Configuration(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);    /* Configure the NVIC Preemption Priority Bits */
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; /* Enable the USART1 Interrupt */
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

}
/*************************************************
函数: void GPIO_Configuration(void) 
功能: 端口锁定 
参数: 无
返回: 无
**************************************************/
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Configure UART_Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//GPIO_TxPin;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    /* Configure UART_Rx as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//GPIO_RxPin;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

}
/*************************************************
函数: void USART_Configuration(void)
功能: 串口配置
参数: 无
返回: 无
**************************************************/
void USART_Configuration(void)
{

    USART_InitTypeDef USART_InitStructure;
    
    USART_InitStructure.USART_BaudRate = 57600;     //BaudRate
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8 Bits
    USART_InitStructure.USART_StopBits = USART_StopBits_1; //One Stop Bit
    USART_InitStructure.USART_Parity = USART_Parity_No ; // No parity
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//Hardware flow control disabled (RTS and CTS signals)
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;    //
    
    USART_Init(USART3, &USART_InitStructure); /* Configure the USART1 */ 
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); /* Enable USART1 Receive and Transmit interrupts */
    USART_Cmd(USART3, ENABLE); /* Enable the USART1 */
}


/*************************************************
函数: int main(void) 
功能: 主函数
参数: 无
返回: 无
**************************************************/
int main(void)
{
    RCC_Configuration();
    NVIC_Configuration();
    GPIO_Configuration();
    USART_Configuration();
    
    while (1) 
    {
        USART_SendData(UART4, 0x55);
        
    }
}

             
沙发
xibei2000|  楼主 | 2009-7-8 15:32 | 只看该作者

串口3好了,UART4又不能用了,晕

我程序是发送中断,USART_IT_RXNE标志位错了,串口3是好了,可是换成串口4有进不了,郁闷呀,哪位高手指点一下

使用特权

评论回复
板凳
ST_ARM| | 2009-7-8 17:23 | 只看该作者

真受不了你写的代码

void RCC_Configuration(void)
{
    /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
    SystemInit();
    
    /* Enable GPIO clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
    
    /* Enable UART clocks */  
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
                                       ^^^^^^^^^ 这里是4,初始化又是3
}

int main(void)
{
    RCC_Configuration();
    NVIC_Configuration();
    GPIO_Configuration();
    USART_Configuration();
    
    while (1) 
    {
        USART_SendData(UART4, 0x55);
                      ^^^^^^^^这里又是4?
    }
}

真让人晕倒!

使用特权

评论回复
地板
xwj| | 2009-7-8 17:46 | 只看该作者

马大哈?

使用特权

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

本版积分规则

1

主题

3

帖子

0

粉丝