STM32F4串口3的问题

2019-07-20 14:18发布

把串口一改为串口三,程序都跑不了了,是怎么回事呢】


#include "sys.h"
#include "usart.h"        

#if SYSTEM_SUPPORT_OS
#include "includes.h"                                        //ucos ê1óà        
#endif

#if 1
#pragma import(__use_no_semihosting)
struct __FILE
{
        int handle;
};

FILE __stdout;
void _sys_exit(int x)
{
        x = x;
}
int fputc(int ch, FILE *f)
{         
        while((USART3->SR&0X40)==0);
        USART3->DR = (u8) ch;      
        return ch;
}
#endif

#if EN_USART3_RX
u8 USART_RX_BUF[USART_REC_LEN] __attribute__ ((at(0X20001000)));
u16 USART_RX_STA=0;   
u32 USART_RX_CNT=0;
  


void uart_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);


        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART3); //
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_USART3); //
        
        //USART1¶Ë¿úÅäÖÃ
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_Init(GPIOB,&GPIO_InitStructure);


        USART_InitStructure.USART_BaudRate = bound;
        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(USART3, &USART_InitStructure);
        
  USART_Cmd(USART3, ENABLE);
        
        //USART_ClearFlag(USART1, USART_FLAG_TC);
        
#if EN_USART3_RX        
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

        //Usart1 NVIC ÅäÖÃ
  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

#endif
        
}


void USART3_IRQHandler(void)
{
        u8 Res;
#if SYSTEM_SUPPORT_OS
        OSIntEnter();   
#endif
        if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
        {
                Res =USART_ReceiveData(USART3);//(USART1->DR);
               
                        if(USART_RX_CNT<USART_REC_LEN)
                {
                        USART_RX_BUF[USART_RX_CNT]=Res;
                        USART_RX_CNT++;                                                                                                      
                }                 
  }
#if SYSTEM_SUPPORT_OS
        OSIntExit();                                                                                          
#endif
}
#endif        
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
10条回答
jeff_梁
1楼-- · 2019-07-21 09:45
不是映射问题就是硬件连接问题
jeff_梁
2楼-- · 2019-07-21 10:19
 精彩回答 2  元偷偷看……
shiqi
3楼-- · 2019-07-21 12:08
yklstudent 发表于 2017-5-24 19:24
检查硬件是否有问题、引脚接线有没有问题

P10跳线帽的问题,解决啦,谢谢您
shiqi
4楼-- · 2019-07-21 17:28
谢谢各位,已解决

一周热门 更多>