OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3564|回复: 2

STM32F302串口实验问题

[复制链接]

32

主题

75

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
331
金钱
331
注册时间
2015-11-19
在线时间
38 小时
发表于 2016-10-25 17:17:31 | 显示全部楼层 |阅读模式
1金钱
STM32F302串口实验使用usart1,但是发不出去
void My_USART1_Init(void)
{
        GPIO_InitTypeDef GPIO_InitStrue;
        USART_InitTypeDef USART_InitStrue;
//        NVIC_InitTypeDef NVIC_InitStrue;
       
        RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_SYSCFG,ENABLE);
       
         // òy½Å¸′óÃ
       
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_7); //PA10???USART1
       
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_Level_1;
        GPIO_InitStrue.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStrue.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_7); //PA9???USART1
  GPIO_Init(GPIOA,&GPIO_InitStrue);
       
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_Level_1;
        GPIO_InitStrue.GPIO_PuPd=GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA,&GPIO_InitStrue);
       
        USART_InitStrue.USART_BaudRate=115200;
        USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
        USART_InitStrue.USART_Parity=USART_Parity_No;
        USART_InitStrue.USART_StopBits=USART_StopBits_1;
        USART_InitStrue.USART_WordLength=USART_WordLength_8b;
       
        USART_Init(USART1,&USART_InitStrue);
       
        USART_Cmd(USART1,ENABLE);//ê1Äü′®¿ú1
/*       
        NVIC_InitStrue.NVIC_IRQChannel=USART1_IRQn;
        NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStrue);
        */
       
}
/*
void USART1_IRQHandler(void)
{
        u8 res;
         if(USART_GetITStatus(USART1,USART_IT_RXNE))
{
     res= USART_ReceiveData(USART1);
     USART_SendData(USART1,res);   
  }
}

*/

int main(void)
{

        system_init();
//  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
        My_USART1_Init();       
        while (1)
        {

    u16 res=0x55;
     USART_SendData(USART1,res);   

                GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);
                delay_ms(500);
                GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_RESET);
                delay_ms(500);
        }
}


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

347

帖子

3

精华

金牌会员

Rank: 6Rank: 6

积分
2082
金钱
2082
注册时间
2014-12-19
在线时间
711 小时
发表于 2016-10-25 19:32:18 | 显示全部楼层
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN; 改为GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF;
取消中断部分的注释
回复

使用道具 举报

32

主题

75

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
331
金钱
331
注册时间
2015-11-19
在线时间
38 小时
 楼主| 发表于 2016-10-26 16:13:06 | 显示全部楼层
lvehe 发表于 2016-10-25 19:32
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN; 改为GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF;
取消中断部分的注 ...

你好,还是不可以。请问一下,你有stm32f302芯片的编程模版吗?我担心是可能和系统文件冲突
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-14 13:52

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表